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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      7 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X