Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help - Oscillator Variance Calculation

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

    Help - Oscillator Variance Calculation

    Hi all,

    I am looking for help with the following.

    I have an oscillator that has a zero line and can go from 10.000000 to -10.000000.

    What I want to do is calculate the amount of the move between bars, or rather how much did the oscillator oscillate.

    Say for example I was using Oscillator and I wanted to make a decision based on how much it moved between the value as of the current bar for the osc, to the value of the osc 3 bars ago?

    I am basically doing something like:
    (this works fine provided my osc values are both above zero)
    if (Oscillator(PoFast, PoSlow, PoSmooth)[0] > Oscillator(PoFast, PoSlow, PoSmooth)[3]
    && Oscillator(PoFast, PoSlow, PoSmooth)[
    0] - Oscillator(PoFast, PoSlow, PoSmooth)[3] > .1

    ...then do something...

    Now I am pretty sure that this is Freshman math, but I was busy doing more important things, lol. Can someone give me the structure for finding the difference between the values of the osc for given bars?

    Will pay in beer.

    #2
    r2kTrader, not sure I follow - if you have the Oscillator as a dataseries you can easily calculate the difference from current bar to x bars back. Or are you looking for some kind of 'pivot detection' algorithm placed on the oscillator? Then I would check into the code of the Swing indicator that would do this on price.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I thought this through using my scientific calculator, lol, and this is what I came up with. My only kickback was when dealing with negative numbers. I know subtraction is obviously the way to find the difference, but it was the result that was skewing my results.

      So I decided that converting the negative number to an absolute would do the trick (I think, looking for some eyes/help).

      My logic is as follows, I do the opposite for short side:

      1. is osc value from current bar greater than osc value from 3 bars ago, if true, then #2

      2. subtract value of osc from 3 bars ago from osc value value of current bar. (I added the Math.abs to convert the result to a whole number so that I can simply base a decision based on the amount of the difference. I already know if its higher, so the result should be the difference)

      3. if variance is great than x, then do something.



      if (Oscillator(PoFast, PoSlow, PoSmooth)[0] > Oscillator(PoFast, PoSlow, PoSmooth)[3]
      && Math.Abs(Oscillator(PoFast, PoSlow, PoSmooth)[
      0] - Oscillator(PoFast, PoSlow, PoSmooth)[3]) > 0

      Comment


        #4
        Just an idea, maybe simpler: try using the absolute value of the x bar momentum of your oscillator for your decisions.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Just an idea, maybe simpler: try using the absolute value of the x bar momentum of your oscillator for your decisions.
          Bertrand,

          Thanks for the reply.

          Couldn't that skew my results if say my values were as follows?

          1 bar ago (1BA)= -.2
          Current bar (CB) = .3

          Wouldn't I get a value of 1 if I did something like:
          Abs(CB) - Abs(1BA) = .3 - .2 = 1

          Whereas:
          Abs(CB- 1BA) = .3 - -.2 = 5

          I could REALLY use a definitive answer on this and I am increasing the answer bounty to 2 beers, microbrewed!

          I want to know the different between the moves of old bars to new bars on my osc and then make a decision based on the deviation or rather the amount of the move.

          Comment


            #6
            I guess you would need to chart the alternatives and then check the needed requirements visually, AbsValue would just affect the sign, not the rounding.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              I guess you would need to chart the alternatives and then check the needed requirements visually, AbsValue would just affect the sign, not the rounding.
              Right, it would take say -5 and make it 5, correct? But isn't that what I want? I want to simply know the diff between the osc value of current bar and 3 bars ago. Just the deviation. To do my compare, it's best to work with a whole value, verses say -5.

              So based on my prior post, is my code/logic correct?

              Also, sidenote, this is an NT related question. As it stands, I am running this calc on every bar update, but I only want to run this calc on bar close. Is there a code snippet to do this? Bear in mind, I want my strategy NOT to calcOnBarClose, but I don't want to reiterate this snippet every update. Would I setup a bool and then nest the rest of the code inside that test?


              Thanks

              Comment


                #8
                r2kTrader, yes I believe this would do it for you - you can use FirstTickOfBar to do this only on the close then, just keep in mind to reference one bar back further to make up for calling it on the open of the next bar...

                Code:
                 
                if (FirstTickOfBar)
                { 
                do your on bar close calculations
                }
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by r2kTrader View Post
                  Also, sidenote, this is an NT related question. As it stands, I am running this calc on every bar update, but I only want to run this calc on bar close. Is there a code snippet to do this? Bear in mind, I want my strategy NOT to calcOnBarClose, but I don't want to reiterate this snippet every update. Would I setup a bool and then nest the rest of the code inside that test?


                  Thanks
                  if (FirstTickOfBar)
                  dosomething;

                  Would allow rest of strategy to update each tick, and 'dosomething' only on bar close.

                  Mike

                  Comment


                    #10
                    doh! Bertrand is speedy fast

                    Mike

                    Comment


                      #11
                      Pete's Wicked Ale for the both of you!

                      Thank you very much guys.

                      So all things being equal Betrand, my logic of using Abs as per my description is correct? I will be able to calculate the difference between the value of osc from one bar to the other bar and by apply Abs on the result, I will avoid skewing the value of the difference and only convert it to a whole number if it is a negative value?

                      Comment


                        #12
                        r2kTrader,

                        I am not sure where you got the idea that Math.Abs converts to whole numbers. Math.Abs just does absolute values. It doesn't change it to a whole number in the process.

                        Math.Abs(-0.2) = 0.2 for example.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          r2kTrader,

                          I am not sure where you got the idea that Math.Abs converts to whole numbers. Math.Abs just does absolute values. It doesn't change it to a whole number in the process.

                          Math.Abs(-0.2) = 0.2 for example.
                          symantics, I'm not a programmer.

                          Let me rephrase. I meant positive, not whole. :-(

                          Comment


                            #14
                            Then that is correct. You will get appropriate positive values for comparison.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Josh,

                              Will this work?

                              private double[] values = Oscillator(PoFast, PoSlow, PoSmooth);
                              private double currentBar = values[0];
                              private double oneBarAgo = values[3];

                              if (currentBar > oneBarAgo && Math.Abs(currentBar - oneBarAgo) > .25)
                              {
                              // do something
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,221 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              437 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X