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

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	
    				}	
    			}
    Paul H.NinjaTrader Customer Service

    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 LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X