Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

ATR Ratchet Stop Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
forest_king
Posted : Saturday, January 9, 2010 6:17:36 PM
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.
nomad_tx
Posted : Sunday, January 10, 2010 11:19:58 PM
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"

forest_king
Posted : Monday, January 11, 2010 7:41:09 PM
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.

nomad_tx
Posted : Tuesday, January 12, 2010 3:10:04 AM
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

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.