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
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 #48007Matthew
- Topics: 5
- Replies: 602
- Posts: 607
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…September 2, 2018 at 1:38 am #48047Darren
- Topics: 70
- Replies: 787
- Posts: 857
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)December 20, 2018 at 10:56 am #50419
I have copied and pasted this exit criteria and it states (please enter a valid script to add to this criteria). I would like to add as exit criteria + ATR14 multi 3.
I have tried CLOSE + ATR14 MULTI3, it comes up as a valid script but does not work as required. I have tried many variables but as soon as I add the + ATR it
still states that it is a valid script but does not work, any help would be appreciated.December 20, 2018 at 11:02 am #50423
Can you please put in a screen shot of exactly what you have in the script editor. I think some characters did not come across in your post and it is a little hard to see what is going on.
MathewDecember 20, 2018 at 5:56 pm #50427
Hi Mathew, all I would like to do is add an exit strategy on a back test ,
entry criteria + (when close, closes above ATR14*3).
Also on a chart with show bar with the entry one colour and the exit another colour.
entry could be (RSI14 crosses above 50) and (close > ma50)
Thank you.December 20, 2018 at 11:54 pm #50435
The script is fine – I just typed it in and it works. I suspect that there is a hidden character in there somewhere. Usually this can happen if a part of the script has been pasted in. I know it is annoying, but can you please try creating a new script and typing that out again?
Another solution is to use Notepad as a go-between. Paste the script into Notepad, then copy it again. The reason for this is that Notepad strips out all hidden characters.
All the best
MathewDecember 21, 2018 at 2:20 pm #50439
I retyped the criteria and it was valid but it is not giving me what I am after.
I thought that it would be a simple code for (entry criteria + (when close, closes above ATR14*3).
CLOSE Crossabove ATR? I have attached the 2 out comes.
The ATR price on the first buy is .32. ([email protected] 8.75 +.96=9.71) exit 9.71 about 8 bars after buy.
- You must be logged in to reply to this topic.