Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Acessing previous High and Low in Current Day High Low indicator

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

    Acessing previous High and Low in Current Day High Low indicator

    Iam trying to access the previous high low value using the CurrentDayOHL1.CurrentHigh[1], but it throws me an error
    OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range.

    Can you please let me know how to access previous high and low?

    Thanks in advance
    Last edited by srganesh; 05-26-2020, 07:31 PM.

    #2
    Hello srganesh,

    Thanks for your post and welcome to the NinjaTrader forums!

    The error is caused by trying to access a bar that does not exist at the moment the script is run.

    Background: All scripts when added to a chart will start processing on the very first historical bar of data. If on that first bar of data your code tries to access a previous bar of any kind it will fail with the error you have observed.

    Your code will need to prevent processing on the first few bars of the historical data file. The way to do this is at the top of OnBarUpdate() to add code to check the CurrentBar (system bar counter) against some number of bars that you decide. If the CurrentBar is less than the number of bars you decide then your code should "return" at that point meaning your code below that line would not be executed until that condition is not true. For example:

    if (Currentbar < 20) return; // do not process below this line until 20 bars processed.

    Please see the help guide here: https://ninjatrader.com/support/help...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks. It works when i skip few bars using the above condition.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      21 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X