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 wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      192 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,234 views
      0 likes
      Last Post xiinteractive  
      Working...
      X