Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
To change your RC in your so that it will measure from 63 day High to today's Low instead of Last I only need to adjust the last line to
Plot = -1 * (Max - Price.Low) / ATR
But to change it so that it will measure from Highest 63 day CLOSE (not high) to Last I made the following changes please make sure I am correct
'# HighPeriod = UserInput.Integer = 63
'# ATRperiod = UserInput.Integer = 63
'# Cumulative
Static Max As Single
Static HC1 As Integer
Static Sum As Single
Static ATR As Single
If CurrentIndex = 0 Or Price.Close > Max Then
Max = Price.Close
HC1 = 1
Else If Max = Price.Close Then
HC1 += 1
End If
If CurrentIndex >= HighPeriod Then
If Price.Close(HighPeriod) = Max Then HC1 -= 1
If HC1 = 0 Then
Max = Price.Close(HighPeriod - 1)
HC1 = 1
For i As Integer = HighPeriod - 2 To 0 Step -1
If Price.Close(i) > Max Then
Max = Price.Close(i)
HC1 = 1
Else If Price.Close(i) = Max Then
HC1 += 1
End If
Next
End If
End If
If CurrentIndex > 0 Then
Sum += System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
Else
Sum = Price.High - Price.Low
End If
If CurrentIndex >= ATRperiod Then
If CurrentIndex > ATRperiod Then
Sum -= System.Math.Max(Price.High(ATRperiod), Price.Last(ATRperiod + 1)) - _
System.Math.Min(Price.Low(ATRperiod), Price.Last(ATRperiod + 1))
Else
Sum -= Price.High(ATRperiod) - Price.Low(ATRperiod)
End If
ATR = SUM / ATRperiod
Else
ATR = SUM / (CurrentIndex + 1)
End If
Plot = -1 * (Max - Price.Last) / ATR
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Thank you! look the same as I tested both last night
Bruce I have my Volatity Stop RC below for your ref. What do I need to do to adj the RC so that it uses the High and Low as the Extreme points rather than Close
For Ex
Currently when Price is above it the indicator is plotted at 3 * ATR - the Highest Close since crossing above. Instead I want the indicator to use the Highest High and not Highest Close
Or when price crosses below it the indicator currently is using the Lowest Close since crossing below to plot 3 * ATR above that Lowest Close. I need to adj it so that it uses the Lowest Low and not Lowest Close
I think I have to change the Extreme(0) in the RC below and there are 4 of them (Line 22, 27, 43 and 50). I know I have to change Line 43 to Price.Low and line 50 to Price.High but I don't know what I need to change line 22 and 27 to
Can you help pls
'# period = UserInput.Single = 14
'# factor = UserInput.Single = 3
'# retreat = UserInput.Single = 1
'# highlow = UserInput.Single = 1
'# Cumulative
Static TR As Single
Static ATR As Single
Static termRatio As Single
static Weight As Single
Static sumWeight As Single
Static extreme(1) As Single
Static tstop As Single
Static state As Boolean
If isFirstBar Then
TR = Price.High - Price.Low
termRatio = (period - 1) / period
ATR = TR
sumweight = termratio + 1
weight = 1 / sumweight
If Price.Last(-1) - System.Math.Min(Price.Low, Price.Low(-1)) < _
System.Math.Max(Price.High, Price.High(-1)) - Price.Last(-1) Then
extreme(0) = Price.Last
tstop = extreme(0) + factor * TR
extreme(1) = tstop
state = False
Else
extreme(0) = Price.Last
tstop = extreme(0) - factor * TR
extreme(1) = tstop
state = True
End If
Plot = tstop
Else
TR = (Price.High - Price.Low + _
System.Math.Abs(Price.High - Price.Last(1)) + _
System.Math.Abs(Price.Last(1) - Price.Low)) / 2
ATR = ATR * (1 - weight) + weight * TR
sumweight = sumweight * termratio + 1
weight = 1 / sumweight
If state
If Price.Low < tstop
state = False
extreme(0) = Price.Low
tstop = extreme(0) + factor * ATR
extreme(1) = tstop
End If
Else
If Price.High > tstop
state = True
extreme(0) = Price.High
tstop = extreme(0) - factor * ATR
extreme(1) = tstop
End If
End If
Plot = tstop
If state Then
If Price.High > Price.MaxHigh(highlow, 1) Then
extreme(0) = System.Math.Max(extreme(0), Price.High)
tstop = extreme(0) - factor * ATR
extreme(1) = System.Math.Max(extreme(1), tstop)
tstop = System.Math.Max(tstop, extreme(1) - retreat * ATR)
End If
Else
If Price.Low < Price.MinLow(highlow, 1) Then
extreme(0) = System.Math.Min(extreme(0), Price.Low)
tstop = extreme(0) + factor * ATR
extreme(1) = System.Math.Min(extreme(1), tstop)
tstop = System.Math.Min(tstop, extreme(1) + retreat * ATR)
End If
End If
End If
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
I got the above to work thank you!
Bruce can this be written in PCF for TC?
This is plotting the 22 day ATR measured in Simple MA when price makes a 63 day high. So if today price makes a 63 day high the RC will plot ATR22 and continue to plot that same value until the next 63 day high
'# HighPeriod = UserInput.Integer = 63
'# ATRperiod = UserInput.Integer = 22
'# Cumulative
Static Max As Single
Static HC1 As Integer
Static Sum As Single
Static ATR As Single
Static ATRstored As Single
If CurrentIndex = 0 Then
ATRstored = Single.NaN
End If
If CurrentIndex = 0 Or Price.High > Max Then
Max = Price.High
HC1 = 1
Else If Max = Price.High Then
HC1 += 1
End If
If CurrentIndex >= HighPeriod Then
If Price.High(HighPeriod) = Max Then HC1 -= 1
If HC1 = 0 Then
Max = Price.High(HighPeriod - 1)
HC1 = 1
For i As Integer = HighPeriod - 2 To 0 Step -1
If Price.High(i) > Max Then
Max = Price.High(i)
HC1 = 1
Else If Price.High(i) = Max Then
HC1 += 1
End If
Next
End If
End If
If CurrentIndex > 0 Then
Sum += System.Math.Max(Price.High, Price.Last(1)) - _
System.Math.Min(Price.Low, Price.Last(1))
Else
Sum = Price.High - Price.Low
End If
If CurrentIndex >= ATRperiod Then
If CurrentIndex > ATRperiod Then
Sum -= System.Math.Max(Price.High(ATRperiod), Price.Last(ATRperiod + 1)) - _
System.Math.Min(Price.Low(ATRperiod), Price.Last(ATRperiod + 1))
Else
Sum -= Price.High(ATRperiod) - Price.Low(ATRperiod)
End If
ATR = SUM / ATRperiod
Else
ATR = SUM / (CurrentIndex + 1)
End If
If Price.High = Max Then
ATRstored = ATR
End If
Plot = ATRstored
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
That is exactly how I would do it. Since it is easier to shorten the formula then lengthen it, here it is out to 100 bars.
IIF(H = MAXH63, ATR22, IIF(H1 = MAXH63.1, ATR22.1, IIF(H2 = MAXH63.2, ATR22.2, IIF(H3 = MAXH63.3, ATR22.3, IIF(H4 = MAXH63.4, ATR22.4, IIF(H5 = MAXH63.5, ATR22.5, IIF(H6 = MAXH63.6, ATR22.6, IIF(H7 = MAXH63.7, ATR22.7, IIF(H8 = MAXH63.8, ATR22.8, IIF(H9 = MAXH63.9, ATR22.9, IIF(H10 = MAXH63.10, ATR22.10, IIF(H11 = MAXH63.11, ATR22.11, IIF(H12 = MAXH63.12, ATR22.12, IIF(H13 = MAXH63.13, ATR22.13, IIF(H14 = MAXH63.14, ATR22.14, IIF(H15 = MAXH63.15, ATR22.15, IIF(H16 = MAXH63.16, ATR22.16, IIF(H17 = MAXH63.17, ATR22.17, IIF(H18 = MAXH63.18, ATR22.18, IIF(H19 = MAXH63.19, ATR22.19, IIF(H20 = MAXH63.20, ATR22.20, IIF(H21 = MAXH63.21, ATR22.21, IIF(H22 = MAXH63.22, ATR22.22, IIF(H23 = MAXH63.23, ATR22.23, IIF(H24 = MAXH63.24, ATR22.24, IIF(H25 = MAXH63.25, ATR22.25, IIF(H26 = MAXH63.26, ATR22.26, IIF(H27 = MAXH63.27, ATR22.27, IIF(H28 = MAXH63.28, ATR22.28, IIF(H29 = MAXH63.29, ATR22.29, IIF(H30 = MAXH63.30, ATR22.30, IIF(H31 = MAXH63.31, ATR22.31, IIF(H32 = MAXH63.32, ATR22.32, IIF(H33 = MAXH63.33, ATR22.33, IIF(H34 = MAXH63.34, ATR22.34, IIF(H35 = MAXH63.35, ATR22.35, IIF(H36 = MAXH63.36, ATR22.36, IIF(H37 = MAXH63.37, ATR22.37, IIF(H38 = MAXH63.38, ATR22.38, IIF(H39 = MAXH63.39, ATR22.39, IIF(H40 = MAXH63.40, ATR22.40, IIF(H41 = MAXH63.41, ATR22.41, IIF(H42 = MAXH63.42, ATR22.42, IIF(H43 = MAXH63.43, ATR22.43, IIF(H44 = MAXH63.44, ATR22.44, IIF(H45 = MAXH63.45, ATR22.45, IIF(H46 = MAXH63.46, ATR22.46, IIF(H47 = MAXH63.47, ATR22.47, IIF(H48 = MAXH63.48, ATR22.48, IIF(H49 = MAXH63.49, ATR22.49, IIF(H50 = MAXH63.50, ATR22.50, IIF(H51 = MAXH63.51, ATR22.51, IIF(H52 = MAXH63.52, ATR22.52, IIF(H53 = MAXH63.53, ATR22.53, IIF(H54 = MAXH63.54, ATR22.54, IIF(H55 = MAXH63.55, ATR22.55, IIF(H56 = MAXH63.56, ATR22.56, IIF(H57 = MAXH63.57, ATR22.57, IIF(H58 = MAXH63.58, ATR22.58, IIF(H59 = MAXH63.59, ATR22.59, IIF(H60 = MAXH63.60, ATR22.60, IIF(H61 = MAXH63.61, ATR22.61, IIF(H62 = MAXH63.62, ATR22.62, IIF(H63 = MAXH63.63, ATR22.63, IIF(H64 = MAXH63.64, ATR22.64, IIF(H65 = MAXH63.65, ATR22.65, IIF(H66 = MAXH63.66, ATR22.66, IIF(H67 = MAXH63.67, ATR22.67, IIF(H68 = MAXH63.68, ATR22.68, IIF(H69 = MAXH63.69, ATR22.69, IIF(H70 = MAXH63.70, ATR22.70, IIF(H71 = MAXH63.71, ATR22.71, IIF(H72 = MAXH63.72, ATR22.72, IIF(H73 = MAXH63.73, ATR22.73, IIF(H74 = MAXH63.74, ATR22.74, IIF(H75 = MAXH63.75, ATR22.75, IIF(H76 = MAXH63.76, ATR22.76, IIF(H77 = MAXH63.77, ATR22.77, IIF(H78 = MAXH63.78, ATR22.78, IIF(H79 = MAXH63.79, ATR22.79, IIF(H80 = MAXH63.80, ATR22.80, IIF(H81 = MAXH63.81, ATR22.81, IIF(H82 = MAXH63.82, ATR22.82, IIF(H83 = MAXH63.83, ATR22.83, IIF(H84 = MAXH63.84, ATR22.84, IIF(H85 = MAXH63.85, ATR22.85, IIF(H86 = MAXH63.86, ATR22.86, IIF(H87 = MAXH63.87, ATR22.87, IIF(H88 = MAXH63.88, ATR22.88, IIF(H89 = MAXH63.89, ATR22.89, IIF(H90 = MAXH63.90, ATR22.90, IIF(H91 = MAXH63.91, ATR22.91, IIF(H92 = MAXH63.92, ATR22.92, IIF(H93 = MAXH63.93, ATR22.93, IIF(H94 = MAXH63.94, ATR22.94, IIF(H95 = MAXH63.95, ATR22.95, IIF(H96 = MAXH63.96, ATR22.96, IIF(H97 = MAXH63.97, ATR22.97, IIF(H98 = MAXH63.98, ATR22.98, IIF(H99 = MAXH63.99, ATR22.99, 1 / 0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
-Bruce Personal Criteria Formulas TC2000 Support Articles
|