| Welcome Guest, please  sign in  to participate in a discussion. | Search | 	Active Topics | | 
	
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	Tweaking code Bruce wrote in a different thread request for labelling major/minor swing highs/lows, I have created an indicator that marks both multi-week and multi-month swing highs and lows.  While I can use  "# of bars since true"  (I think) to determine how many bars have passed since the last swing high/low, I am interested in determining the average number of bars between each of the last 5 occurences of a multi-week high (or low) and the same for a multi-month high (or low) in order to determine how many bars that cycle normally lasts.  Any ideas how I would go about doing this? 
	Thanks, and I hope what I'm asking for is clear (but understand if it isn't). 
	-Bruce V. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | 
	Can you post what you are using currently. I'm pretty sure I have created a few different Swing High/Low Indicators/Conditions. 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	Sure, would it be easier for me to email the template or share it? | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | 
	Sharing it would probably be both easier and quicker. Just let me know the share name once you've done so. 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	just shared it under name "cycle highs and lows". 
	-Bruce | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | 
	A RealCode Indicator for the Multi-Week High which displays the average number of bars between the five most recent swing highs could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Multi-Week High
'|******************************************************************
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.High >= Price.MaxHigh(6, 1) AndAlso _
	Price.High >= Price.MaxHigh(6, -6) Then
	recent.Insert(0, CurrentIndex)
	Label = "MW"
	If recent.Count >= 5 Then
		Label = "MW " & (recent(0) - recent(4)) / 4
		recent.RemoveAt(4)
	Else
		Label = "MW"
	End If
End If
Plot = Price.High
If isLastBar Then
	recent.Clear
End If 
	A RealCode Indicator for the Multi-Month High which displays the average number of bars between the five most recent swing highs could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Multi-Month High
'|******************************************************************
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.High >= Price.MaxHigh(16, 1) AndAlso _
	Price.High >= Price.MaxHigh(16, -16) Then
	recent.Insert(0, CurrentIndex)
	Label = "MW"
	If recent.Count >= 5 Then
		Label = "MW " & (recent(0) - recent(4)) / 4
		recent.RemoveAt(4)
	Else
		Label = "MW"
	End If
End If
Plot = Price.High
If isLastBar Then
	recent.Clear
End If 
	A RealCode Indicator for the Multi-Week Low which displays the average number of bars between the five most recent swing lows could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Multi-Week Low
'|******************************************************************
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.Low <= Price.MinLow(6, 1) AndAlso _
	Price.Low <= Price.MinLow(6, -6) Then
	recent.Insert(0, CurrentIndex)
	Label = "MW"
	If recent.Count >= 5 Then
		Label = "MW " & (recent(0) - recent(4)) / 4
		recent.RemoveAt(4)
	Else
		Label = "MW"
	End If
End If
Plot = Price.Low
If isLastBar Then
	recent.Clear
End If 
	A RealCode Indicator for the Multi-Month Low which displays the average number of bars between the five most recent swing lows could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Multi-Month Low
'|******************************************************************
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.Low <= Price.MinLow(16, 1) AndAlso _
	Price.Low <= Price.MinLow(16, -16) Then
	recent.Insert(0, CurrentIndex)
	Label = "MW"
	If recent.Count >= 5 Then
		Label = "MW " & (recent(0) - recent(4)) / 4
		recent.RemoveAt(4)
	Else
		Label = "MW"
	End If
End If
Plot = Price.Low
If isLastBar Then
	recent.Clear
End If 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	Works great, Bruce!   
	Thanks very much for your incredibly quick help, 
	Bruce V. | 
	|  | 
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	Bruce, 
	Sorry, I spoke a little too soon.  While the labels are accurate, they are using price as the value.  That is, if it has been an average of 25 bars between each of the last 5 swing highs and I want that to show that average in a data column, it is instead showing a value that appears to be the price.  Any way of capturing the average duration between swings as a value rather than a label? 
	-Bruce | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | 
	The RealCode was an alteration of your RealCode designed to provide the value in the Label 
	If you want an indicator which plots the average number of bars between Swing Highs/Lows, you should probably not plot it in the same Pane as Price History (it definitely won't be in the same Scale). 
	Set the SwingPeriod to 6 for the Weekly and to 16 for the Monthly. RealCode for the Highs could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Avg Bars Between Swing Highs
'|******************************************************************
'# SwingPeriod = UserInput.Integer = 6
'# SwingsUsed = UserInput.Integer = 5
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.High >= Price.MaxHigh(SwingPeriod, 1) AndAlso _
	Price.High >= Price.MaxHigh(SwingPeriod, -SwingPeriod) Then
	recent.Insert(0, CurrentIndex)
	If recent.Count >= SwingsUsed Then
		Dim Last As Integer = SwingsUsed - 1
		Plot = (recent(0) - recent(Last)) / Last
		recent.RemoveAt(Last)
	Else
		Plot = Single.NaN
	End If
Else
	Plot = Single.NaN
End If
If isLastBar Then
	recent.Clear
End If 
	RealCode for the Lows could be written as: 
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Avg Bars Between Swing Lows
'|******************************************************************
'# SwingPeriod = UserInput.Integer = 6
'# SwingsUsed = UserInput.Integer = 5
Static recent As New List (Of Single)
If isFirstBar Then
	recent.Clear
End If
If  Price.Low <= Price.MinLow(SwingPeriod, 1) AndAlso _
	Price.Low <= Price.MinLow(SwingPeriod, -SwingPeriod) Then
	recent.Insert(0, CurrentIndex)
	If recent.Count >= SwingsUsed Then
		Dim Last As Integer = SwingsUsed - 1
		Plot = (recent(0) - recent(Last)) / Last
		recent.RemoveAt(Last)
	Else
		Plot = Single.NaN
	End If
Else
	Plot = Single.NaN
End If
If isLastBar Then
	recent.Clear
End If 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 1/16/2005
 Posts: 72
 
 | 
	I'll give that a shot. 
	Thanks again Bruce. | 
	|  | 
	
	
	| Registered User Joined: 11/18/2010
 Posts: 2
 
 | 
	Bruce:  The Real code you posted below ..  on 8/6/12... how do u put that into a PCF indicator.  When I do new PCF indiactor I am getting an error.  THANKS! | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | 
	TC2000 uses the Personal Criteria Formula Language and does not have a way to use StockFinder's RealCode. There is no way to create an Indicator Formula replicating this RealCode which is short and fast enough to be practical or post in the forums. 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
| Guest-1 |