Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Time Frame Calculation not working on first day

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

    Multi Time Frame Calculation not working on first day

    In the Initialize() mehod I have the Add statement Add(PeriodType.Day, 1)

    coded. The Strategy normally runs on a 1 minute chart. I want to calculate the 10 day ATR so I have the following coded near the top of the OnBarUpdate() method:

    if (BarsInProgress == 1)
    {
    Index = CurrentBars[1] - Bars.GetBar(Time[0].Date.AddHours(21));
    dailyATR = ATR(BarsArray[1],10)[Index];

    }

    This works fine except for the first day that I want to start processing trades. Since the BarsArray[0] processes before the BarsArray[1] bars the ATR doesn't get calculated on the first day.

    What would be a good way to correct this?

    #2
    freeway, I'm not exactly sure I'm following you here, there be no meaningful ATR to calculate with one daily bar or here in your example until 10 daily bars are seen.

    Comment


      #3
      Say I am trying to track trades in Aug 2011. I make the From date in the Strategy Analyzer Jul 1, 2011. The data is there. It works on Aug 2 thru Aug 31. It appears to me that the Primary data is processed before the Secondary data. In this case the 1 min Bars array is processed before the Daily data. That is the reason the code I have used doesn't work on the first day. So, I am wondering what I can do make it work on the first day. Is there a way to make the Bars refer to the Daily data while in the 1 min processing?
      Last edited by freeway; 11-01-2011, 11:24 AM.

      Comment


        #4
        You could check for the daily bars also in BarsInProgress == 0 context, your primary series, but this would still not give you a valid ATR to work with on the daily chart, it would those 10 daily bars to stabilize it's values.

        Comment


          #5
          I have it working. Just seems like there ought to be an easier way. In my inputs to the Strategy I have a set of Begin and End dates and the Strategy Analyzer also has it's From and To dates to set. As I said in an earlier post, if I want to process trades for Aug 2011 I enter Jul 1, 2011 in the From date and Aug 31,2011 in the End date.I enter 1 trading day before I want to start processing trades in my Begin date. So for Aug 2011, I enter July 29, 2011 for the Begin date and Aug 31 for End date.

          Comment


            #6
            How can I check for the daily bars in the BarsInProgress = 0 context?

            Comment


              #7
              BarsInProgress just determines which bar series called OnBarUpdate(), you still have access to any of the added bars series.

              So something like this works:
              Code:
              if (BarsInProgress == 0)
              {
              	Print(BarsArray[0].Count);
              	Print(BarsArray[1].Count);
              }

              Comment


                #8
                How can I access the daily ATR while it is processing the bars on the 1 min chart? I couldn't find a way to do that. Had to wait until it was done processing the 1 min data to go to the daily data.

                These statements wouldn't work on the 1 min data (BarsInProgress = 0):

                Index = CurrentBars[1] - Bars.GetBar(Time[0].Date.AddHours(21));
                dailyATR = ATR(BarsArray[1],10)[Index];
                Last edited by freeway; 11-02-2011, 10:00 PM.

                Comment


                  #9
                  I'm not exactly sure what you're trying to accomplish. However, it's always helpful when you're having problems to use some debugging/print statements to check the values that are being used vs those you think are being used.

                  Taking your examples and putting in some print statements:
                  Code:
                  if (BarsInProgress == 0)
                  {
                  	Index = CurrentBars[1] - Bars.GetBar(Time[0].Date.AddHours(21));
                  	dailyATR = ATR(BarsArray[1], 10)[Index];
                  	Print("CurrentBars = " + " " + CurrentBars[1]);
                  	Print("BarTime = " + " " + Time[0].Date.AddHours(21));
                  	Print("Index = " + " " + Index);				
                  }
                  gives output like this:
                  CurrentBars = 9
                  BarTime = 11/3/2011 9:00:00 PM
                  Index = -14001
                  CurrentBars = 9
                  BarTime = 11/3/2011 9:00:00 PM
                  Index = -14001

                  Using BarsInProgress == 1:
                  Code:
                  if (BarsInProgress == 1)
                  {
                  	Index = CurrentBars[1] - Bars.GetBar(Time[0].Date.AddHours(21));
                  	dailyATR = ATR(BarsArray[1], 10)[Index];
                  	Print("CurrentBars = " + " " + CurrentBars[1]);
                  	Print("BarTime = " + " " + Time[0].Date.AddHours(21));
                  	Print("Index = " + " " + Index);				
                  }
                  Gives output like this:
                  CurrentBars = 8
                  BarTime = 10/31/2011 9:00:00 PM
                  Index = 0
                  CurrentBars = 9
                  BarTime = 11/1/2011 9:00:00 PM
                  Index = 0

                  Are those values for your Index what you are expecting expecting them to be? It is either always 0 or negative values.

                  As I said before, perhaps I'm not sure what you're trying to do, but that certainly doesn't seem right.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  647 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  368 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  571 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X