Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access historical bars via Low[]

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

    Access historical bars via Low[]

    I have used Metatrader 4 so far and am currently in the process of becoming friends with NinjaTrader.

    I would like to access historical bars using Low[] in an indicator.

    For Low[0] this seems to work. See example 1.

    It doesn't seem to work for Low[10] . See example 2.

    Can someone explain why Low[10] doesn't seem to work?

    Seems like a silly, simple problem, but I just can't figure out the solution....​
    Attached Files

    #2
    Hello Joost,

    You are likely seeing an error here, its best to keep the control center log tab and NinjaScript output window in view while testing scripts. The problem is that you can't use 10 bars ago before processing 10 bars. Your script always starts at bar 0 and works forward, trying to access 10 bars ago on bar 0 doesn't make sense because there are not 10 bars before bar 0.

    To fix this type of problem you can check the CurrentBar. NinjaScript is C# language so you can use features like return to stop code execution past that point based on a condition.

    Code:
    if(CurrentBar < 10) return;
    // do something with Low[10] after this point

    Comment


      #3
      Perfect, thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      43 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      27 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      163 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      158 views
      2 likes
      Last Post CaptainJack  
      Working...
      X