Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I reset the OBV at the start of the session?

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

    How can I reset the OBV at the start of the session?

    I've copied the OBV indicator, adding (for a 6:PM reset) :
    if (ToTime(Time[0]) = 180000)
    Value.Set(0);
    which didn't work, so I tried (for a midnight reset):
    if (ToDay(Time[0]) != ToDay(Time[1]))
    Value.Set(0);
    which also didn't work. I didn't touch anything else in the indicator, except changing all the OBV references to myOBV, and inserting the above lines as the first line under the OnBarUpdate. Both options compiled fine... the first one didn't reset the OBV, and the second one didn't even produce an indicator plot?????
    What am I doing wrong?

    #2
    The second is likely throwing an error message to the output window (tools -> output window) about bars being out of range. This is because on the first bar your trying to access 1 bar ago. You can use a Current Bar check to prevent this



    What are you trying to do at 6pm?
    Value.Set(0);
    will make the current plot value drop to 0

    I look forward to assisting further
    LanceNinjaTrader Customer Service

    Comment


      #3
      Yes, I want the OBV to reset to 0 either at the session start or at midnite... i don't really care which. There is already a CurrentBar check built into the provided OBV indicator... which i did not remove, I just added my instruction before it, as follows:

      protected override void OnBarUpdate()
      {
      if (ToTime(Time[0]) = 180000)
      Value.Set(0);
      if (CurrentBar == 0)
      Value.Set(0);
      else
      {
      if (Close[0] > Close[1])
      Value.Set(Value[1]+ Volume[0]);
      else if (Close[0] < Close[1])
      Value.Set(Value[1] - Volume[0]);
      else
      Value.Set(Value[1]);

      Comment


        #4
        By adding this before the current bar check you're going to set the value to zero and then keep evaluating which would then set the value based on the condition in the code. Value.Set(0) does not stop the script from continuing to process.

        The C# code will continue to evaluate logically one step at a time.

        If you wanted to reset the value at a specific time you would likely want to put this at the end of the OnBarUpdate()

        If possible could you create a drawing of what you want to display? I'm still not understanding what resetting this value would achieve. Are you wanting the OBV indicator to only display the current value for the current day and clear the previous values at a new session?
        LanceNinjaTrader Customer Service

        Comment


          #5
          Yes, you do understand. As a daily"market sentiment" gauge, I want to know only the daily OBV, not the OBV of the entire chart history. And, putting it at the end of the OnBarUpdate worked! In my head, I thought it would work logically at the front, also... reading the command as the first parameter on every bar update... so I'm still at a loss as to why it doesn't? Thank you very much for getting it to work!

          Comment


            #6
            This would partially depend on the type of chart you were running the script on. If you just want Daily OBV you could run the indicator on daily bars with CalculateOnBarClose = false

            Placing it up front does work, however moments later it will be set again, negating your initial reset. By placing it at the end you ensure it clears any value that may have been set.

            Consider doing something like this if you want to avoid the coding route: http://www.youtube.com/watch?v=x_6BN5SIiig

            For coding also, consider resetting previous values at the start of the new session


            You can also reset previous values if needed by using .Reset()


            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            579 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 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
            554 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