Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentDayOHL: reseting values at specific time

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

    CurrentDayOHL: reseting values at specific time

    Hello,

    I am trying editing CurrentDayOHL indicator. I want to reset values when RTH opens on ETH session template with historical data.

    RTH opens at 15:30 in my time zone.

    This is edited condition for reseting values:
    if ((ToTime(15, 30, 0) > ToTime(Time[1]) && (ToTime(15, 30, 0) <= ToTime(Time[0]))) || currentOpen == double.MinValue)

    I want to compare 1 bar ago if bar is before 15:30 and current bar if time is 15:30 or more. It doesn't work. I want to use this method because I am using Range Bars. I tried printing value ToTime(Time[1]) and I got this message "Error on calling 'OnBarUpdate' method for indicator 'MyCurrentDayOHL' on bar 0: Bar index needs to be greater/equal 0". ToTime(Time[0]) works.

    What am I doing wrong?

    Thanks for responding.

    #2
    Hello,

    Thanks for the note.

    Anytime you access a previous bar value you have to make sure that value exists before you access it. The reason is that indicators start on the first bar on the chart and then calculate all values forward until the last bar on the chart.

    If the calculation is run on the first bar on the chart and on that first bar in the chart you try to access 1 bar ago that would not exist for that bar and would error with the error you posted.

    To prevent this error please use this example:



    Let me know if any further questions.
    BrettNinjaTrader Product Management

    Comment


      #3
      Thanks Brett. Now it works :-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      574 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      332 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X