Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple time frame issue

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

    Multiple time frame issue

    Hi, I'm testing a strategy that uses data from two time frames.

    I've added the time frames in the Initialize function

    Add(PeriodType.Day, 1);
    Add(PeriodType.Week, 1);

    In the OnBarUpdate function I have limited the strategy only to update bars only when there's a new daily bar:

    if (BarsInProgress != 1)
    return;

    My question is this. If I run my strategy and select "Day" as the data series type and "1" as the value why don't I get the same result if I change BarsInProgress to "!= 0"?

    Like this:

    if (BarsInProgress != 0)
    return;

    What is the difference between the two settings, when the backtest settings and the settings in the initialize function are the same?

    #2
    db8r,

    There are 3 bar objects based on the code you have provided.

    BarsInProgress 0 <-- primary bars as determined by the chart
    BarsInProgress 1 <-- your daily bars
    BarsInProgress 2 <-- your weekly bars

    Setting BarsInProgress != 0 means you will process BarsInProgress 1 and 2.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your swift reply. I'm not quite understanding why BarsInProgress 1 and 2 will be processed. What setting BarsInProgress to 0 is doing is getting all other settings than 0 to return (i.e. not be processed). Why would then BarsInProgress 1 and 2 be processed?

      Either way I think I've gotten my head around how I will test on multiple time frames and process only on daily bars. I will define daily bars in the Initialize function, set BarsInProgress to 1 and specify BarsArray[1] as data series in any indicators that I use. That seems to give me accurate results.

      Comment


        #4
        Right, I missed the "return" line you placed after the if-statement. Your analysis is correct.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        64 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Working...
        X