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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      134 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      75 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      119 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      114 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      92 views
      0 likes
      Last Post CarlTrading  
      Working...
      X