Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    Comment


      #3
      Thanks Brett. Now it works :-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,609 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      9 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      19 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      6 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      16 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X