Three stoplosses, in one strategy

Forums ProRealTime English forum ProOrder support Three stoplosses, in one strategy

Viewing 11 posts - 1 through 11 (of 11 total)
  • #121320

    Hello,

    I am trying to build a long-only strategy that incorporates three stop-losses in one.

    • First of all, right when the trade is opened, the stop-loss should be 2% below the entry.

    Next, if the price moves > 1% from the entry, the stop needs to become the highest value of the following two:

    • The entry (moving the stop to breakeven)
    • The lowest low in the last 5 candles (a trailing stop)

    If the highest value of the two is hit, the strategy should immediately exit the long.

    I’ve read through all the available posts about stop-losses on the forum and tried several code snippets, but I couldn’t get it to work…

    I would appreciate your help a lot.

    Thank you,

    Pascal

     

    #121336

    Try this (not tested):

     

    1 user thanked author for this post.
    #121338

    Sorry, line 12 should be replaced by:

     

    1 user thanked author for this post.
    #121391

    That worked. Thank you, Roberto!

    #121401

    Hmm, I tried to replicate the same code snippet including shorting, and I can’t make it work…

    Here’s what I have:

    Do you have any ideas about what the issue could be?

    #121402

    1. line  18 must be moved just before line 16, otherwise it will ALWAYS be overridden by line 34

    2. line 34 must be moved just before line 32, otherwise il will ALWAYS override line 18

     

    1 user thanked author for this post.
    #121414

    Thank you, just made the above changes.

    However, unfortunately, the trailing stop for the short side is still not working.

    Here is the code with the changes you suggested:

    Is there anything else that I am missing?

    #121415

    Try replacing line 19 and 35 with:

    #121426

    Made the addition. Still not working, unfortunately.

    #121430

    The error concerns trailing SHORT stop loss is in line 8, which should be a high number when reset:

    if it’s zero, then there will never be a price less than that (line 36).

    You can add these lines (less, or more, according to your needs) to spot errors by monitoring values candle by candle (see pic):

     

    1 user thanked author for this post.
    #121437

    That worked! Thank you so much, Roberto!!!

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

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