Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Swing High and Swing Low Indicators Topic Rating:
Previous Topic · Next Topic Watch this topic · Print this topic ·
kenoracle
Posted : Friday, April 25, 2014 4:48:07 PM
Registered User
Joined: 1/13/2012
Posts: 72

If the 20-day moving average (simple) is going up, and the price dips and forms a Swing Low, how would this be found in Stockfinder?  There are PCFs in TC2000.

 

I have tried several methods to find Swing Low, such as ...

1) Look for 3 bars going down -> IF Price.Low  < Price.MaxLow(3,1) then pass,

 

then

2) 3 bars going up -> IF Price.High  > Price.MaxHigh(3,1) then pass

 

in a sequence. The results look like a 'hodge-podge'.

---------------------

There must be an easier, and clearer way.

(it would be nice to mark the entire Swing Low, if possible, OR at least mark the bottom bar)

 

Thanks.

 

Bruce_L
Posted : Monday, April 28, 2014 12:06:36 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

A Swing High RealCode Condition can be written as:

'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Swing High
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
If CurrentIndex >= Before AndAlso _
	CurrentIndex < Price.Count - After Then
	If Price.High > Price.MaxHigh(Before, 1) AndAlso _
		Price.High > Price.MaxHigh(After, -After) Then
		Pass
	End If
Else
	SetIndexInvalid
End If

While a Swing Low RealCode Condition can be written as:

'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Swing Low
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
If CurrentIndex >= Before AndAlso _
	CurrentIndex < Price.Count - After Then
	If Price.Low < Price.MinLow(Before, 1) AndAlso _
		Price.Low < Price.MinLow(After, -After) Then
		Pass
	End If
Else
	SetIndexInvalid
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
caution
Posted : Wednesday, December 9, 2015 3:00:00 PM
Registered User
Joined: 5/5/2010
Posts: 185

Bruce,

I know it's possible to construct an indicator from the swing high swing low conditions, but how can i write a code which checks for the last signal and keeps on until the next signal (watchlist).

Bruce_L
Posted : Thursday, December 10, 2015 10:43:14 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Maybe something like the following RealCode Indicator?

Note that it should not be used for backtesting as it starts plotting the new value at the Swing High or Swing Low instead of after the Swing High or Swing Low where it is actually detected. This should not affect its use a WatchList Column however.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Swing High/Low
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
	Status = Single.NaN
End If
If CurrentIndex >= Before AndAlso _
	CurrentIndex < Price.Count - After Then
	Dim BothTest As Boolean = False
	If Price.High > Price.MaxHigh(Before, 1) AndAlso _
		Price.High > Price.MaxHigh(After, -After) Then
		BothTest = True
		Status = 1
	End If
	If Price.Low < Price.MinLow(Before, 1) AndAlso _
		Price.Low < Price.MinLow(After, -After) Then
		If BothTest = True Then
			Status = 0
		Else
			Status = -1
		End If
	End If
End If
Plot = Status


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
caution
Posted : Thursday, December 10, 2015 1:51:43 PM
Registered User
Joined: 5/5/2010
Posts: 185

thx Bruce!

caution
Posted : Tuesday, December 15, 2015 2:00:27 PM
Registered User
Joined: 5/5/2010
Posts: 185

Bruce,

As with the code above, please do the same with a stochastic indicator crossing above and below.

thanks.

StockGuy
Posted : Tuesday, December 15, 2015 2:13:20 PM

Administration

Joined: 9/30/2004
Posts: 9,187

Crossing above and below what?

caution
Posted : Tuesday, December 15, 2015 2:47:17 PM
Registered User
Joined: 5/5/2010
Posts: 185

value = 50, my problem is with coding the output.

example, if stoch > 50 then plot = 1, signal until stoch < 50 then plot = -1 signal until.....

Bruce_L
Posted : Tuesday, December 15, 2015 3:06:24 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Maybe something like the following?

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross
'|******************************************************************
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
	Status = Single.NaN
End If
If Price.STOC(Period, SK) > 50 Then
	Status = 1
Else If Price.STOC(Period, SK) < 50 Then
	Status = -1
End If
Plot = Status


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Bruce_L
Posted : Tuesday, December 15, 2015 3:08:08 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Really the only time you can't just use the following is when the stochastic equals 50 exactly.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross Simple
'|******************************************************************
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
If Price.STOC(Period, SK) > 50 Then
	Plot = 1
Else
	Plot = -1
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
caution
Posted : Tuesday, December 15, 2015 5:33:31 PM
Registered User
Joined: 5/5/2010
Posts: 185

Thanks Bruce!

caution
Posted : Monday, August 29, 2016 2:39:55 PM
Registered User
Joined: 5/5/2010
Posts: 185

Bruce can we amend the code dated tuesday December 15, 3:06:24 pm?  I would like to add my own indicator ( indicator.value) thanks.

Bruce_L
Posted : Monday, August 29, 2016 2:45:28 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

In what way to you want to include indicator.value in the code? Do you want have the results based on indicator.value instead price?

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross
'|******************************************************************
'# indicator = chart.indicator
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
	Status = Single.NaN
End If
If indicator.STOC(Period, SK) > 50 Then
	Status = 1
Else If indicator.STOC(Period, SK) < 50 Then
	Status = -1
End If
Plot = Status


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
caution
Posted : Monday, August 29, 2016 3:13:36 PM
Registered User
Joined: 5/5/2010
Posts: 185

after adding my indicator , i get error msg... Name ('indicator') is not declared

Bruce_L
Posted : Monday, August 29, 2016 3:29:15 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

That just means your indicator isn't called "indicator" as would seem to have been suggested in your question..

See the line that says, "'# indicator = chart.indicator"?

That line would be correct if your indicator was actually called "indicator" and on the chart.

The line is normally created by dragging on dropping the the indicator into the RealCode.

You can do this by deleting the line from the RealCode, dragging and dropping your indicator into that place in the RealCode and then changing the variable name (the part between the '# and = in the line) to indicator.

RealCode for Real People: Indicators (6:05)
Writing Conditions in RealCode (10:11)



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.