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

Comparing successive values of an indicator.

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

    Comparing successive values of an indicator.

    Hello,

    I am trying to compare 2 consecutive values of an indicator, to do different things if the value is constant than if the value is changing.

    Code:
    		if (AroonOscillator(period)[1] == AroonOscillator(period)[0])
    			Diff[0] = 100;
    		else
    			Diff[0] = 0;
    However, I am having the issue that I can only get a return value when several days are constant and not for every day that fulfills the condition.

    Is there anything wrong in the way I am comparing or is this a result of the indicator I am using?
    Attached Files

    #2
    Hello user1986,

    The code doesn't show when this is being called, however, it would appear that it should work fine.

    If you print the time with the values being checked in the condition (this is known as debugging), do you see a print at the time you are expecting it to be checked? Are the values the expected values?

    Print(string.Format("{0} | AroonOscillator(period)[1]: {1} == AroonOscillator(period)[0]: {2}", Time[0], AroonOscillator(period)[1], AroonOscillator(period)[0]));

    Please post the output from this print and also let us know on what bar you are expecting this to be checked and what you expect the indicator values to be.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It is being called OnBarUpdate.


      03/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: 92,8571428571429 == AroonOscillator(period)[0]: 78,5714285714286
      04/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: 78,5714285714286 == AroonOscillator(period)[0]: 78,5714285714286
      05/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: 78,5714285714286 == AroonOscillator(period)[0]: 64,2857142857143
      06/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: 64,2857142857143 == AroonOscillator(period)[0]: 64,2857142857143
      09/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: 64,2857142857143 == AroonOscillator(period)[0]: -42,8571428571429
      10/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      11/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      12/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      13/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      16/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      17/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429
      18/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -42,8571428571429

      19/05/16 11:30:00 p. m. | AroonOscillator(period)[1]: -42,8571428571429 == AroonOscillator(period)[0]: -100


      As you see there are many cases when the sentence is true (bold) for many consecutive days, but I only see the value of 100 every other day (underlined) (one day 100, then it goes to 0 on the next day, and goes back up on the third day).
      Attached Files

      Comment


        #4
        Hello user1986,

        Thank you for the output.

        It looks like this is a daily chart.

        The Diff value for the May 4th, should have a value of 100 and is not consecutive. Does this bar not have a value for 100?

        After the value is set, print the value along with the bar time so that we can see what that bars value for Diff is holding.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          04/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 100 == AroonOscillator(period)[0]: 92,8571428571429 | 0
          07/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 92,8571428571429 == AroonOscillator(period)[0]: 92,8571428571429 | 100
          08/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 92,8571428571429 == AroonOscillator(period)[0]: 100 | 0
          09/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 100 == AroonOscillator(period)[0]: 85,7142857142857 | 0
          10/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 85,7142857142857 == AroonOscillator(period)[0]: 85,7142857142857 | 0
          11/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 85,7142857142857 == AroonOscillator(period)[0]: 100 | 0
          14/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 100 == AroonOscillator(period)[0]: 85,7142857142857 | 0
          15/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 85,7142857142857 == AroonOscillator(period)[0]: 85,7142857142857 | 0
          16/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 85,7142857142857 == AroonOscillator(period)[0]: 78,5714285714286 | 0
          17/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 78,5714285714286 == AroonOscillator(period)[0]: 71,4285714285714 | 0
          18/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 71,4285714285714 == AroonOscillator(period)[0]: 64,2857142857143 | 0
          21/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 64,2857142857143 == AroonOscillator(period)[0]: 57,1428571428571 | 0
          22/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 57,1428571428571 == AroonOscillator(period)[0]: 50 | 0
          23/03/16 11:30:00 p. m. | AroonOscillator(period)[1]: 50 == AroonOscillator(period)[0]: 42,8571428571429 | 0


          Somehow, it seems it is only calculating every other day...
          Attached Files

          Comment


            #6
            Hi user1986,

            You may be running into an issue with a double epsilon.



            try:

            if (Math.Abs(AroonOscillator(period)[1] – AroonOscillator(period)[0]) < 0.0001)
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            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
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X