ATR Exit

This topic contains 5 replies, has 4 voices, and was last updated by Darren Darren 3 weeks, 2 days ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #47979

    Jane
    • Topics: 1
    • Replies: 2
    • Posts: 3

    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?

    #47983
    Mathew
    Mathew
    • Topics: 14
    • Replies: 781
    • Posts: 795

    Hi Jane,

    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()[1] – a1[1])

    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 “[1]” offset.

    Hope that helps

    Mathew

    #48003

    Jane
    • Topics: 1
    • Replies: 2
    • Posts: 3

    Thanks Mathew

    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 [1] 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?

    Cheers

    Jane

    #48007
    Matthew
    Matthew
    • Topics: 3
    • Replies: 69
    • Posts: 72

    Hi Jane,

    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.

    #48023

    Jane
    • Topics: 1
    • Replies: 2
    • Posts: 3

    Hi Matthew

    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…

    Attachments:
    #48047
    Darren
    Darren
    • Topics: 28
    • Replies: 131
    • Posts: 159

    Hi Jane,

    Use this as the exit, not the ATRTSCAN function, and see how you go:

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

Share This

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close