Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 Time frames in one indicator

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

    2 Time frames in one indicator

    Good evening,

    Is it possible to use 2 different time frames inside one indicator?

    Looking to have and indicator that finds on the daily Chart;

    if( Open[0] > (Close[3] * 1.2))

    and on the 1 min Chart;

    If( Close[0] < Open[0])

    Any input would be great on using multiple time frames inside one indicator.

    Thank you in advance,
    Ryan

    #2
    Hello Tonkingrf1551,

    Thank you for your post.

    Yes, you can absolutely add an additional data series within your indicator and use that in some of your conditions while using the primary series on the chart for others.

    I would advise first reading through this section of our help guide on working with Multi-series scripts:



    Additional series of different time frames may be added using AddDataSeries():



    The biggest thing is making sure you specifiy which series you are referring to when referencing series data like open/close/high/low/volume/times. When using multiple data series, you'd want to use the syntax like Opens[BarsInProgress index][BarsAgo index]:





    I've made a simple example of an indicator that uses the daily series to check the first condition and the primary 1 minute series to check the second. However, you may want to adjust the conditions as I've found the condition for the daily series will only very rarely if ever become true. You can run this example on a 1 minute chart with 3 or more days of data loaded. If both conditions are true for a bar, it will print an upwards arrow below the bar. This will also print information about whether the conditions are true or false to the NinjaTrader Output window (New > NinjaScript Output.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Kate, thank you so much for you response, very helpful. I am reviewing your example, under else if (State == State.Configure), there is only Day time frame listed, in your example how is the 1 minute time frame identified? Thank you very much in advance.

      Comment


        #4
        Hello Tonkingrf1551,

        Thank you for your reply.

        An indicator or strategy will always use the data series for the chart/window it is applied to as the primary series. This does not get specified in the script, only additional series you wish the script to calculate using would need to be added in State.Configure. The primary series may be referred to as BarsArray[0] in a script:



        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Ok got it thank you for that. So I loosened some of the criteria and I cant seem to get it to work. I changed what you had to fine a gap up on the daily chart of 10% or more (Closes[1][1] *1.1) And a green bar on the 1min chart. When I load this on symbol WDFC it says the 1min candle is True but the daily Candle is False? not sure why being the open is 1.1x greater then close.

          }
          else if (State == State.Configure)
          {
          AddDataSeries(Data.BarsPeriodType.Day, 1);

          }
          }

          protected override void OnBarUpdate()
          {
          // check to make sure we have enough daily bars loaded before processing since we need to look
          // back 3 days
          if(CurrentBars[1] < 3)
          return;

          // only check our conditions when the primary series updates
          if(BarsInProgress == 0)
          {
          // prints to check what the conditions below will return
          Print("");
          Print(Times[0][0] + " Bar " + CurrentBars[0]);
          Print("Opens[1][0] > (Closes[1][1] * 1.1): " + (Opens[1][0] > (Closes[1][1] * 1.1)));
          Print("(Closes[0][0] > Opens[0][0]): " + (Closes[0][0] > Opens[0][0]));

          // if the open of the daily series is greater than the close of the daily series 3 bars ago
          // multiplied by 1.1
          if(Opens[1][0] > (Closes[1][1] * 1.1)
          // and the close of the 1 minute primary series is less than the open
          && (Closes[0][0] > Opens[0][0]))
          {
          // draw a dot on the primary series chart
          Draw.ArrowUp(this, "MyArrow" + CurrentBars[0], true, 0, Lows[0][0] - (2 * TickSize), Brushes.RoyalBlue);
          Print("Conditions true on bar " + CurrentBars[0]);
          }

          Comment


            #6
            Hello Tonkingrf1551,

            Thank you for your reply.

            I'm seeing the revised example below plot arrows on real time data. You can't really get the correct values on historical data since it can only calculate OnBarClose, so I've restricted this version to real time data only. Do you see arrows drawn on real time data as you would expect today?

            Thanks in advance; I look forward to assisting you further.
            Attached Files

            Comment


              #7
              When I apply this indicator to the stock WDFC, I dont see any arrows on the chart like other indicators, so you says that the arrows only so up then the indicator is triggered in real time? I can't go back and look were the indicator was triggered this morning?

              Comment


                #8
                Hello Tonkingrf1551,

                Thank you for your reply.

                The reason it can't work on historical data as it is is that on historical data, because all that's known of the bars are the OHLC, the strategy can only process OnBarClose. This means that it doesn't see the current day's currently forming bar, and thus can't calculate according to that bar's open price.

                I'm working on a workaround option for you but trading appears to have stopped for that particular instrument for today, so I'll have to do further testing to make sure they match between the two of them. I'll get that to you tomorrow after the market reopens and I have the ability to test.

                Thanks for your patience, I look forward to assisting you further.

                Comment


                  #9
                  Hello Tonkingrf1551,

                  Thank you for your patience.

                  I've come up with a workaround for your particular use case. Since we're basically only using the daily series to get the current day open and prior day close, we can use indicator values to get those without adding an additional daily bar series. I'm attaching this workaround which would work on historical as well as real time data.

                  Please let us know if we may be of further assistance to you.
                  Attached Files

                  Comment


                    #10
                    Kate thanks so much for the response. Would this be the only work around? I am asking because there will be more added to this indicator in the future. So I will need to have several other criteria on the daily time frame, such as SMA conditions and MAX high and low values, with then a couple criteria on the 5min chart for entries. Not sure the best approach to add conditions based on 2 different time frames before entry.

                    Thank you very much for you help Kate.

                    Comment


                      #11
                      Hello Tonkingrf1551,

                      Thank you for your reply.

                      Generally with indicators that are calculating on a different time frame, you can use Update() to get more recent values for the secondary series:



                      I'd take a look at this section of our help guide that goes over calculating indicators using a secondary series:


                      Please let us know if we may be of further assistance to you.

                      Comment


                        #12
                        Thanks Kate, very helpful. Another question as I am working through this, with the AddDataSeries(, I want to assign 4 daily bars ago to a int

                        So I am working on the 1min time frame and I want to say "example int" = (CurrentBar - 4); but I want the current bar to be the daily bar. for a high on the daily I would simply say Highs[1][0]

                        How to I specify the CurrentBar needs to be the daily and not the 1min?

                        thank you again for your help.

                        Comment


                          #13
                          Hello Tonkingrf1551,

                          Thank you for your reply.

                          To get the CurrentBar number of a secondary series, use CurrentBars[BarsInProgress index]. For example, to get the current bar number of the first added secondary series:

                          int myValue = CurrentBars[1] - 4;

                          Please let us know if we may be of further assistance to you.

                          Comment


                            #14
                            Kate, thanks so much, I tried that before but missed the 's' on the end of CurrentBars. Thanks for all your help. I will let you know if I have further questions.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            630 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            364 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            105 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            565 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            568 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X