Trigger Trailing SL if target is met

Viewing 9 posts - 61 through 69 (of 69 total)
  • Author
    Posts
  • #198596 quote
    PeterSt
    Participant
    Master

    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)?

    I am not Mr.Mjau, but No, Why ?

    One thing : can you add a Trailing Stop with Manual Trading in PRT-IG ? (hint : I can’t)

    @Mr.Mjau, I didn’t follow all to the letter, but you are on the PRT-IG platform, right ?
    (if you’re on PRT-IB, no wonder – all these issues (mis-communication ?))

    #198598 quote
    GraHal
    Participant
    Master

    can you add a Trailing Stop with Manual Trading in PRT-IG ?

    Yes by right clicking an open trade and it is an option, but I recall there is a setting, maybe even on IG Settings, to enable Trailing Stop before the TS can be seen as an option.

    #198599 quote
    Mr.Mjau
    Participant
    New

    GraHal wrote:

    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)?

    Yes this is correct, usually put on the trailing after some time I’ve been in the trade. So yes almost all start in red

    #198600 quote
    Mr.Mjau
    Participant
    New

    @Mr.Mjau, I didn’t follow all to the letter, but you are on the PRT-IG platform, right ?

    (if you’re on PRT-IB, no wonder – all these issues (mis-communication ?))

    Yes I’m on PRT-IG platform, but maybe just bad at expressing myself 🙂

    #198740 quote
    Mr.Mjau
    Participant
    New

    @GraHal

    I’ve spent the weekend looking over the 2 files you made, and I think we still have some problems.

    The first one “Mjau MAxTS DAX M1 10K v1gh” will start trailing when C2 happens. The starting point of the trail will be where the position started+A21, so not point C2. I guess if it’s not possible to start from c2, then letting the trail start from where the position began is the next best thing. The biggest problem with this file is that the rule of c2 keeps lingering in the trailing, so it ONLY makes a trailing step when c2 happends. See attachment:(Mb this version was just a rushed test?)

    On the second one “Mjau MAxTS DAX M1 10K v2gh” Does not have the lingering C2 problem. This one will start trailing from where position started +(A22), probably even better then +A21 like it was in the last one. Problem with this one is that the trailing SL will only start if C2 happends when position is in profit, this makes “Time in the market” explode. Is there a way to make trailing start in C2 even if the position is not in profit?

    C2-Problems.png C2-Problems.png
    #198743 quote
    GraHal
    Participant
    Master

    Is there a way to make trailing start in C2 even if the position is not in profit?

    Yes Roberto kindly provided us with above on the link beow

    Trigger Trailing SL if target is met

    #198748 quote
    Mr.Mjau
    Participant
    New

    Yes I looked at the code from Roberto gave. He solves the problem with by setting the starting point at SL. The problem with this is that it takes such a long time for the trailingsl to get to good level. If A22=50 and A46=400 it will take 8 bars after c2 just to get where the position started.

    Maybe we are at that point where we have to choose between your version that starts in a good place but don’t get triggerd if c2 is below starting point or Robertos that takes a long time to get the sl-level up.

    Either way, making a trailingSL this way makes it dependent on steps per bar and works from bottom up that takes time, and is an inferior way to how SET STOP pTRAILING works.

    Is there no way to make something like “IF C2 THEN SET STOP pTRAILING xx” to work?

    #198759 quote
    GraHal
    Participant
    Master

    You could have a go yourself or do you not do any coding?

    Try …

    If C2 or TSON Then
    Set Stop pTrailing X
    Endif

    Or you could run the v2gh version on a shorter timeframe … 5 mins or 1 min then the code will be read every 5 mins or 1 min and so the Trail will act faster.

    Mr.Mjau thanked this post
    #205256 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 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

     

     

    Waking this tread up

    I have been using the code Roberto provided for some time now with okey results.

    But there is one problem with it, and that it some time makes an error smt like “Can’t put stoploss below current market price” or smt like that. And that makes the program stop is there a way to fix this? ty

Viewing 9 posts - 61 through 69 (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...