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

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 Shansen, 08-30-2019, 10:18 PM
            24 responses
            938 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            3 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            2 views
            0 likes
            Last Post rocketman7  
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            27 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Working...
            X