Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

DD count Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
thnkbigr
Posted : Friday, July 20, 2018 5:22:59 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

I currently use this PCF to plot the DD in the last 63 days

-1 * (MAXH63 - C) / ATR63

I like to create an indicator that plot the total count of 

If the 63 day Draw down is more than 10 then +1

More than 15 +1

More than 20 +1

So if the is > 20 the new indicator will plot 3, if its only 13 it will only plot 1.

Can you show me how to do this pls 

thnkbigr
Posted : Monday, July 23, 2018 2:14:30 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Dw about this I figured it out 

Bruce_L
Posted : Monday, July 23, 2018 2:19:41 PM


Worden Trainer

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

I am happy to read you were able to figure it out on your own.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Monday, July 23, 2018 3:57:11 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Are these two plotting the same exact thing 

This in SF

'# Period = UserInput.Integer = 63
Static Value As Single
Static HC1 As Integer
If CurrentIndex = 0 Or Price.High > Value Then
Value = Price.High
HC1 = 1
Else If Value = Price.High
HC1 += 1
End If
If CurrentIndex >= Period Then
If Price.High(Period) = Value Then HC1 -= 1
If HC1 = 0 Then
Value = Price.High
HC1 = 1
For i As Integer = 1 To 499
If Price.High(i) > Value Then
Value = Price.High(i)
HC1 = 1
Else If Price.High(i) = Value Then
HC1 += 1
End If
Next
End If
End If
Plot = 100 * (Price.Last / Value - 1)
 
vs. this in TC
 
-1 * (MAXH63 - C) / ATR63
 
I understand the RC in SF is adjusted for IPO's. Is there any other diff?
thnkbigr
Posted : Monday, July 23, 2018 4:12:23 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

My bad one is calculating in % and the other in ATR

How do I change the SF RC to plot it in ATR 

 

thnkbigr
Posted : Monday, July 23, 2018 4:16:36 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
Did I do it right 
 
'# ATR = indicator.AverageTrueRange
'# Period = UserInput.Integer = 63
Static Value As Single
Static HC1 As Integer
If CurrentIndex = 0 Or Price.High > Value Then
Value = Price.High
HC1 = 1
Else If Value = Price.High
HC1 += 1
End If
If CurrentIndex >= Period Then
If Price.High(Period) = Value Then HC1 -= 1
If HC1 = 0 Then
Value = Price.High
HC1 = 1
For i As Integer = 1 To 499
If Price.High(i) > Value Then
Value = Price.High(i)
HC1 = 1
Else If Price.High(i) = Value Then
HC1 += 1
End If
Next
End If
End If
Plot = (Price.Last - Value - 1) / ATR.Value
Bruce_L
Posted : Tuesday, July 24, 2018 11:31:18 AM


Worden Trainer

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

No, I don't think it is right. Since I am assuming you want the indicator to start plotting immediately, please try the following RealCode Indicator instead.

'# Period = 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.High > Max Then
	Max = Price.High
	HC1 = 1
Else If Max = Price.High Then
	HC1 += 1
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 >= Period Then
	If Price.High(Period) = Max Then HC1 -= 1
	If HC1 = 0 Then
		Max = Price.High(Period - 1)
		HC1 = 1
		For i As Integer = Period - 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
	If CurrentIndex > Period Then
		Sum -= System.Math.Max(Price.High(Period), Price.Last(Period + 1)) - _
			System.Math.Min(Price.Low(Period), Price.Last(Period + 1))
	Else
		Sum -= Price.High(Period) - Price.Low(Period)
	End If
	ATR = SUM / Period
Else
	ATR = SUM / (CurrentIndex + 1)
End If
Plot = -1 * (Max - Price.Last) / ATR


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, July 27, 2018 12:36:46 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Bruce is the ATR setting in the RC above the same as the Max High

So If we are saying DD from Max 63 Day High it is using teh same 63 period to calculate ATR and onece I change the look back period to 252 it will change the ATR period to 252 as well? 

Am I correct 

Bruce_L
Posted : Friday, July 27, 2018 12:42:22 PM


Worden Trainer

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

Yes, the periods are the same.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, July 27, 2018 1:52:49 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Can I change this so that there are 2 period inputs one for ATR and one for the look back period

My look back period sometimes is set to 252 but my ATR is never set to highert than 63 usually 22

Bruce_L
Posted : Friday, July 27, 2018 2:07:33 PM


Worden Trainer

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

Breaking out the two periods doesn't complicate things too much.

'# 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.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
Plot = -1 * (Max - Price.Last) / ATR


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, July 27, 2018 5:43:32 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

The Value of the ATR that the RC above returns is different than the Average True Range indicator

I changed the final line in the RC above to Plot = ATR and teh value that it returns is not the same as the ATR indicator in the library. I have both set to 22 days   

thnkbigr
Posted : Sunday, July 29, 2018 10:51:42 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

When I change the finasl line to 

Plot = -1 * (Max - Price.Last)

to just plot the distance from last X high the value it plots is correct but the ATR value is not

Bruce_L
Posted : Monday, July 30, 2018 10:30:20 AM


Worden Trainer

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

The ATR indicator in StockFinder uses Wilder's smoothing while the ATR in TC2000 uses a simple moving average in its calculation. The RealCode is designed to replicate the TC2000 formula and uses a simple moving average instead of Wilder's smoothing.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Monday, July 30, 2018 6:45:39 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Oh I didn't know that. Thanks 

thnkbigr
Posted : Friday, October 12, 2018 11:55:03 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Bruce, How do I wirte a RC that continues to plot the 22 Day ATR value only 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 

Bruce_L
Posted : Friday, October 12, 2018 12:49:19 PM


Worden Trainer

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

Please try the following RealCode Indicator.

'# 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


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, October 12, 2018 1:16:43 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

The ATR here is being calculated in simple MA and not Wilders right?  

Bruce_L
Posted : Friday, October 12, 2018 1:22:09 PM


Worden Trainer

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

Yes.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, October 12, 2018 1:27:23 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Perfect. Thx

thnkbigr
Posted : Friday, October 12, 2018 2:25:12 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Bruce a while back you showed me a way to plot 4 values from the same RC so that I don't have to have the RC calculated 4 times to makes things less resouce intensive. 

How do I do that again?

For ex I want the RC above to plot 

Plot = 4 * ATRstored

Plot = 5 * ATRstored

Plot = 6 * ATRstored

Plot = 7 * ATRstored

The RC is already calculating ATRstored so at the end it just needs to multiply that with a value rather than plotting the same RC 4 times 

 

Bruce_L
Posted : Friday, October 12, 2018 2:55:40 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
OpenValue = 4 * ATRstored
HighValue = 5 * ATRstored
LowValue = 6 * ATRstored
Plot = 7 * ATRstored

You will need plot 1-period moving averages of the open, high and low to get the values plotted on the chart.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, October 12, 2018 3:07:14 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

I am not understaning you line. How do I plot a MA on the Open, High and Low of the RC

When I try to plot an MA on the indicator it doesn't give me an option

You will need plot 1-period moving averages of the open, high and low to get the values plotted on the chart.

Bruce_L
Posted : Friday, October 12, 2018 3:16:38 PM


Worden Trainer

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

There should be a Moving Average of OHLC indicator designed specifically for this.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, October 12, 2018 3:21:12 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Oh wow got it 

thx

thnkbigr
Posted : Friday, October 12, 2018 3:36:33 PM
Platinum Customer 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
thnkbigr
Posted : Friday, October 12, 2018 3:37:36 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

The RC I am referencing above is the one you wrote on  Friday, July 27, 2018 2:07:33 PM

Bruce_L
Posted : Friday, October 12, 2018 3:56:21 PM


Worden Trainer

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

It looks correct to me (but I have only done limited testing).

I don't see any instances of Price.High left (in the Max section of the code (but you left it in the ATR section). And since I used Price.Last instead of Price.Close, I can see which replacements are yours.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Monday, October 15, 2018 1:05:04 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Bruce 

Is this in SF 

'# 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.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
Plot = -1 * (Max - Price.Last) / ATR
 
the same as this in TC??
 
-1 * (MAXH63 - C) / ATR63
 
 
Bruce_L
Posted : Tuesday, October 16, 2018 8:49:04 AM


Worden Trainer

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

It looks like it should be the same.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Tuesday, October 16, 2018 10:25:15 AM
Platinum Customer 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
 
Bruce_L
Posted : Wednesday, October 17, 2018 8:19:34 AM


Worden Trainer

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

I am pretty sure based on what you are trying to do you want Price.Low in line 22 and Price.High in line 27.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Wednesday, October 17, 2018 10:06:19 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Thanks 

In the RC above ATR is being measured with Wilders smoothing can you pls show me how to adjust this so that it uses simple MA like TC   

Bruce_L
Posted : Wednesday, October 17, 2018 5:34:56 PM


Worden Trainer

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

I think I have replaced all of the ATR code from the indicator and the result does seem vaguely like a Volatility Stop:

'# period = UserInput.Single = 14
'# factor = UserInput.Single = 3
'# retreat = UserInput.Single = 1
'# highlow = UserInput.Single = 1
'#Cumulative
Static Sum As Single
Static ATR As Single
Static extreme(1) As Single
Static tstop As Single
Static state As Boolean
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 >= period Then
	If CurrentIndex > period Then
		Sum -= System.Math.Max(Price.High(period), Price.Last(period + 1)) - _
			System.Math.Min(Price.Low(period), Price.Last(period + 1))
	Else
		Sum -= Price.High(period) - Price.Low(period)
	End If
	ATR = SUM / period
Else
	ATR = SUM / (CurrentIndex + 1)
End If
If isFirstBar Then
	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 * ATR
		extreme(1) = tstop
		state = False
	Else
		extreme(0) = Price.Last
		tstop = extreme(0) - factor * ATR
		extreme(1) = tstop
		state = True
	End If
	Plot = tstop
Else
	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


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Thursday, October 18, 2018 12:53:57 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

I'll play with it but the only diff between the two is one is measuring ATR in Wilder smoothing while the other is using ATR in Simple MA

Since in TC ATR is measured in Simple MA I am trying to get what I use in SF to match TC 

Bruce_L
Posted : Thursday, October 18, 2018 7:42:26 AM


Worden Trainer

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

That is all I changed.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Thursday, October 18, 2018 3:04:38 PM
Platinum Customer 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
thnkbigr
Posted : Thursday, October 18, 2018 3:49:28 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

I feel like this is the concept that will do it. I just have to extended this to 50 days or 100 days back.

Am I correct or you have othe ways of doing it

IIF(H >= MAXH63, ATR22, IIF(H.1 >= MAXH63.1, ATR22.1, IIF(H.2 >= MAXH63.2, ATR22.2,  0)))

Bruce_L
Posted : Friday, October 19, 2018 7:58:36 AM


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
thnkbigr
Posted : Friday, October 19, 2018 9:15:05 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Thank you!

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.