Registered User Joined: 1/2/2008 Posts: 41
|
Could you help me transforming the following code to real code for StockFinder?
‘LEN = 30
‘H = high
‘L = low
‘ StdDevX standard deviation
inputs:LEN(30), Smooth(3), Strength(1);
vars: RWH(0), RWL(0),PEAK(0), MEAN(0), STD(0);
RWH = (H[0] - L[LEN]) / (AvgTrueRange(LEN) * SquareRoot(LEN));
RWL = (H[LEN] - L[0]) / (AvgTrueRange(LEN) * SquareRoot(LEN));
PEAK = WAverage((RWH - RWL),3);
MEAN = average(PEAK,LEN);
STD = StdDevx(PEAK,LEN);
if (MEAN + (1.33 * STD)) > 2.08 then value1 = (MEAN + (1.33 * STD))
else value1 = 2.08;
if (MEAN - (1.33 * STD)) < -1.92 then value2 = (MEAN - (1.33 * STD))
else value2 = -1.92;
if PEAK[1] >= 0 and PEAK > 0 then plot2(value1,"+/-97.5%");
if PEAK[1] <= 0 and PEAK < 0 then plot2(value2,"+/-97.5%");
Plot is as a histogram
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I am not familiar with the language being used and am not a programmer in any case. My best guess at a RealCode Indicator based on the code provide would be:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Kase Peak Oscilator
'|******************************************************************
'# LEN = UserInput.Integer = 30
Static RWH As New List(Of Single)
Static RWL As New List(Of Single)
Static PEAK As New List(Of Single)
Static SUM As Single
Static SUMSQ As Single
Static ATR As Single
Static SQR As Single
If isFirstBar Then
RWH.Clear
RWL.Clear
PEAK.Clear
SUM = 0
ATR = 0
SQR = System.Math.Sqrt(LEN)
Else
ATR += System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
End If
If CurrentIndex > LEN Then
ATR -= System.Math.Max(Price.High(LEN), Price.Last(LEN + 1)) - _
System.Math.Min(Price.Low(LEN), Price.Last(LEN + 1))
End If
If CurrentIndex >= LEN Then
RWH.Insert(0, Price.High - Price.Low(LEN) / (SQR * ATR / LEN))
RWL.Insert(0, Price.High(LEN) - Price.Low / (SQR * ATR / LEN))
End If
If RWH.Count = 3 Then
PEAK.Insert(0, 3 * (RWH(0) - RWL(0)) + 2 * (RWH(1) - RWL(1)) + RWH(2) - RWL(2))
RWH.RemoveAt(2)
End If
If PEAK.Count > 0 Then
SUM += PEAK(0)
SUMSQ += PEAK(0) ^ 2
End If
If PEAK.Count = LEN Then
Dim MEAN As Single = SUM / LEN
Dim STD As Single = System.Math.Abs((SUMSQ + SUM ^ 2 / LEN) / LEN) ^ .5
If PEAK(1) >= 0 AndAlso PEAK(0) > 0 Then
Dim value1 As Single = MEAN + 1.33 * STD
value1 = System.Math.Max(value1, 2.08)
Plot = value1
Else If PEAK(1) <= 0 AndAlso PEAK(0) < 0 Then
Dim value2 As Single = MEAN - 1.33 * STD
value2 = System.Math.Min(value2, -1.92)
Plot = value2
Else
Plot = 0
End If
SUM -= PEAK(LEN - 1)
SUMSQ -= PEAK(LEN - 1) ^ 2
PEAK.RemoveAt(LEN - 1)
Else
Plot = Single.NaN
End If
If isLastBar Then
RWH.Clear
RWL.Clear
PEAK.Clear
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|