Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lower High

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

    Lower High

    Hi

    One of the criteria of my strategy is that the High of a specific candle must be lower than the high of at least one of the highs of the 30 previous candles.

    I'm looking for something more efficient than this:

    High[0] < High [1] || High[0] < High [2] || etc

    Thanks

    #2
    laocoon, you could look into C#'s looping commands to optimize your code further -

    Comment


      #3
      Try the MAX indicator....

      see: http://www.ninjatrader.com/support/h...aximum_max.htm

      Comment


        #4
        Thanks for your help, Bertrand & KBJ.
        The looping commands look interesting but for some reason I didn't manage to make them work the way I wanted. As with the MAX command, I use it already in another context but in this particular case it's not ideal since I'm looking for the High of a specific candle that must be lower than the high of AT LEAST ONE of the highs of the 30 previous candles, but not lower than the High of the HIGHEST HIGH of the last 30 candles, which is how I understand the MAX command works.

        In the meantime I implemented the method I highlighted in my first post, not very elegant but it works.

        Comment


          #5
          Hi Laocoon,
          Originally posted by laocoon View Post
          Thanks for your help, Bertrand & KBJ.
          I'm looking for the High of a specific candle that must be lower than the high of AT LEAST ONE of the highs of the 30 previous candles, but not lower than the High of the HIGHEST HIGH of the last 30 candles, which is how I understand the MAX command works.
          If I understand you correctly, this should work? Though the lookback period could be a little different, now it loops starting at High[1] (i.e. one bar back) and ends at High[30] (31 bars back).

          PHP Code:
          private int specificCandle = 2;     // i.e. the specific candle is 2 bars back
          private int lookbackPeriod = 30;
          private double specificHigh, lowestHigh, highestHigh;
          
          protected override void OnBarUpdate()
          {
              if (CurrentBar < lookbackPeriod + 1)    // ensures that we have enough data for the lookback period
              {
                  return;
              }
          
              specificHigh = High[specificCandle];
              lowestHigh = specificHigh;  // initalize to a default value for comparison purposes
              highestHigh = specificHigh;
          
              for (int i = 1; i < (lookbackPeriod + 1); i++)    // loop through the latest 30 bars, starting at 1 stopping at 30
              {
                  if (High[i] > highestHigh)
                  {
                      highestHigh = High[i];
                  }
                  if (High[i] < lowestHigh)
                  {
                      lowestHigh = High[i];
                  }                
              }
              Print(Time[0].ToString() + " After looping: The highest high is: " + highestHigh + " and the lowest high is: " + lowestHigh);
          } 
          
          This gives the following output:
          Code:
          2-2-2009 22:23:00 After looping: The highest high is: 1,2879 and the lowest high is: 1,2863
          Also see the attached screenshot which corresponds to this output.

          Good luck!

          Regards,
          Attached Files

          Comment


            #6
            Thanks a lot for your contribution Jos, I'll look into it.

            Regards

            Comment


              #7
              Originally posted by laocoon View Post
              Hi

              One of the criteria of my strategy is that the High of a specific candle must be lower than the high of at least one of the highs of the 30 previous candles.

              I'm looking for something more efficient than this:

              High[0] < High [1] || High[0] < High [2] || etc

              Thanks
              Translate that statement to: "the target candle cannot be the highest candle in the set of 31 candles that includes it", and you can simply write:

              Code:
              bool ConditionMet = MAX(High, 30)[idxBarsAgoTargetCandle] > High[idxBarsAgoTargetCandle];
              In other words, the max high in the preceding 30 bars must be greater than the high of the target bar.

              So for example if the candle 2 bars ago is the one being evaluated, then that would be:

              Code:
              bool ConditionMet = MAX(High, 30)[2] > High[2];
              If being evaluated against today, it would be:

              Code:
              bool ConditionMet = MAX(High, 30)[0] > High[0];

              Comment


                #8
                Originally posted by laocoon View Post
                ... but not lower than the High of the HIGHEST HIGH of the last 30 candles....
                Sounds like an impossible condition. EVERY high is lower than the HIGHEST high: it is the definition of "highest".

                Comment


                  #9
                  Thanks a lot for your help Koganam, I'm currently looking at your code snippet.

                  My wording was indeed wrong, what I meant was: A Lower High than the High of at least one of the last 30 candles, but NOT NECESSARILY the Highest High. As you were saying, every candle's High will be lower than the High of the Highest High.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  668 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  377 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  110 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  580 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X