Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pitfall: Historical multi-series GetClose(CurrentBars[..]) can see into the future

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

    Pitfall: Historical multi-series GetClose(CurrentBars[..]) can see into the future

    I'm not going to say for certain whether this is a bug or not, but it was a slightly unintuitive quirk that had me stumped for a few hours.

    Let's say you add two data series, a 1 minute and a 5 minute. On bar close, you only run logic if BarsInProgress == 1. One of these logics involves BarsArray[2].GetClose(CurrentBars[2])

    In historical data, the 5 minute bar close has already been determined (seeing into the future).

    In real time data, the 5 minute bar close is updated for every minute bar as they happen.

    The workaround is very simple, only use your fine-grained current bar close for the most recent data. I'm posting this to spark discussion and make sure y'all don't fall for this too.

    #2
    nathanfranke You're not going to like this answer, but this is actually understood to be the way that it works. It's very well documented at https://ninjatrader.com/support/help...nstruments.htm - expand the sections and study this page carefully.

    Basically, you should not be doing .GetClose[CurrentBars[x] - y] but should be doing Closes[x][y] because what you're doing (at least for Calculate.OnPriceChange or Calculate.OnEachTick) is seeing incomplete bars instead of complete bars, and for historical, they're basically all known to be completed at once, while in realtime, that is not necessarily the case. That should be enough to get you started.

    This is, indeed, an area where one could get wrapped around the axle. It would be great if realtime and historical worked exactly the same for multi time frames but that's harder than it sounds.
    Last edited by QuantKey_Bruce; 06-03-2023, 04:25 AM.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello nathanfranke,

      Thanks for your post.

      QuantKey_Bruce is correct in stating that this is understood to be the way that this works. Please review the help guide page QuantKey_Bruce shared.

      Instead of using BarsArray[2].GetClose(CurrentBars[2]) you need to use Closes[int barSeriesIndex][int barsAgo] to get close price values from a series in a custom NinjaScript. For example, to get the current close price of the second added series in a NinjaScript, Closes[2][0] should be used.

      See this help guide page about Closes: https://ninjatrader.com/support/help...nt8/closes.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X