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/04/2022 at 8:23 PM #19851108/04/2022 at 8:47 PM #19851308/04/2022 at 9:09 PM #198514
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!? 🙂
08/04/2022 at 9:09 PM #198515If 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.
08/04/2022 at 9:28 PM #198516I 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.
08/04/2022 at 9:28 PM #19851708/04/2022 at 9:33 PM #19852008/04/2022 at 9:34 PM #19852208/04/2022 at 9:43 PM #198523Even 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! 😉
1 user thanked author for this post.
08/05/2022 at 10:23 AM #198545Been 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?
08/05/2022 at 10:49 AM #198550Trailing 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.
08/05/2022 at 11:48 AM #198551This 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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// 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 tradeprice08/05/2022 at 12:49 PM #198553Link to above added as Log 333 here …
1 user thanked author for this post.
08/05/2022 at 4:18 PM #198569Yes 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:
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:
1 user thanked author for this post.
08/05/2022 at 5:40 PM #198580Yes 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)?
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on