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

BarsAgo synchronization question

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

    BarsAgo synchronization question

    How does BarsAgo work when some sequences are a different length?
    For example, I have Microsoft weekly and SPY weekly and I want to take the ratio: Value[0] = Close[0] / SPY[0];

    I figured out that I had to skip the first bars. MSFT has 1546 bars and SPY has 1482. I would think that they'd both be accessible after skipping the first 64 bars. However, if I skip bars 0-92 I get
    Error on calling 'OnBarUpdate' method on bar 93: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.​
    It works fine if I skip bars 0-93. Clearly, I do not understand the bars synchronization. Why do I have to skip so many bars?

    #2
    Hello ETFVoyageur,

    I see that you deleted your comment and said the post became obsolete, do you mean the entire thread or just the post you deleted? If this thread is obsolete I will close the case.
    JesseNinjaTrader Customer Service

    Comment


      #3
      No ... just that post.

      My question about bar synchronization remains. My knowledge is evidently incomplete or incorrect so please help with the correct information:
      • The situation is that I am processing two bar series that are not the same length.
      • The question is how many bars OnBarUpdate() must skip before accessing both series.
      • I would have thought skipping the difference in the two series' lengths but experience has proven that is wrong.
      • Question: how do I calculate the number of bars for OnBarUpdate() to skip before it can access both series with [0]?
      • Question: does it matter whether the longer series is the primary series?
      • Question: once both series can be accessed, I presume synchronization means that [0] refers to the same bar for each -- is that correct?

      Comment


        #4
        Hello ETFVoyageur,

        When you request data that is processed based on the bars type you selected. For example if you used 5 minutes you would have 5 minute bars where data is available for each instrument. If one of the series doesn't have data for certain periods OnBarUpdate won't be called for that bars in progress during that time. The easiest way to explore this would be to use prints and print out the bar time and BarsInProgress. That will let you see which datapoints are being processed for each series.

        Question: how do I calculate the number of bars for OnBarUpdate() to skip before it can access both series with [0]?
        ​If you require 0 bars ago you dont have to calculate anything, just use 0 bars ago. If you use 1 bars ago you would use a if(CurrentBar < 1) return; condition to wait 1 bar. For multi series scripts you may also have if(CurrentBars[0] < 1 || CurrentBars[1] < 1) if you need 1 bar on each series before processing.

        Question: does it matter whether the longer series is the primary series?
        ​No

        Question: once both series can be accessed, I presume synchronization means that [0] refers to the same bar for each -- is that correct?
        ​[0] bars ago is only relevant to the series being processed. The two series are not in direct sync because they are two different instruments with different data. [0] bars ago is relevant to right now in processing on that bars in progress.

        JesseNinjaTrader Customer Service

        Comment


          #5
          [edit] I reported a problem with the indicator refreshing extremely slowly after I fixed OnBarUpdate(). I subsequently found the fix -- restart NinjaTrader. This is not the first time. I have learned that when I encounter inexplicable behavior, one thing to try is to restart NT -- that often fixes the problem.

          ---

          That aside, thanks, Jesse, your answer put me on the right track and it works fine now (since restarting NT).
          Last edited by ETFVoyageur; 05-29-2024, 09:18 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Pole123, Today, 06:02 PM
          0 responses
          8 views
          0 likes
          Last Post Pole123
          by Pole123
           
          Started by samish18, Today, 05:27 PM
          0 responses
          5 views
          0 likes
          Last Post samish18  
          Started by Tonkingrf1551, Today, 03:59 PM
          0 responses
          10 views
          0 likes
          Last Post Tonkingrf1551  
          Started by rocker84, Today, 03:10 PM
          0 responses
          14 views
          0 likes
          Last Post rocker84  
          Started by Oracletrades, 02-21-2020, 01:37 PM
          17 responses
          2,066 views
          0 likes
          Last Post Ttrade12  
          Working...
          X