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

Help Coding Combined Indicator Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
danielbender
Posted : Friday, April 6, 2018 1:14:32 PM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

I would like real code to generate the following counts for daily and 5-minute timeframes

 

1. Postive count indicating number of bars since:

a) RSI reversed from negative to positive slope AND

b) StochasticMomentumIndex crossed UP through trigger

Please make this count number positive.  ie, 1 = 1 bar since last occurrence, 2 = 2 bars since, etc.,

 

2. Negative count indicating number of bars since (mirror image of above):

a) RSI reversed from positive to negative slope AND

b) StochasticMomentumIndex crossed DOWN through trigger

Please make this count number negative.  ie, -1 = 1 bar since last occurrence, -2 = 2 bars since, etc.,

 

If possible, I would like the ability to adjust the parameters of the indicators and the timeframes.

Thank you.... Dan Bender

Bruce_L
Posted : Monday, April 9, 2018 2:52:11 PM


Worden Trainer

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

Do a and b have to happen on the same bar?



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Monday, April 9, 2018 7:02:05 PM
Registered User
Joined: 1/14/2006
Posts: 436

yes, both a and b should occur on the same bar.  Thanks.

Bruce_L
Posted : Tuesday, April 10, 2018 10:44:59 AM


Worden Trainer

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

You will need to create the '# WR and '# SMI lines yourself by dragging and dropping the indicators from the chart into the RealCode Editor. Initially this will mean changing the indicators on the chart will change the settings. If you save the indicator, you should be able to adjust the settings by just editing the indicator.

RealCode for Real People: Indicators (6:05)

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Since Reversal
'|******************************************************************
'# WR = chart.WildersRSI
'# SMI = chart.StochasticMomentumIndex
'# Trigger = UserInput.Integer = 10
Static Count As Single
Static Sign As Single
If isFirstBar Then
	Count = Single.NaN
	Sign = 0
Else If WR.Value > WR.Value(1) AndAlso _
	WR.Value(1) <= WR.Value(2) AndAlso _ 
	SMI.Value > SMI.XAVG(Trigger) AndAlso _
	SMI.Value(1) <= SMI.XAVG(Trigger, 1) Then
	Count = 0
	Sign = 1
Else If WR.Value < WR.Value(1) AndAlso _
	WR.Value(1) >= WR.Value(2) AndAlso _ 
	SMI.Value < SMI.XAVG(Trigger) AndAlso _
	SMI.Value(1) >= SMI.XAVG(Trigger, 1) Then
	Count = 0
	Sign = -1
Else
	Count += Sign
End If
Plot = Count


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Tuesday, April 10, 2018 2:31:19 PM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce - Thank you - An additional request

Could you modify the code to so that a and b occur within one bar of each other, but not necessarily on the same bar?  I am getting too few simultaneous triggers when both occur on the same bar. Too restrictive.  Thank you.

Bruce_L
Posted : Tuesday, April 10, 2018 3:11:07 PM


Worden Trainer

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

Maybe the following?

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Since Reversal
'|******************************************************************
'# WR = chart.WildersRSI
'# SMI = chart.StochasticMomentumIndex
'# Trigger = UserInput.Integer = 10
Static Count As Single
Static Sign As Single
If isFirstBar Then
	Count = Single.NaN
	Sign = 0
Else If WR.Value > WR.Value(1) AndAlso _
	SMI.Value > SMI.XAVG(Trigger) AndAlso _
	((WR.Value(1) <= WR.Value(2) AndAlso _ 
	SMI.Value(1) <= SMI.XAVG(Trigger, 1)) OrElse _
	(WR.Value(1) <= WR.Value(2) AndAlso _
	SMI.Value(2) < SMI.XAVG(Trigger, 2)) OrElse _
	(WR.Value(2) < WR.Value(3) AndAlso _
	SMI.Value(1) <= SMI.XAVG(Trigger, 1))) Then
	Count = 0
	Sign = 1
Else If WR.Value < WR.Value(1) AndAlso _
	SMI.Value < SMI.XAVG(Trigger) AndAlso _
	((WR.Value(1) >= WR.Value(2) AndAlso _ 
	SMI.Value(1) >= SMI.XAVG(Trigger, 1)) OrElse _
	(WR.Value(1) >= WR.Value(2) AndAlso _
	SMI.Value(2) > SMI.XAVG(Trigger, 2)) OrElse _
	(WR.Value(2) > WR.Value(3) AndAlso _
	SMI.Value(1) >= SMI.XAVG(Trigger, 1))) Then
	Count = 0
	Sign = -1
Else
	Count += Sign
End If
Plot = Count


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Wednesday, April 11, 2018 2:20:37 AM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce - thank you

Bruce_L
Posted : Wednesday, April 11, 2018 9:37:57 AM


Worden Trainer

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

You're welcome.



-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.