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

Calculation of AO values

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

    Calculation of AO values

    I have some problem calculating the value of the AO indicator.

    As variables, I have :

    Code:
    // AOMinusOne is the previous AO bar. AOMinusTwo is 2 bars before
            
            bool AOMinusOne;
            bool AOMinusTwo;
    Calculation is at bar close. I think my problem is in this part :

    Code:
      protected override void OnBarUpdate()
            {
                
            //    Calculation of AOMinusOne
            // If AOMinusOne is red, AOMinusOne is false, else, is true
                if (FirstTickOfBar) {
                    
                    if ((AO()[Math.Min(CurrentBar, 1)] < AO()[Math.Min(CurrentBar, 2)]))
                        AOMinusOne = true;
                    else 
                        AOMinusOne = false;
    .......
    I want to draw a pink diamond when :

    Code:
            if ((AOMinusOne== false));
                {
                    DrawDiamond("My diamond" + CurrentBar, false, 0, High[0], Color.LightCoral);
                }
    The problem is that the diamond is drawn at the high of each bar, not only when the previous AO bar is red....
    I think, my problem is in the definition of the previous AO bar : AO()[Math.Min(CurrentBar, 1)

    Any ideas ?

    Thank you very much for your help !
    Jed

    #2
    You would probably want to use AO().AOValue[int barsAgo] if you are using my 3rd party release. http://www.ninjatrader-support2.com/...ome+oscillator
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Like this ?

      Code:
      if ((AO().AOValue[1 barsAgo] < AO().AOValue[2 barsAgo]))
                          AOMinusOne = true;
                      else 
                          AOMinusOne = false;
      I have some syntax errors....
      Cannot see what....

      Thank you for your help !

      Comment


        #4
        if (AO().AOValue[1] < AO().AOValue[2])
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          OH !
          Thank you

          and, in order to avoid the problem of the "index out of range" I should do like that :
          Code:
          if ((AO().AOValue[Math.Min(CurrentBar, 1)] < AO().AOValue[Math.Min(CurrentBar, 2)]))
                              AOMinusOne = true;
                          else 
                              AOMinusOne = false;
          Is it ?
          Thank you.

          Comment


            #6
            Or you can just do
            Code:
            if (CurrentBar < 2)
                 return;
            at the start of the OnBarUpdate() method.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Ok, thank you !

              I still have a diamond at the high of each bar....

              Any ideas ?

              Code:
              if (CurrentBar < 2)
                                   return;
                          
                          if (FirstTickOfBar) {
                              
                              if ((AO().AOValue[1] < AO().AOValue[2]))
                                  AOMinusOne = false;
                              else 
                                  AOMinusOne = true;
              
              .........
              
              if ((AOMinusOne== false) 
              
                                  );
                          {
                              DrawDiamond("My diamond" + CurrentBar, false, 0, High[0], Color.LightCoral);
                          }

              Comment


                #8
                You need to work through your logic. If your bool is false it will draw the dot. Likely your bool is never being set to true. Please see this tip on how to debug: http://www.ninjatrader-support2.com/...ead.php?t=3418
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you Josh. Very helpful like usually !

                  I'll debug after lunch

                  See you

                  Jed

                  Comment


                    #10
                    I did that :
                    Code:
                    if ((AO().AOValue[1] < AO().AOValue[2]))
                                        AOMinusOne = false;
                                    Print ("AOMinusOne rouge");
                    And it seems that on each bar, my bool is false....
                    What do you mean by :
                    Originally posted by NinjaTrader_Josh View Post
                    Likely your bool is never being set to true.
                    Thanks
                    Jed

                    Comment


                      #11
                      What I mean is that if on each bar you are setting it to false then of course you will get a draw object on every bar. Only when you set it to true will you not get the draw object. You need to print out your AO values and run calculations by hand to compare with. That way you can understand your code better.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        For me red is false, green is true.
                        if value of AO of the previous bar is < of the value of the bar before, AO is red, is it right ?

                        For me red is false, green is true.

                        So I want the AO value (AOMinusOne) to be false only if AO().AOValue[1] < AO().AOValue[2]
                        Then, I want to print the diamond.

                        What am I doing wrong ?

                        Jed

                        Comment


                          #13
                          Jed,

                          I do not recall the code in the AO. Your logic is only looking at the actual AO value, nothing to do with the color of the AO. When the AO's value of previous bar is less than the AO's value of the bar before that is when you will set to false.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Right, I understand.

                            Solved my problem, it was mainly a syntax problem....
                            Here's the right piece of code :
                            Code:
                            if (FirstTickOfBar) {
                                            
                                            if  (AO().AOValue[1] < AO().AOValue[2])
                                                {AOMinusOne = false;}
                                            
                                            else 
                                                {AOMinusOne = true;}
                            I'll continue on the rest of the code and will come back to you later.

                            Thank you very much, your help is very precious !
                            Jed

                            Comment


                              #15
                              Hi all.

                              Jed, are you coding to paint a buy/sell indicator for the AO on the price chart itself?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              9 responses
                              127 views
                              1 like
                              Last Post caryc123  
                              Working...
                              X