Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multi timeframe indicator, smaller timeframe bar close

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi timeframe indicator, smaller timeframe bar close

    I have a strategy that I want to develop that will use a smaller timeframe to confirm a market entry.

    In the image below:
    • The top panel is the main instrument on 60 minutes.
    • The second panel is a manually added data series, different instrument on a 15 minute time frame (the bars are displayed correctly).
    • The third panel is a custom indicator with the same instrument as panel 2 on a 15 time frame. The values in panel 3 should be the same as the second panel, and if all of the panels are on the same timeframe panels 2 and 3 look exactly alike. However when the indicator in panel 3 is on a different time than the primary panel, it does not render its bars correctly.
    1. Is there a solution to render the bars in panel 3 to make the look like panel 2 when its on a smaller time frame than the primary instrument?
    2. If not, is there a way to use the data in panel 2 (the manually added data series) in the strategy? I'm really looking to trigger the entry based on the close of a bar in the smaller time frame.
    3. If both of those options are not possible, is there a way to have a completely separate chart send a signal a the strategy? In that scenario I'd setup the other chart with the custom indicator and when the conditions are met have it send a signal to the chart that will place the trade if its other condition are also met.

    Thank you for any suggestions.





    Click image for larger version

Name:	capture.png
Views:	100
Size:	10.0 KB
ID:	1186396

    #2
    Hello bojim,

    Thanks for your post.

    The indicator in panel 3 appears to be plotted only when the 30-minute bars are plotted which would be expected if the indicator is run from the 30-minute bars. An indicator can only plot based on the data series it is applied to.

    "is there a way to use the data in panel 2 (the manually added data series) in the strategy? I'm really looking to trigger the entry based on the close of a bar in the smaller time frame."
    Yes, you add any data series you wish to a strategy. A strategy will adopt the chart bars as the primary series and in code, you can add data series as needed using the AddDataSeries() method: https://ninjatrader.com/support/help...dataseries.htm Please note that adding a data series to a script makes the bars available to the script but would not display the added data series on the chart.

    When you add a data series to a script there is a number of important considerations as you have created a multi-series or multi-time frame script. Please see this section of the help guide to best review and understand these considerations for your coding: https://ninjatrader.com/support/help...nstruments.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for replying.

      I've read the docs on Multi-Time Frame & Instruments more than once.

      The custom indicator in panel 3 is added with this line of code.
      Code:
      AddDataSeries("ES 03-22", BarsPeriodType.Minute, 15);
      When I add the data series to the strategy as you suggest, I cannot get the smaller timeframe to look right. I understand that it's the nature of the way ninja script uses the primary instrument's timeframe to draw the bars, which does not work for what I'm trying to accomplish. To be more detailed I'm wanting to measure the slope of a moving average on the smaller timeframe panel. Because the bars are not displayed correctly I cannot get the data I need.

      Can you please reread my question list? I was asking if I can access the "manually added dataset" which is displayed correctly, and your response was have me add it via code, which is exactly what panel 3 is already doing.

      Also the primary bars are 60 minutes, not 30 minutes.

      What am I missing here?

      Thank you again for your help.
      Last edited by bojim; 01-20-2022, 07:44 AM.

      Comment


        #4
        Hello bojim,

        Thanks for your reply.

        No, from a script you cannot access another manually added data series on the chart.

        If panel 3 that you show is an indicator output and the indicator is added to the 30-minute bars, then the visual output can only be based on the primary series "slots".

        If the interest is in slope you can do that in the code using Slope() and the data from the added data series. For example:

        double mySlope = Slope(Closes[1], 10, 0); // get the slope of the 1st added data series close prices.

        or if using an indicator such as SMA

        double mySlope = Slope(SMA(Closes[1], 20), 10, 0); // get the slope of a 20 period SMA on the first added data series

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          So are you saying that even though the data is rendered incorrectly in panel 3, the slope values based on that data will still be correct? That does not make sense to me.

          As eluded to in the title of the post, I need to know when the smaller timeframe bars close and I want do something based on their closed value. I don't need specifics of how to add a data series or to use the slope command with the closes array. Thank you, but I know all of that.

          What I really need is a way to know when the smaller timeframe bars close on their smaller timeframe(every 15 minutes) , not the primary timeframe, and then do something based on those values. What is point of having a smaller timeframe if you can't use the smaller timeframe? It seems like this should be fairly straight forward, but I guess I've run up against a limitation of ninja script.

          Thanks for trying though...

          Comment


            #6
            Hello bojim,

            Thanks for your reply.

            In a multi time frame script, you will know precisely when each series calls the OnBarUpdate().
            You can check the value of BarsInProgress to know which series has called the OnBarUpdate().

            I don't know if this is what you are looking for but you can segment your code like this:

            if (BarsInProgress == 0)
            {
            // do something when the chart bars call OnbarUpdate()
            }

            if (BarsInProgress == 1)
            {
            // do something when the 1st added series calls OnBarUpdate()
            }

            The other parts of this relate to what Calculate setting you are using and if you are looking at values historically versus live. This is discussed in the documentation here: https://ninjatrader.com/support/help...taIsReferenced
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              This is close, but it's more like:
              Code:
              if (BarsInProgress == 0)
              {
              // do something when the chart bars call OnbarUpdate()
              }
              
              if (BarsInProgress == 1 && IsFirstTickOfBar) {
                    // do something when the 1st added series calls OnBarUpdate() and it is on the 1st tick of the bar of the smaller timeframe.
                 }
              }
              If the added series is a smaller time frame, like 15 minutes, then the added data series should get an IsFirstTickOfBar three times as often as the primary if the primary is 60 minutes. Currently the code never falls into that condition.

              Comment


                #8
                Hello bojim,

                Thanks for your reply.

                I've attached a screenshot of a simple strategy that adds a 1-minute data series and I have applied it to a 5-minute chart. I added the code to print out based on the BarsInProgress and the bool IsFirstTickOfBar. As you can see in the output window there are 5 prints for the 1 minute and 1 print for the 5-minute bar. You may want to recreate this and test it.

                Click image for larger version

Name:	bojim-1.PNG
Views:	86
Size:	194.3 KB
ID:	1186498
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Perfect... thank you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by emillieany, Today, 01:28 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post emillieany  
                  Started by GilbeCarra, Today, 01:22 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post GilbeCarra  
                  Started by oprahwinfreyketogummies, Today, 01:20 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post oprahwinfreyketogummies  
                  Started by ntbone, Today, 01:02 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post ntbone
                  by ntbone
                   
                  Started by nikholasjain, Today, 12:52 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post nikholasjain  
                  Working...
                  X