Dynamic Stop Loss – ATR Based

Forums ProRealTime English forum ProOrder support Dynamic Stop Loss – ATR Based

Viewing 8 posts - 1 through 8 (of 8 total)
  • #66027

    Can anybody see how to get this code to work for an ExistShort please? I’ve tried for an hour / several changes, but I can’t get it to work.

    I need the full code for an Exit Long and an ExitShort please.

    The original code came from a Nicolas post here

    https://www.prorealcode.com/blog/learning/moving-stoploss-dynamic-informations-proorder/

    Many Thanks
    GraHal

     

    #66035

    line 13 should read :

    because SL is a large number, in the vicinity of close.

     

    In total, for shorts, maybe like this ?

     

    #66047
    BC

    Hi Verdi

    I think line 13 should be

    #66059

    is ok as long as the instrument has a pointsize = 1 , because SL variable is calculated in price format, the best way would be to use ‘set stop loss’ to be completely compatible with any security.

     

    #66084

    is ok as long as the instrument has a pointsize = 1 , because SL variable is calculated in price format, the best way would be to use ‘set stop loss’ to be completely compatible with any security.

     

    Yes, that’s right. Maybe I shouldn’t code at 1:45 in the night in order to get sleepy…

    I did not realize that ATRsl is an absolute price quantity in the region of the current price. Not an ATR quantity (a small stop distance).

     

    Now, let’s recall what is intended with this code :

    The absolute stop price of a position shall be ATRsl, right from the beginning. When this moves closer to positionprice, it shall be adapted in the way of a trailing stop.

    So, why don’t we use ATRsl as an absolute stop (exit) price all of the time ? We then do not need the quantities dynamicSL and SL anymore (which have caused the whole confusion), we just look in every bar whether ATRsl has moved closer to positionprice or not.

    We have to add “and (not shortonmarket)” in line 9, because do not want these commands to be executed onve again when a position is already open, which could reset the current dynamic stop to a higher value (we only want lower values for shorts).

     

    Therefore, revised version for shorts :

     

    The long version then also needs a revision :

     

    Phew ! Quite a lot of hard thinking. Why complex, when it can be done easily ?

    Everybody agree ?

    #66090
    BC

    Hi Verdi

    U are right! 👍

    #66093

    The result is about the same as with Nicolas’ original code, although line 19 is not entirely correct there. In the first bar after a position has been opened,

    works nevertheless most of time, because the first dynamicSL (only in this bar being a small stop distance) is always very small compared to ATRsl (which is always a large absolute price).

     

    This is also the reason why the “GRAPH dynamicSL ” command in the last line of the original code gives a little strange looking results. There are spikes down to almost 0 each time when a new position is opened or when “condition” is true once again during the course of an open position, because then  “dynamicSL”  switches from an absolute price to a small stop distance and back. 

     

    DAX-1-Minute-1

    In the new code, there are only “sell at xx stop” and “exitshort at xx stop” commands, which may improve comprehensiblity a little. And the graph commands show nicely the development of the trailing stops. Maybe Nicolas can amend this in his code.

    1 user thanked author for this post.
    #66096

    Thank you @Verdi55, seems I wasn’t doing much wrong last night after all, it just wasn’t making  much difference to my results so I assumed my code for a Short wasn’t correct. 🙂

    Last night I was trying to fit the Dynamic SL into an RSI[2] Strat I am working on.

    Yes I was scratching my head also to understand how it worked, your code seems much simpler.

    This morning, using the complex version (before I saw the easier version) I got a Long and Short working using the simple MA condition. I may as well attach results and an .itf file in case anybody wants to take it further?

    For the hell of it, I will now fit Verdi55 simpler  version into the same simple condition Strat and see what the difference is if any! 🙂

    Cheers
    GraHal

    PS It’s only good over 10k bars, but I am starting to think the market changed so much from early Feb is there any point going back further and thus ending up with a strategy that is not reactive enough for today’s very short up & down zig & zags !? 🙂

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

Create your free account now and post your request to benefit from the help of the community
Register or Login