August 28, 2018 at 12:14 pm #47979
I want to play around with some trend following in the backtester with using an ATR for the stop loss: exit on open the following bar when the previous bar closes below xATR(y).
When I did a show bar with the following script I got 1 arrow at the start of the chart and then never again. Its not showing me every time the close crosses below.
CLOSE() CrossesBelow ATRTSCAN(ATRTRAIL=2.00, ATRBARS=15, CALCOFF=High)
Similarly in the backtester, you can choose an ATR Long Trailing Stop but I don’t think its working correctly because I only get a few trades (ie with an entry of a close above a moving average over 10 years of daily data I get 43 trades….).
I have watched the 3 scripting courses and searched the knowledge base but can’t find anything that explains how to set up these functions? Do I somehow have to link the stop loss with each entry trigger?August 29, 2018 at 12:29 am #47983
- Topics: 15
- Replies: 823
- Posts: 838
The ATRTSCAN is a special function that is used in the stop section of the back tester. I’m not 100% sure why, but it does not work in a script (something we’ll check out).
In the mean time, this is a script that will work for you.
a1 = ATR(BARS=15, MULT=2.00);
CLOSE() CrossesBelow (HIGH() – a1)
we calculate the ATR and store it in “a1”. Then we see if today’s close crosses below yesterday’s value of high minus the atr by using the “” offset.
Hope that helps
MathewAugust 29, 2018 at 9:25 am #48003
Its not working in the backtester either -the built-in ATR Long Trailing Stop was what I tried first but it is not working correctly?
Is the  the same as using the offset function? I did wonder if that was why the ATR Long Trailing Stop was not functioning correctly but I didn’t know if the offset was perhaps ‘baked-in’ to the ATRSCAN function already?
JaneAugust 29, 2018 at 3:38 pm #48007
- Topics: 3
- Replies: 80
- Posts: 83
I’ve tested the script and it appears to be working ok here.
Where have you added the criteria, to the Stops section or to the Exit? As it’s a custom criteria it should be under the Exit section (with an OR separating it from other exit criteria), the Stops section works with preset options only.August 31, 2018 at 11:25 am #48023
I have it added as the exit criteria and I have no other exit criteria (so no OR required?).
Can I just check that the script is correct? I have CLOSE() <= ATRTSCAN(CALCOFF=HIGH) but I think I may have changed it from the low which was the default?
Either way, I just ran the back on a single code (BXB) and I only get 1 trade in 10 years. It seems to be taking the first entry in the test period of the last 10 years on 2/9/08 and then the exit is on the last bar of the chart (30/8/18). In fact I suspect this is only because I have ‘close all positions’ ticked in the backtester.
In the attached chart of BXB, there are 3 show bars overlaid on the chart as well as the strategy trades arrows. Green arrows are possible entries (criteria is just a close above 18 period WMA), red arrow is the ATR Long Trailing Stop script above – you get 3 red arrows at the beginning of the chart in 1985 and then nothing and then the pink arrows are Mathew’s ATR exit script from this thread.
I have NO idea what I’m doing wrong?!! I’ve uploaded screenshots of the backtest as well as the workbook with the BXB chart…
You must be logged in to access attached files.September 2, 2018 at 1:38 am #48047
- Topics: 29
- Replies: 152
- Posts: 181
Use this as the exit, not the ATRTSCAN function, and see how you go:12345a1 = ATR(BARS=15, MULT=2.00);CLOSE() CrossesBelow (HIGH() – a1)
You must be logged in to reply to this topic.