Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 kevinenergy, 02-17-2023, 12:42 PM
          117 responses
          2,765 views
          1 like
          Last Post jculp
          by jculp
           
          Started by Mongo, Today, 11:05 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by SightCareAubetter, Today, 12:55 PM
          0 responses
          3 views
          0 likes
          Last Post SightCareAubetter  
          Started by traderqz, Today, 12:06 AM
          8 responses
          16 views
          0 likes
          Last Post traderqz  
          Started by SightCareAubetter, Today, 12:50 PM
          0 responses
          2 views
          0 likes
          Last Post SightCareAubetter  
          Working...
          X