Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi TimeFrame Question

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

    Multi TimeFrame Question

    I want to get the 10 period ATR from the Daily chart when I am on another time frame chart. When I code an Add(PeriodType.Day, 1); in the Initialize method the Strategy doesn't work right. What else do I have to do?

    #2
    freeway, what OnBarUpdate() code are you then using that would work on the added bars to calc the ATR?

    Comment


      #3
      Here is the code dailyATR = ATR(BarsArray[1],10)[1];

      But the problem is, once that Add statement is in the Initialize method the strategy doesn't enter the trades it does without that statement. This code for the dailyATR is not the problem.

      Comment


        #4
        That looks ok, thanks - in which BarsInProgress are you trading then? Once a series is added you would need to filter the OnBarUpdate() calls for the correct series to do your calcs and execute trades.

        Comment


          #5
          Before I put the Add statement in I was doing testing on Aug 2011. I was getting 124 trades. When I put in the Add statement the number of trades went to 15. So I put in a if(BarsInProgress != 0) return; statement in the OnBarsUpdate method. Still got only 15 trades. And actually those 15 trades are on Jul 31 and Sep 1. Is there a way to get access to the From and To dates so I can prevent processing the day before the From date and the day after the To date?
          Last edited by freeway; 10-28-2011, 10:44 AM.

          Comment


            #6
            Hi Freeway,

            Is there a way to get access to the From and To dates
            Unfortunately this information is not available via NinjaScript.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              When you implement additional TF, especially so big as Day, you must add your own StartDate variable, or calculate the value for "BarsRequired".
              In your case you want a Daily ATR(10). That means that you need to load 10 days of data before you will have a reliable value.
              To do it in your example:
              private int StartDate = 20110801; //Aug 1, 2001

              In OnBarsUpdate:
              if (ToDay(Time[0]) < StartDate) return;

              In backtest: From: 07/15/2011
              You can add ToDate too, but its less important.

              Baruch

              Comment


                #8
                I have to make the From date in Backtest 1 month before I want to start processing trades. This does work for what I want to do but I don't quite understand why I have to go a whole month before I want to process the trades in the To Date. e.g. to process trades in Aug 2011 I have to enter July 1 2011 as the start date. Also the daily ATR is not being calculated correctly. Here is a part of my code:

                protected override void Initialize()
                {

                // ClearOutputWindow();

                Add(PeriodType.Minute ,1);

                Add(PeriodType.Day, 1);

                sBeginHH = SessionBeginTime.ToString().Substring(0,2);
                sBeginMM = SessionBeginTime.ToString().Substring(3,2);
                sBeginSS = SessionBeginTime.ToString().Substring(6,2);

                sBeginTime = sBeginHH + sBeginMM + sBeginSS;
                beginTime = Convert.ToInt32(sBeginTime);

                sEndHH = SessionEndTime.ToString().Substring(0,2);
                sEndMM = SessionEndTime.ToString().Substring(3,2);
                sEndSS = SessionEndTime.ToString().Substring(6,2);

                sEndTime = sEndHH + sEndMM + sEndSS;
                endTime = Convert.ToInt32(sEndTime);

                Add(EMA(LittleMoPeriod));
                Add(EMA(BigMoPeriod));



                CalculateOnBarClose = true;


                }

                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                ///
                protected override void OnBarUpdate()
                {
                if(ToDay(Time[0]) < StartDate) return;

                if (BarsInProgress == 1)
                {
                dailyATR = ATR(BarsArray[1],10)[1];
                }
                if (BarsInProgress != 0) return;

                What do I have to do the calculate the dailyATR correctly?

                Comment


                  #9
                  freeway, the reason is the BarsRequired setting has to be fulfilled for all series, if you run with the default of 20, this would mean 20 daily bars have to be available as well before any OnBarUpdate() call is run. You can set this to a lower # but be aware the ATR would need 10 bars minimum (your period) to produce meaningful values.

                  Comment


                    #10
                    Bertrand,
                    I know that I can verify it my self, but I'm too lazy.
                    So what is correct?
                    In help file it says that BarsRequared applies ONLY to primary BIP.

                    and you say the opposite
                    the reason is the BarsRequired setting has to be fulfilled for all series, if you run with the default of 20, this would mean 20 daily bars have to be available as well before any OnBarUpdate() call is run.

                    Comment


                      #11
                      Baruch, it's applied for all series - where did you read to the contrary please so we can amend the docs?

                      Comment


                        #12
                        Here
                        Baruch
                        BarsRequired
                        Definition
                        The number of historical bars required before the strategy starts processing calls to the OnBarUpdate() method. This property is generally set via the UI when starting a strategy.

                        The OnBarUpdate() method is not triggered until CurrentBar >= BarsRequired. In a multi-series strategy this restriction applies only for the primary Bars object. Should your strategy logic intertwine calculations across different Bars objects please ensure all Bars objects have met the BarsRequired requirement before proceeding. This can be done via checks on the CurrentBars array.

                        Comment


                          #13
                          Correct, if you check with CurrentBar it would check only for the primary series, hence you need a CurrentBars check for the other series as well if you're working a MultiSeries Script.

                          if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
                          return;

                          Comment


                            #14
                            No, what it says is that you don't need to check. NT does it by itself.

                            Comment


                              #15
                              Originally posted by Baruch View Post
                              No, what it says is that you don't need to check. NT does it by itself.
                              This is unfortunately not correctly interpreted Baruch, you would need to do the check.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              656 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              371 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              579 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X