Trigger Trailing SL if target is met

Viewing 15 posts - 46 through 60 (of 69 total)
  • Author
    Posts
  • #198511 quote
    Mr.Mjau
    Participant
    New

    Yes I think you jumped to DJI but np. For me this happends step by step.

    Buy 8/4 17:30 @32671

    newSL 32721
    newSL 32796

    newSL 33321

    Sold 2/5 20:30 @32471 (900 points below SL?)

    What am I missing?

    DJI-15-minutes.png DJI-15-minutes.png
    #198513 quote
    Mr.Mjau
    Participant
    New

    @phoentzs YES!!!!! 🙂

    And if you pick a low intrerval like 1 min it will match so often that you miss it. With larger interval it becomes more visible.

    #198514 quote
    GraHal
    Participant
    Master

    What am I missing?

    I think you are missing that unless C2 =1 / True that the Trailing Stop (TS) will not function / trail.  If C2=0 the Trail is switched off. Remember also that crosses over means crosses over at the end of that bar (when the code is read)NOT has crossed over in the previous bar or some bar prior to that. The TS probably needs some extra lines of code to make newSL = 0 when C2 =0.  As the TS code stands, newSL appears to remain at a previous value but is not functioning as a Trailing Stop (due to C2 = 0)? Often working out what is and what is not happening is very time consuming, if you are interested enough to want to find out … keep at it, spend time and more time on it, but in the end will it make you money?? 🙂 Whilst I can do above, and have for myself in the past (teach yourself – the best way to learn!) I tend to concentrate on getting a Trading System to give a good equity curve and good stats etc and then the time  seems worth the effort and it feels like I am working towards a positive goal? I feel here we are pursuing a strategy that is not going anywhere anyway??  Ditch the ‘crossing over’ and move on is my advice. Anybody who can see what I have not seen in this code / strategy feel free to jump in please!? 🙂
    #198515 quote
    phoentzs
    Participant
    Master
    If you omit your exit cross, you miss the exits that end negative and always end up in the SL. If you choose a > b as the trigger for the trail, you will also miss the negative-ended outputs. So the solution remains… leave the exitcross in the code and optimize the trail independently to land a little more hits.
    #198516 quote
    Mr.Mjau
    Participant
    New
    I used Crosses Over with [2] delay if you guys remember, and it’s working great for me. My ide with it triggering a trailing SL and not a sell was to see if I could cram just a little bit more out of it. So the Cross will remain, and the trailing is out. This is a great way to learn, for me atlest 🙂   Tank you guys for taking time to help me.
    #198517 quote
    GraHal
    Participant
    Master
    Ha … I’ve maybe solved it … a Flag which stays at 1 after C2 = 1? Results attached Code / .itf attached which retains the crosses over! 🙂
    Mr.Mjau thanked this post
    Mjau-MAxTS-DAX-M1-10K-v2gh.itf TSON.jpg TSON.jpg
    #198520 quote
    GraHal
    Participant
    Master
    And here we are, we’re even making money now!!! Attached with re-optimised settings!!
    Mr.Mjau thanked this post
    TSON2.jpg TSON2.jpg
    #198522 quote
    Mr.Mjau
    Participant
    New
    You beautiful son of a gun!!!!!! U did it!!! Works fine now, what I can see Now time for optimising start and trail values
    GraHal thanked this post
    #198523 quote
    GraHal
    Participant
    Master
    Even good on 5 min TF – see attached! More interested now I can see profit and good equity curve, it’s only over 10K bars I know but hey that suits me anyway!! Make Money while You Sleep! 😉
    Mr.Mjau thanked this post
    TSON3.jpg TSON3.jpg
    #198545 quote
    Mr.Mjau
    Participant
    New
    Been looking over the data testing tinkering, and it looks like the Trailing Stop only starts when the position is in profit. “trailing will start @trailinstart points profit”. Have I understod this right? And if so is there a way to make the trailingstop to start at cross even if the position is not in profit? And also, in the code you send to me last night, you have A21, A22 and A46 and not numbers, what are those and how does that work?
    #198550 quote
    GraHal
    Participant
    Master
    Trailing Stop only starts when the position is in profit
    Yes above is how a normal Trailing Stop normally works.
    is there a way to make the trailingstop to start at cross even if the position is not in profit?
    Does the cross ever occur if the position is not in profit. Use GRAPH to find out and let us know.
    you have A21, A22 and A46 and not numbers, what are those and how does that work?
    Look in the optimiser and you will see the above code line numbers as variable names.
    #198551 quote
    robertogozzi
    Moderator
    Master
    This version will NOT use TRAILINGSTART, as it will start from the Stop Loss, then will increase it by TRAILINGSTEP pips as the price exceeds the previous SL by TRAILINGSTEP * 2 pips. I also added a Take Profit to avoid trades lasting several months. You will spot a few more changes throughout the code. Be warned that strategies based solely on average crossovers are very prone to future losses, as backtests are usually and easily overoptimized.
    // 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 AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    NewSL = 0
    TSON  = 0
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = Average[20](close)
    indicator4 = Average[100](close)
    c2 = (indicator3 crosses over indicator4)
    
    IF OnMarket AND Not OnMarket[1] THEN
    NewSL = TradePrice - (A46 * PipSize)
    ENDIF
    
    If C2 AND OnMarket Then
    TSON = 1
    Endif
     
    If TSON Then
    // Stops and targets
    trailingstart = A21 //10   //trailing will start @trailinstart points profit
    trailingstep  = A22 //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
    IF close>=NewSL+(trailingstep*pipsize*2) THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    Endif
    
    TSOUT = Close < newSL AND C2 = 1
    //GRAPH Close < newSL
    SET STOP pLOSS A46 //500
    set target pProfit A46*A99
    //GRAPH C2
    //GRAPH TSOUT
    graphonprice NewSL coloured(0,0,255,255)
    graphonprice tradeprice
    GraHal and Mr.Mjau thanked this post
    Mjau-MAxTS-DAX-M1-10K-v2gh-X.itf
    #198553 quote
    GraHal
    Participant
    Master
    Link to above added as Log 333 here … Snippet Link Library
    robertogozzi thanked this post
    #198569 quote
    Mr.Mjau
    Participant
    New
    @GraHal Yes I use trailingstops everyday in my manuell trading, 90% of them start in the red and some end up in the red to. So to me that “Trailing Stop only starts when the position is in profit” was super strange 🙂 The cross does occur even when the position is not in profit, but you have to max out SL and even then is not very common. I do get is kinda odd to ask that coz it almost never happends, but for me I need to know what happens at the extremes to understand the big picture. Found the optimizer :rofl: now I got the weekend cut out for me :thumbsup: @robertogozzi O tank you so much, this is just what I was looking for! Now I have another tool to use. Will look over it this weekend :thumbsup:
    GraHal thanked this post
    #198580 quote
    GraHal
    Participant
    Master
    Yes above is how a normal Trailing Stop normally works.
    What I should have said is … how a normal coded Trailing Stop works.
    90% of them start in the red
    Above is because you start the manual Trailing Stop after the trade is opened (most trades go in the red immediately after open, if only due to spread)?
    Mr.Mjau thanked this post
Viewing 15 posts - 46 through 60 (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...