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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      57 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      78 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      39 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      101 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      61 views
      0 likes
      Last Post PaulMohn  
      Working...
      X