Registered User Joined: 11/4/2009 Posts: 81
|
Hi Bruce,
I would like to ask for your help to write a realcode indicator.
actually, 2 realcodes (both about the same);
indicator 1: plot the highest point of the price above the 50 moving average and remain the same after current close across below the 50moving average until the current close above the moving average;
indicator 2: plot the lowest point of the price below the 50 moving average and remain the same after current close across above the 50 moving average until the current close below the moving average.
can you also show me how to put both indicators in one realcode?
thank you
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You can only output either a single value at each bar or the open, high, low and close at each bar using a RealCode Indicator. It is not possible to plot two values using a single RealCode Indicator.
A RealCode Indicator for the Highest High with the Close above the 50-Period Simple Moving Average of price could be written as:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Highest High with Close above Moving Average
'|******************************************************************
'# Period = UserInput.Integer = 50
Static Highest As Single
If isFirstBar Then
Highest = Single.NaN
Else If Price.Last > Price.AVGC(Period) Then
If Price.Last(1) <= Price.AVGC(Period, 1) Then
Highest = Price.High
Else
Highest = System.Math.Max(Highest, Price.High)
End If
End If
Plot = Highest
A RealCode Indicator for the Highest High with the Close above the 50-Period Simple Moving Average of price could be written as:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Lowest Low with Close below Moving Average
'|******************************************************************
'# Period = UserInput.Integer = 50
Static Lowest As Single
If isFirstBar Then
Lowest = Single.NaN
Else If Price.Last < Price.AVGC(Period) Then
If Price.Last(1) >= Price.AVGC(Period, 1) Then
Lowest = Price.Low
Else
Lowest = System.Math.Min(Lowest, Price.Low)
End If
End If
Plot = Lowest
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Registered User Joined: 11/4/2009 Posts: 81
|
Hi Bruce,
thank you for the real code, it works great.
I like to ask if I like to plot the lowest point of last 10 period when the crossing occur.
do i change lowest=minlow(10) only or change both lowest=minlow(10) and lowest=system.math.min(lowest,minlow(10))
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If I'm understanding your request correctly, you should only need to change Lowest = Price.Low to Lowest = Price.MinLow(10). The Lowest = System.Math.Min(Lowest, Price.Low) section is just there to lower the low after the cross, not at the point of the cross.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Registered User Joined: 11/4/2009 Posts: 81
|
okay, thank you
that works for me.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|