Trigger Trailing SL if target is met
Forums › ProRealTime English forum › ProOrder support › Trigger Trailing SL if target is met
- This topic has 68 replies, 5 voices, and was last updated 2 years ago by Mr.Mjau.
-
-
08/05/2022 at 7:07 PM #198596
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 ?))08/05/2022 at 7:56 PM #198598can 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.
08/05/2022 at 8:38 PM #198599Above 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
08/05/2022 at 8:42 PM #198600@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 🙂
08/08/2022 at 1:26 PM #198740@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?
08/08/2022 at 1:32 PM #198743Is 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
https://www.prorealcode.com/topic/trigger-trailing-sl-if-target-is-met/page/4/#post-198551
08/08/2022 at 2:15 PM #198748Yes 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?
08/08/2022 at 4:58 PM #198759You could have a go yourself or do you not do any coding?
Try …
123If C2 or TSON ThenSet Stop pTrailing XEndifOr 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.
1 user thanked author for this post.
12/04/2022 at 11:27 PM #205256123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[20](close)indicator2 = Average[100](close)c1 = (indicator1 CROSSES under indicator2)IF c1 AND Not OnMarket THENBUY 1 CONTRACT AT MARKETNewSL = 0TSON = 0ENDIF// Conditions to exit long positionsindicator3 = Average[20](close)indicator4 = Average[100](close)c2 = (indicator3 crosses over indicator4)IF OnMarket AND Not OnMarket[1] THENNewSL = TradePrice - (A46 * PipSize)ENDIFIf C2 AND OnMarket ThenTSON = 1EndifIf TSON Then// Stops and targetstrailingstart = A21 //10 //trailing will start @trailinstart points profittrailingstep = A22 //30 //trailing step to move the "stoploss"//reset the stoploss value//IF NOT ONMARKET THEN//newSL=0//ENDIF//manage long positionsIF 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 THENIF close>=NewSL+(trailingstep*pipsize*2) THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFEndifTSOUT = Close < newSL AND C2 = 1//GRAPH Close < newSLSET STOP pLOSS A46 //500set target pProfit A46*A99//GRAPH C2//GRAPH TSOUTgraphonprice NewSL coloured(0,0,255,255)graphonprice tradepriceWaking 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
-
AuthorPosts
Find exclusive trading pro-tools on