Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple multi instrument use case - I don't get it

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

    Simple multi instrument use case - I don't get it

    Hello,

    i don't understand how to write simple multi instrument strategies which do the following things:

    - add some (e.g. 3) instruments to the strategy
    - on OnBarUpdate, evaluate all 3 instruments
    - based on the evaluation, place an order for one of the three instruments.

    I tried two different approaches:

    1)

    Code:
    protected override void Initialize()
    {
         // Add 3 instruments
         Add("AAA", PeriodType.Day, 1);
         Add("BBB", PeriodType.Day, 1);
         Add("CCC", PeriodType.Day, 1);
    }
    		
    protected override void OnBarUpdate()
    {
         if (BarsInProgress != 0)
         {    // No call for PRIMARY instrument
              return;
         }
    
         // Do some fancy calculation based on Closes[0 ... 3][0],  RSI(BarsArray[0 ... 3], ....), ... 
    
         // Place an order, e.g. for instrument 2:
         EnterLong(2, NewLongAmount, "Some text");
    }
    and 2)

    Code:
    protected override void Initialize()
    {
         // Add 3 instruments
         Add("AAA", PeriodType.Day, 1);
         Add("BBB", PeriodType.Day, 1);
         Add("CCC", PeriodType.Day, 1);
    }
    		
    protected override void OnBarUpdate()
    {
         if (BarsInProgress != 3)
         {    // No call for LAST instrument
              return;
         }
    
         // Do some fancy calculation based on Closes[0 ... 3][0],  RSI(BarsArray[0 ... 3], ....), ... 
    
         // Place an order, e.g. for instrument 2:
         EnterLong(2, NewLongAmount, "Some text");
    }
    With 1) there is the problem that series 1 - 3 are not up to date, Closes[2][0] is not the close of instrument 2 the current day

    For 2), Closes[2][0] has the right value but orders placed for instruments 1 - 2 are executed with one day delay -> one day to late!

    What am i missing? How can i solve this?

    Regards, Robin

    #2
    Hi Robin,

    Thanks for the post and welcome to the NinjaTrader forums. I would look at this help guide article in the section How Bar Data is Referenced in a multiseries strategy.

    Data availability varies depending on whether you're accessing historically or real time with CalculateOnBarClose = false.

    The key point is the time stamp of all series, because in a historical sense you are not able to access data time stamped in advance of other series. To this end, it may be useful for you to print the time stamps of all series and see how they relate to one another.

    if (BarsInProgress == 0)
    Print("BIP0 " + Time[0] + " BIP1 " + Times[1][0] + " BIP2 " + Times[2][0]);

    For evaluating the timing of orders compared to when the condition evaluates true, it's useful to add drawing objects for additional signal verification. In a historical sense you should expect that the order is submitted the next bar following the condition.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      i forgot to mention, it's only about historical backtesting at the moment. So maybe it's easier to focus just on that to prevent further confusion. And it's still Ninja Trader 6.5, but i guess such fundamental things did not change from 6.5 to 7

      I read the section you mentioned but still not know how to solve my problem. There are different time-frames mixed, i have various instruments with one (same) timeframe.

      I think i understood the time stamp issue. For my sample above it would be as follows:

      Code:
      if (BarsInProgress == 0)
      {
         // Time[0] == Day N    Time[0][0] == Day N    Time[1][0] == Day N-1   Time[2][0] == Day N-1   Time[3][0] == Day N-1
      }
      if (BarsInProgress == 1)
      {
         // Time[0] == Day N    Time[0][0] == Day N    Time[1][0] == Day N   Time[2][0] == Day N-1   Time[3][0] == Day N-1
      }
      ...
      So, it' clear that to process Day N for all intruments together, i have to wait until
      Code:
      if (BarsInProgress == 3)
      But the problem is still that
      Code:
       if (BarsInProgress == 2) EnterLong(2, NewLongAmount, "Some text");
      and
      Code:
       if (BarsInProgress == 3) EnterLong(2, NewLongAmount, "Some text");
      are not equal, the second one delays the order for instrument 2 by one additional day!

      I hope i explained it better this time. Sorry if not

      Thank you!

      Comment


        #4
        Actually the multi-series model did change from version 6.5 to 7. Version 6.5 had a limitation where secondary series only work when smaller than the primary. We recommend evaluating any multiseries scripts using version 7 only because of this.

        Give yours a run using version 7 and let us know if we can be of further assistance.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        670 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X