Trailing stop loss advice

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #184925 quote
    SVK
    Participant
    Junior

    Hi all,

    I would really appreciate if any of you experienced people can point me in the right direction of Trailing stop loss.
    I’m aware of the Snippet Link Library and I have now tested several of them and it must be me but none of them are doing what I’m looking for.
    Maybe some of them do and I’m just far too stupid (spent 6 hours yesterday and 4 hours today and frustration is getting better of me).

    Can you please point me to Trailing stop loss which does following ?

    Example:
    1; Stop Loss = 20 points

    2; Trailing starts after price moves 5 points in my favor

    3; Trailing step is 5 points

     

    So every 5 points in my favor stop moves up by 5 points (simple mechanical thing).

    Stop Loss

    Trailing start

    Trailing step

    Vonas has done something close to that but there is not trailing step (if his startegy didn’t have minimum stop distance it would does what I’m after).

    sl = 144 //Stop loss distance
    slmove = 5 //Price move needed to move stop
    minstop = 10 //Minimum stop distance allowed

    Thank you very much

    #184927 quote
    robertogozzi
    Moderator
    Master

    Lines 17-56 of this snippet by Nicolas is doing exactly what you are looking for https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/.

    Just Copy & Paste those lines at the end of your code and replace 20 with 5 in trailingstart (trailingstep is already set as 5).

    SVK thanked this post
    #184937 quote
    SVK
    Participant
    Junior

    Hi Roberto,

    thank you very much for your response.
    I’m using Nicolas’s trailing stop with your modification.

    1; Nicolas’s trailing stop was stopping strategy 100% of the time as soon as profit reached Trailingstart

    2; I have searched for hours and found your post I think in German language where you have Distance = 4 * pipsize. This has helped massively as the strategy stopped quitting after each succesfull trade.

    3; Trailing stop never trails. 100% of profitable trades exit at the point of reaching trailingstart.
    DAX settings

    Trailing start = 30 points

    Trailing step = 6 points (tested with, 7, 8, 9, 10, 11 makes zero difference)

     

    I have observed behavior of this trailing stop:

    1; Trailing start reached (30 points)

    2; it correctly moves stop loss to break even point

    3; immediatelly it moves stop to the next step 6 points

    4; another 6 points and another until it reaches 30 points and then it sells at that point (100% trades exited at 30 point)

     

    What I’m after:

    Stop loss = -20 points

    Step size = 5 points

    Trailing start = 30

    30 points move up = New stop loss -15

    Another 30 points up = New stop loss -10

     

    Thank you very much for your help

    #184952 quote
    robertogozzi
    Moderator
    Master

    I’ll code it asap.

    SVK thanked this post
    #184953 quote
    SVK
    Participant
    Junior

    Roberto,

    you are a gentleman.

    Thank you very much for your help

    #185053 quote
    robertogozzi
    Moderator
    Master

    Try this one:

    //----------------------------------------------------------------------------------------------------
    // Trailing Stop (classic, no breakeven)
    //
    NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket)
    //
    IF Not OnMarket OR NewTrade THEN
       MainSL        = 400 * PipSize
       TrailingStart = 100 * PipSize
       TrailingStep  = 30  * PipSize
       Distance      = 10  * PipSize
    ENDIF
    //
    // LONG  side
    //
    MyProfit = positionperf * positionprice
    IF LongOnMarket  THEN
       IF (Not OnMarket[1]) OR ShortOnMarket[1] THEN
          TrailingSL    = TradePrice - MainSL
       ENDIF
       IF ((close - TradePrice) >= TrailingStart) AND (TrailingStart > 0) THEN
          TrailingSL    = TrailingSL + TrailingStart
          SavedPips     = TrailingStart
          TrailingStart = 0
       ENDIF
       WHILE ((MyProfit - SavedPips) >= TrailingStep)
          TrailingSL    = TrailingSL + TrailingStep
          SavedPips     = SavedPips  + TrailingStep
       WEND
    ENDIF
    //
    // SHORT side
    //
    IF ShortOnMarket THEN
       IF (Not OnMarket[1]) OR LongOnMarket[1]  THEN
          TrailingSL    = TradePrice + MainSL
       ENDIF
       IF ((TradePrice - close) >= TrailingStart) AND (TrailingStart > 0) THEN
          TrailingSL    = TrailingSL - TrailingStart
          SavedPips     = TrailingStart
          TrailingStart = 0
       ENDIF
       WHILE ((MyProfit - SavedPips) >= TrailingStep)
          TrailingSL    = TrailingSL - TrailingStep
          SavedPips     = SavedPips  + TrailingStep
       WEND
    ENDIF
    //
    // LONG  Exit
    IF LongOnMarket  THEN
       IF close > (TrailingSL + Distance) THEN
          SELL      AT TrailingSL STOP
       ELSIF close < (TrailingSL - Distance) THEN
          SELL      AT TrailingSL LIMIT
       ELSE
          SELL      AT Market
       ENDIF
    ENDIF
    // SHORT Exit
    IF ShortOnMarket THEN
       IF (close - Distance) > TrailingSL THEN
          EXITSHORT AT TrailingSL LIMIT
       ELSIF (close + Distance) < TrailingSL THEN
          EXITSHORT AT TrailingSL STOP
       ELSE
          EXITSHORT AT Market
       ENDIF
    ENDIF
    SVK thanked this post
    #185221 quote
    SVK
    Participant
    Junior

    Roberto,

    thank you very much for your help.
    I will try it tomorrow and will report back.

     

    Would have never manage to code something like this.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Trailing stop loss advice


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
SVK @svk Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by SVK
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/09/2022
Status: Active
Attachments: No files
Logo Logo
Loading...