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 andrewtrades, Today, 04:57 PM
      0 responses
      3 views
      0 likes
      Last Post andrewtrades  
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      6 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X