Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max/Min Values Between two Bars

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

    Max/Min Values Between two Bars

    Dear Support,

    What is the NT7 Syntax (or a code script) for finding the lowest low or highest high of any bar between two historical bars.

    For example: MIN(Low[15], Low[30]) gives the lowest of these two bar. I want the lowest low of any bar between and including bars 15 to bar 30.

    Thanks.

    #2
    Hello aligator,

    Thanks for your post.

    Correct, as you have observed the MIN/MAX will only return the values at the bars ago specified.

    To accomplish your goal of finding the MIN/MAX from a range of sequential bars is to use a for loop and compare the high and low of each bar to an initial value.

    I've created some example code that will do this and includes orange dots to show what bars are being processed and then a red dot to show which is the (newest) low and blue for high. (The dots are offset just so you can observe them from the bars, the location of the dots are not the values used but to indicate the bar location)

    Code:
    			double testLow = MIN(Low,0 )[30];  //seed value
    			double testHi = MAX(High, 0)[30];  // seed value		
    			
    			for (int i= 0; i <= 14; i++)
    			{
    				DrawDot ("Test3" + i, true, 30 + i, testLow - 8 *TickSize, Color.Orange); // shows bars being processed	
    				
    				if (Low[30 + i] <= testLow)
    				{
    					testLow = Low[30 + i];
    					DrawDot ("test1", true, 30 + i, Low[30 + i] - 5 * TickSize, Color.Red); // shows the newest Low in the range
    				}
    				if (High[30 + i] >= testHi)
    				{
    					testHi = High[30 + i];
    					DrawDot ("test2", true, 30 + i, High[30 + i] + 5 * TickSize, Color.Blue); // shows the newest high in the range	
    				}	
    			}

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello aligator,

      Thanks for your post.

      Correct, as you have observed the MIN/MAX will only return the values at the bars ago specified.

      To accomplish your goal of finding the MIN/MAX from a range of sequential bars is to use a for loop and compare the high and low of each bar to an initial value.

      I've created some example code that will do this and includes orange dots to show what bars are being processed and then a red dot to show which is the (newest) low and blue for high. (The dots are offset just so you can observe them from the bars, the location of the dots are not the values used but to indicate the bar location)

      Code:
      			double testLow = MIN(Low,0 )[30];  //seed value
      			double testHi = MAX(High, 0)[30];  // seed value		
      			
      			for (int i= 0; i <= 14; i++)
      			{
      				DrawDot ("Test3" + i, true, 30 + i, testLow - 8 *TickSize, Color.Orange); // shows bars being processed	
      				
      				if (Low[30 + i] <= testLow)
      				{
      					testLow = Low[30 + i];
      					DrawDot ("test1", true, 30 + i, Low[30 + i] - 5 * TickSize, Color.Red); // shows the newest Low in the range
      				}
      				if (High[30 + i] >= testHi)
      				{
      					testHi = High[30 + i];
      					DrawDot ("test2", true, 30 + i, High[30 + i] + 5 * TickSize, Color.Blue); // shows the newest high in the range	
      				}	
      			}
      Fantastic! Thank you Paul. Excellent script. This is really handy for many other codes needing a loop.

      Cheers!
      Last edited by aligator; 07-18-2016, 10:36 AM.

      Comment

      Latest Posts

      Collapse

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