Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument question

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

    Multi instrument question

    Hello. I've read all the content in the help guide, but still can't get my head around the concept.

    Assume I have two instruments, both running on 30 min bars.
    My question is, does instrument number two (BarsInProgress =1) always complete after instrument number one (BarsInProgress = 0)?
    In other words, does

    If (BarsInProgress = 1)
    {
    Print (Closes[1][0])
    Print Closes [0][0])
    }
    return closing values that correspond to the same time stamp?

    Similarly, would
    If (BarsInProgress = 0)
    {
    Print (Closes[1][0])
    Print Closes [0][0])
    }
    return a "current" value for the first instrument, but a value for the second instrument corresponding to the prior close time?

    In general, I'm just looking for advice as to what BarsInProgress I want to use if I'm trying to reference prices for both instruments that correspond to the same time. Similarly, if I'm calling an indicator for each instrument, do I need to do that from within a particular If BarsInProgress =, and then use the BarsInProgress = 1 if comparing them, to make sure they correspond to the same time?

    Hope this makes sense. Thanks

    #2
    Hello stewarco,

    Thanks for your question. It is not guaranteed that BarsInProgress 0 will always come before BarsInProgress 1. These will be processed in chronological order, timestamps of the bar for historical data, and then as the bar updates are received with realtime data.

    Code:
    if (BarsInProgress = 1)
    {
        Print(Closes[1][0]);
        Print(Closes [0][0]);
    }
    The above condition checks if your first added data series is processing in OnBarUpdate, and then you print the Close of that data series (Closes[1][0]) and the most recent value the script saw from from the primary data series (Closes[0][0])

    Code:
    if (BarsInProgress = 0)
    {
        Print(Closes[1][0]);
        Print(Closes [0][0]);
    }
    The above condition checks if the primary data series is processing in OnBarUpdate, and then you print the most recent Close of the first added data series (Closes[1][0]) and the Close of the primary data series that is currently processing/has just been updated (Closes[0][0])

    These do not necessarily mean the values corresponding to the same timestamp. They would be the "last seen value at the time the print was processed."

    If you want to reference prices as the primary data series is updated, place logic in a BarsInProgress == 0 check. If you want to references prices as the secondary series updates, use a BarsInProgress == 1 check.

    For the threads reference, please see the Multi Time Frame and Instruments documentation for complete information on working with multiple data series.

    https://ninjatrader.com/support/help...nstruments.htm

    We look forward to assisting.

    Last edited by NinjaTrader_Jim; 10-16-2020, 10:27 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      hey Jim thanks. that makes sense.
      but so I'm clear, is there any way for me to make sure I'm comparing bars that are both complete with the same end time? would it work if I used an if statement comparing the bar star/ end times? e.g. check time on the current bar in progress/ instrument, compare it to the other instrument, and if the times match I know the other one has already completed, otherwise i need to wait for the next bar in progress/ instrument, at which point I'll know both have completed with the same end time?

      Comment


        #4
        Hello stewarco,

        You are on the right track.

        You could compare the timestamps for each bar within each BarsInProgress check (since we cannot know if one instrument will have a bar closure at the same time as another bar, and bar closures are signaled by the first tick of a new bar) and if the timestamps match, you have found a corresponding bar.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          great. thanks again

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by my-trade, Today, 10:45 AM
          0 responses
          7 views
          0 likes
          Last Post my-trade  
          Started by localappleseed, Today, 09:51 AM
          0 responses
          3 views
          0 likes
          Last Post localappleseed  
          Started by wehewwehd, Today, 09:13 AM
          0 responses
          4 views
          0 likes
          Last Post wehewwehd  
          Started by aaajv, Yesterday, 06:45 AM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Started by asmmbillah, Today, 08:13 AM
          0 responses
          5 views
          0 likes
          Last Post asmmbillah  
          Working...
          X