Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Instrument Strategy

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

    Multiple Instrument Strategy

    Dear Support,

    I have a question, when I write a multiple instrument strategy, I make sure to write if(BarsInProgress == 0){ do something} on OnBarsUpdate.

    But I'm curious, how can you be so sure that bars for all the other instruments are updated when the instrument [0] is updated?

    Is there any way I can confirm that all instrument bars are created when I run the strategy?
    I need to make sure because otherwise, the performance will not match the simulation.


    Would appreciate your advise.


    Best Regards,
    hana_maui

    #2
    You can check the number of BarsArray that have been added to the strategy OnStartUp() before it starts processing in OnBarUpdate.

    There are a number of ways to handle this, but here is one example

    Code:
    			protected override void OnStartUp()
    			{
    				int bars = 0;
    				
    				foreach (object b in BarsArray)
    				{
    					
    					bars++;		
    					
    				}
    					
    				Print(bars);
    					
    			}
    MatthewNinjaTrader Product Management

    Comment


      #3
      Dear Mr Matthew!


      Thanks for the reply.

      Now, I have another question.

      What happens if I have two instruments on a strategy and I mentioned if (BarsInProgress == 0) ( do something) and when the bar for the instrument 0 was complete and this event triggered the other instrument's bar was not complete? Will Closes(1)(0) fetch the current price of instrument 1, even though that bar is not complete?
      Please let me know what happens.
      Thank you

      Best regards,
      Hana Maui

      Comment


        #4
        Is this calculate on bar close = true/false?
        MatthewNinjaTrader Product Management

        Comment


          #5
          It is CalculateOnBarClose == true

          Could you let me know what the NT would return for Closes(1)(0) ?
          1) close of the previous bar?
          2) current price of the last bar?
          3) wait till the instrument 1 closes the corresponding bar and return the close price for that bar in sync with instrument 0?

          Another question.
          What happens on other hand, when the instrument1 had already closed the bar and started running the next bar?
          Will Closes(1)(0) return
          1) closing price of the bar in sync with the time that the instrument 0 is referring to?
          2) current price of the last bar?

          Look forward to hearing from you.

          Thank you.

          Comment


            #6
            Originally posted by hana_maui View Post
            It is CalculateOnBarClose == true

            Could you let me know what the NT would return for Closes(1)(0) ?
            When using CalculateOnBarClose true, this will return the last closed bar of BarsArray[1]. This will not be the current price of the bar forming unless you have COBC=false.


            Originally posted by hana_maui View Post
            Another question.
            What happens on other hand, when the instrument1 had already closed the bar and started running the next bar?
            It will still return the closing price of the last completed bar for that series. This will not matter if the primary series has completed and moved on.

            I think if you open a chart with a 1 minute data series and then a 10 minute data series manually added, so you can physically see the two bars array, this should help clear up what's happening. You may also consider using DrawText() objects to draw the CurrentBars value on the chart to visualize this.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Dear Mr. Matthew,

              Thank you very much. I understand.

              hana_maui

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 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
              572 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