Registered User Joined: 10/29/2004 Posts: 2
|
Looking for Realcode for an ATR ratchet stop. Here it goes: the maximum (250 day) of (price - (10 * 14 day ATR). Similar to what Blackstar used in their November 2005 study Does Trend Following Work on Stocks?. Any ideas?
I hope that I've expressed this correctly. Many thanks.
|
Registered User Joined: 9/5/2009 Posts: 47
|
Not familiar with ATR ratchet stops, but here's My stab at it.
Add indicator - Average True Range Period 14 to chart.
Add realcode RULE with this code:
'# ATR = indicator.AverageTrueRange
Static RatchetStop As Single
If isfirstbar Then
RatchetStop = 0
End If
If CurrentIndex > 14 Then
If Price.Close - (10 * ATR.value) > RatchetStop Then
RatchetStop = Price.Close - (10 * ATR.value)
End If
If price.Close < RatchetStop Then
RatchetStop = 0
pass
End If
End If
To see where the stop is, Add INDICATOR with this code:
'# ATR = indicator.AverageTrueRange
Static RatchetStop As Single
If isfirstbar Then
RatchetStop = 0
End If
If CurrentIndex > 14 Then
If Price.Close - (10 * ATR.value) > RatchetStop Then
RatchetStop = Price.Close - (10 * ATR.value)
End If
If price.Close < RatchetStop Then
RatchetStop = 0
End If
plot = RatchetStop
End IF
Left click indicator and check "Show last indicator value"
|
Registered User Joined: 10/29/2004 Posts: 2
|
Thanks Nomad. I'll give it a try. In case you are interested I've attached the Blackstar study link below. They introduce the stop on page 4.
http://www.blackstarfunds.com/files/Does_trendfollowing_work_on_stocks.pdf
Best regards.
|
Registered User Joined: 9/5/2009 Posts: 47
|
After looking at the pdf I made a few changes to the code.
They use a 40 period ATR. Their stop NEVER gets reset.
They use more data than We can,and They adjust for dividends,etc.
You can increase your data to max in "Settings > Data Manager".
The original code would reset the stop after a stop was hit.
That may work if you trade shorter term.
Add indicator - Average True Range Period 40 to chart.
Add realcode RULE with this code:
'# ATR = indicator.AverageTrueRange
Static RatchetStop As Single
Static RatchetStop1 As Single
If isfirstbar Then
RatchetStop = 0
RatchetStop1 = 0
End If
RatchetStop1 = RatchetStop
If CurrentIndex > 40 Then
If Price.Close - (10 * ATR.value) > RatchetStop Then
RatchetStop = Price.Close - (10 * ATR.value)
End If
If price.Close < RatchetStop AndAlso price.Close(1) > RatchetStop1 Then
pass
End If
End If
Indicator
'# ATR = indicator.AverageTrueRange
Static RatchetStop As Single
If isfirstbar Then
RatchetStop = 0
End If
If CurrentIndex > 14 Then
If Price.Close - (10 * ATR.value) > RatchetStop Then
RatchetStop = Price.Close - (10 * ATR.value)
End If
plot = RatchetStop
End IF
|