Backtesting ATR

If I wanted to backtest the ATR trailing stop…

 

How would I achieve this…

 

Let’s say, Enter ATR trailing (falling) stop (in a down market) with ATR 2.5 & Exit ATR trailing (rising) stop (is a upmarket) ATR 2.5.

 

How would this be achieved? I tried to play around, but couldn’t find ATR in the list to backtest with.

Hi Jonathan,

This is a little tricky to do with the ATR function because to be a real stop it should not move higher/lower against the trend. A better tool to use is the Chandelier Stop. It is based on ATRs but it has a “ratchet” feature so it will never move away from price. The script of this tool also has a “State” feature which makes it easy to script.

To write an entry script you can use this

CHST(FACTOR=2.50, LENGTH=14).State ChangeTo 0

To exit

CHST(FACTOR=2.50, LENGTH=14).State ChangeTo 1

I always suggest testing scripts on a chart with a Show Bar tool so you can be sure it is capturing what you need.

Hope that helps

Mathew

 

Thanks Matt,

 

Not quite what I had in mind. But good starting spot. You did pick up a flaw in my request. One that I didn’t consider before.

 

cheers1