Trigger Trailing SL if target is met

Viewing 15 posts - 31 through 45 (of 69 total)
  • Author
    Posts
  • #198472 quote
    phoentzs
    Participant
    Master

    1-30 is nonsense too. 30-1 maybe. 😉

    #198478 quote
    Mr.Mjau
    Participant
    New
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[20](close)
    indicator2 = Average[100](close)
    c1 = (indicator1 CROSSES UNDER indicator2)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = Average[20](close)
    indicator4 = Average[100](close)
    c2 = (indicator3 CROSSES OVER indicator4)
    
    IF c1 THEN
    BUY 5 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit long positions
    indicator3 = Average[20](close)
    indicator4 = Average[100](close)
    c2 = (indicator3 CROSSES OVER indicator4)
     
    If c2 Then
    // Stops and targets
    trailingstart = 10   //trailing will start @trailinstart points profit
    trailingstep  = 30     //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    Endif
    SET STOP pLOSS 500

    I cleaned it up with no delay or strange trailing start and steps. If you look at the trade that starts May 12 08:00 and don’t sell of until June 15 you will se the problem. That trade should have been closed May 12/13 if the trailing stop was working.

    30 min timeframe, DAX

    #198479 quote
    phoentzs
    Participant
    Master

    Am I making myself so slurred? trailstart must be larger than trailstep.

    #198480 quote
    Mr.Mjau
    Participant
    New
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[20](close)
    indicator2 = Average[100](close)
    c1 = (indicator1 CROSSES UNDER indicator2)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = Average[20](close)
    indicator4 = Average[100](close)
    c2 = (indicator3 CROSSES OVER indicator4)
    
     
    If c2 Then
    // Stops and targets
    trailingstart = 10   //trailing will start @trailinstart points profit
    trailingstep  = 30     //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    Endif
    SET STOP pLOSS 500
    

    Disregard the last one. This one is correct. (Both will give the same result but the other one got some code in it that don’t belong)

    I cleaned it up with no delay or strange trailing start and steps. If you look at the trade that starts May 12 08:00 and don’t sell of until June 15 you will se the problem. That trade should have been closed May 12/13 if the trailing stop was working.

    DAX 30min

    #198481 quote
    phoentzs
    Participant
    Master

    13509 08:00 on 05/12

    13665 21:00 on 05/12.

    Ergo… try trailstart 100 and trailstep 5 and see what happens.

    #198482 quote
    Mr.Mjau
    Participant
    New

    Trailstart 100 Trailstep 5, does not change that trade for me.

    13509 08:00 05/12

    13494 14:00 06/15

    Did a backtest with 100 and 5, on 5k units. Do you get the same numbers as me?

    5k.png 5k.png
    #198484 quote
    phoentzs
    Participant
    Master

    I don’t have a laptop handy.

    @Grahal

    #198491 quote
    GraHal
    Participant
    Master

    Import attached .itf and try out, my results attached.

    Start 50 Step 25 SL 200 1 min TF spread = 5 (should be 2)

    Mr.Mjau thanked this post
    Mjau-MAxTS-DAX-M1-10K-v1gh.itf TS.jpg TS.jpg
    #198494 quote
    Mr.Mjau
    Participant
    New

    Used the file and got same result,ty

    Yes now you to can to see the problem. For example the first trade in your pic, the one that stays in the market for half the chart. 3-4 times it have +100p drop and don’t sell of.

    Same with the last trade, it droped over 100p before sold.

    If you change your settings from 1min to 30 min, the problem becomes even more clearly. There you can for example see one trade that was good in profit fall 1000p without beeing sold.

    (Used the file and got same result,ty)

    #198499 quote
    GraHal
    Participant
    Master

    have +100p drop and don’t sell of

    That because you asked for C2 (c2 = (indicator3 CROSSES OVER indicator4) to trigger WHEN the Trailing Stop is to start Trailing.

    So the Trailing Stop started on 27 July at 13,222 (as you can see from the variable Line / newSL I added for you as GRAPH newSL) and the trade exited at 13,197 on 28 July.  See attached at red arrowhead for TS Start and Blue arrowhead for Trade Exit.

    Beware of what you ask for! 🙂

    Mr.Mjau thanked this post
    TS2.jpg TS2.jpg
    #198501 quote
    Mr.Mjau
    Participant
    New

    Plz just try with a higher setting 5 min, 15 min, 30 min. and post a pic of it. If you don’t see it then we just drop this and move on.

    #198502 quote
    GraHal
    Participant
    Master

    I see what you are saying and I agree with your observation, but there is a lot of ground you need to cover / reading up / thinking / testing … to understand why.

    For example, same code / settings on 15 min TF but C2 setting is now as below … see what a difference it makes?

    c2 = (indicator3 > indicator4)

    TS3.jpg TS3.jpg
    #198506 quote
    GraHal
    Participant
    Master

    Start thinking on attached … this is with c2 = (indicator3 crosses over indicator4) but see the variable line this is GRAPH = Close < newSL AND C2 = 0.

    TS4.jpg TS4.jpg
    #198508 quote
    GraHal
    Participant
    Master

    But what you want is C2 = 1 / True because you asked for c2 = (indicator3 crosses over indicator4).

    Attached is GRAPH = Close < newSL AND C2 = 1

    As you can see from attached … above doesn’t happen ever … see the straight line at 0 !

    I stand to be corrected on my findings as I have done this a bit too quick maybe?

    TS5.jpg TS5.jpg
    #198510 quote
    phoentzs
    Participant
    Master

    In hindsight it’s logical. If the trail settings don’t exactly match the cross, i.e. right at the one candle, the trail never starts to work. So no cross but a > b.

    Mr.Mjau thanked this post
Viewing 15 posts - 31 through 45 (of 69 total)
  • You must be logged in to reply to this topic.

Trigger Trailing SL if target is met


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mr.Mjau @mr-mjau Participant
Summary

This topic contains 68 replies,
has 5 voices, and was last updated by Mr.Mjau
3 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/30/2022
Status: Active
Attachments: 17 files
Logo Logo
Loading...