Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing Two Consecutive Daily Highs/Lows

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

    Comparing Two Consecutive Daily Highs/Lows

    Hello

    I'm using the standard Ninja CurrentDayOHL Indicator and have integrated two of its variables into my strategy, namely:

    Low[0] == CurrentDayOHL().CurrentLow[0]
    High[0] == CurrentDayOHL().CurrentHigh[0]

    This works great as long as I'm using defined candles, but I'm having trouble with one very simple thing: I'd like to compare the CURRENT daily high/low of a candle with the PREVIOUS daily high/low, no matter how many candles prior it occurred. I'm attaching a picture to illustrate the point. The difficulty comes from the fact that since I don't know how many candles I have to go back until the second most recent daily high/low, I can't use the command posted above.

    The two red arrows in the picture are highlighting the current daily high and the daily high prior to this one.
    What I'd like to do is to include a filter in my code that when the current daily high is higher than x ticks compared to the prior daily high, then my entry condition is invalid.

    Thanks for any pointers.

    PS: please ignore all candles to the right of the second red arrow. The candle with the second red arrow shall be the most recent one in this example, ie High[0] == CurrentDayOHL().CurrentHigh[0]
    Attached Files
    Last edited by laocoon; 06-27-2013, 06:36 AM.

    #2
    Hi Laocoon,

    Thank you for posting.

    There is a PriorDayOHLC indicator available with NinjaTrader.

    This will work very similar to the CurrentDay only that with the [0] index, will be one day ago or yesterday's values.

    Code:
    PriorDayOHLC().PriorOpen[0]
    Below is a link on the Prior Day OHLC from the online help guide.
    http://www.ninjatrader.com/support/h...r_day_ohlc.htm

    Please let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Cal. I'm not sure the indicator you mentioned will do the job though, because I'm looking for the current & prior daily high/low of the CURRENT session.
      Sorry if this wan't clear enough in my post.

      Thanks

      Comment


        #4
        Hi Laocoon,

        If you following you correctly, would want to check the Current High against the current high from one bar ago.

        i.e.
        Code:
        If(CurrentDayOHL().CurrentHigh[0] >= (CurrentDayOHL().CurrentHigh[1] + (2 * TickSize)))
        {trade}
        This would check when a new high were to take place and if it was greater than or equal to the prior high plus two ticks.

        Let me know if this is what you are looking for.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Cal,

          Thanks for your reply. What you're describing is exactly what I'm already able to do, ie comparing the current daily High/Low with the High/Low of x bars ago.

          What I'm not yet able to do is to compare the current daily High/Low with the prior daily High/Low (as illustrated in the attachement of the opening post), when I can't program on which candle it occurred, because this will obviously change every time.

          I'll give you another example: a fresh daily high is made at 10:00 AM. Another one is made at 10:20 AM.
          I now want to compare these two highs and if they're further away from each other than x Ticks, my entry condition is invalidated. The problem of course is that I cannot know in advance how many bars I have to look back to get the prior daily high. In this case it's 20 bars, but in the next example it may be 40, etc.

          That's why I'm looking for a generic way to compare the current and the prior daily high, irrespective of the number of bars that are in between.

          Thanks.

          Comment


            #6
            Laocoon,

            You write that when a fresh high is made at 10:00 AM and then 20 mintues later another new higher high is made and that you would have to check for 20 bars back.

            This is not the case. The 10:19 bar will still have the same CurrentHigh from the 10:00 bar. Therefore when using
            Code:
            If(CurrentDayOHL().CurrentHigh[0] >= (CurrentDayOHL().CurrentHigh[1] + (2 * TickSize)))
            {trade}
            When the 10:20 bar is closed it will compare that CurrentHigh from the Current of one bar ago which will have the CurrentHigh from the 10:00 bar.

            Hope this gives some clarity.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Cal,

              Thanks a lot for bearing with me. You're of course absolutely correct with your last post, but how do I deal with a special situation like in the posted chart where the three candles preceding the second red arrow all have the same high as the candle with the current daily high (the candle below the red arrow) ?

              What I'm asking is: does CurrentHigh[1] reference the prior CANDLE or the prior DAILY HIGH in a situation where a few candles have the same daily high in a row (like in the chart)?

              Thanks again for your help.

              Comment


                #8
                Laocoon,

                When you use CurrentHigh with CurrentDayOHL, CurrentDayOHL().CurrentHigh[0], it will grab the Current High for that indicator

                Back to the chart picture, when you come to the candle that you outlined with the second red arrow, the CurrentHigh[1] will reference one bar ago for the CurrentDayOHL indicator.

                Let me know if I can be of further assistance.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Cal, that's what I thought.
                  I've done some testing and the code works fine, except in the aforementioned situation where the current and the previous candle both have the same high (=the daily high). How can I modify the code to deal with this situation, ie when both the current and the previous candle have the same daily high?
                  I want this daily high to be compared to the previous DIFFERENT daily high.

                  Example:
                  High of Current Candle n: 10 (= Daily High)
                  High of Candle n-1: 10 (= Same Daily High)
                  High of Candle n-2: 9 (= Previous DIFFERENT Daily High)

                  I want the High of n to be compared to the High of n-2, ignoring n-1

                  Thanks again.

                  Comment


                    #10
                    Laocoon,

                    You can set the CurrentHigh[1] to a variable and be able to check that against the CurrentHigh[0].
                    Example:
                    Code:
                    	     if(CurrentBar < 1)
                                 return;
                    			
                    	     if(CurrentDayOHL().CurrentHigh[0] > CurrentDayOHL().CurrentHigh[1])
                                 {
                    				
                    			PrevHigh = CurrentDayOHL().CurrentHigh[1];
                    	     }
                    				
                    	     else if(CurrentDayOHL().CurrentHigh[0] == CurrentDayOHL().CurrentHigh[1])
                    	     {
                    					
                    	     }
                    Declare your variable in the top variables region as a double and this should give the ability to check the CurrentDay High against the previous High.

                    Let me know if this helps out
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks a lot for your example Cal. Is there a way though to compare the two last (different) daily highs without having to check whether ANY of the bars in between (not only the prior one) made a similar daily high?

                      Example: (see attachment)
                      Bar n makes a daily high (Current Daily High): DH1
                      Bar n-1 doesn't make a daily high
                      Bar n-2 doesn't make a daily high
                      Bar n-3 doesn't make a daily high
                      Bar n-4 makes a daily high (Same as Current Daily High): DH1
                      Bar n-5 makes a daily high (Different from Current Daily High): DH2

                      I now want to compare DH1 with DH2 and if DH1 is more than 7 Ticks higher than DH2, then my trading setup is invalid.

                      This can be accomplished with

                      if (CurrentDayOHL().CurrentHigh[0] > CurrentDayOHL().CurrentHigh[1]+7*TickSize) etc

                      The problem is that Bar n-4 makes the same Daily High as Bar n, and the code compares the high of Bar n with the high of Bar n-4 (which is 0 in this case as both make the same high). The trade would thus be triggered although it is invalid because the code mistakenly compares two Daily Highs that are identical. I want the code to compare two Daily Highs only if they're different from each other, as is the case with DH1 & DH2.

                      Thanks
                      Attached Files

                      Comment


                        #12
                        Laocoon,

                        That is exactly what the sample I gave you will allow you to do.

                        By placing the CurrentDayOHL().CurrentHigh[1] in a variable when the change in High occurs -
                        Code:
                        if(CurrentDayOHL().CurrentHigh[0] > CurrentDayOHL().CurrentHigh[1] + 7 * TickSize)
                                     {
                        				
                        			PrevHigh = CurrentDayOHL().CurrentHigh[1];
                        	     }
                        Will place the Previous High into a variable and will allow you to check the current High with the previous High in the if statement, regardless of how many bars there are in between and if any other bars meet the same current High, until a new high change occurs.
                        Cal H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        649 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        370 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        573 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X