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

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
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by trilliantrader, 04-18-2024, 08:16 AM
      4 responses
      18 views
      0 likes
      Last Post trilliantrader  
      Started by mgco4you, Today, 09:46 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by wzgy0920, Today, 09:53 PM
      0 responses
      10 views
      0 likes
      Last Post wzgy0920  
      Started by Rapine Heihei, Today, 08:19 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 08:25 PM
      0 responses
      10 views
      0 likes
      Last Post Rapine Heihei  
      Working...
      X