| Welcome Guest, please  sign in  to participate in a discussion. | 	Search | 	Active Topics |  | 
	
	
	
	
		Registered User Joined: 3/4/2005 Posts: 94 
	 | 
	
		In stockfinder, I would like to be able to find the max high in the say last 100 bars.  I would then like to be able to subtract the min low from that high.  If i looked at the min low for the last 100 bars I could get a min low that was before the max high. 
 
Thanks for the help. 
 
	 | 
	 | 
	
	
	
		 
   Worden Trainer
  Joined: 10/7/2004 Posts: 65,138 
	 | 
	
		The following RealCode Indicator includes the Low of the Bar of the MaxHigh when calculating the range since there is no way of knowing if that Low happened before or after the High of the Bar: 
 
'|****************************************************************** 
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com  
'|*** Copy and paste this header and code into StockFinder ********* 
'|*** Indicator:Range Since High 
'|****************************************************************** 
'# Period = UserInput.Integer = 100 
Static Top As Single 
Static TopIndex As Integer 
Static Drop As Single 
If CurrentIndex > Period Then 
    If Price.High >= Top Then 
        Top = Price.High 
        TopIndex = CurrentIndex 
        Drop = Price.Low 
    Else If CurrentIndex - TopIndex = Period Then 
        Top = Price.MaxHigh(Period) 
        For i As Integer = 0 To Period - 1 
            Drop = System.Math.Min(Drop, Price.Low(i)) 
            If Price.High(i) = Top Then 
                TopIndex = CurrentIndex - i 
                Exit For 
            End If 
        Next 
    Else 
        Drop = System.Math.Min(Drop, Price.Low) 
    End If 
    Plot = Top - Drop 
Else If CurrentIndex = Period Then 
    Top = Price.MaxHigh(Period) 
    Drop = Price.Low 
    For i As Integer = 0 To Period - 1 
        Drop = System.Math.Min(Drop, Price.Low(i)) 
        If Price.High(i) = Top Then 
            TopIndex = CurrentIndex - i 
            Exit For 
        End If 
    Next 
    Plot = Top - Drop 
Else 
    Plot = Single.NaN 
End If
  -Bruce Personal Criteria Formulas TC2000 Support Articles
	 | 
	 | 
	
	
	
		Registered User Joined: 3/4/2005 Posts: 94 
	 | 
	
		Bruce: 
That works great.  Thanks for the solution. 
 
Va_Bear
	 | 
	 | 
	
	
	
		 
   Worden Trainer
  Joined: 10/7/2004 Posts: 65,138 
	 | 
	
		You're welcome.
  -Bruce Personal Criteria Formulas TC2000 Support Articles
	 | 
	 | 
| 
Guest-1 |