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:37 AM #19847208/04/2022 at 9:51 AM #198478123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// 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 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = Average[20](close)indicator4 = Average[100](close)c2 = (indicator3 CROSSES OVER indicator4)IF c1 THENBUY 5 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = Average[20](close)indicator4 = Average[100](close)c2 = (indicator3 CROSSES OVER indicator4)If c2 Then// Stops and targetstrailingstart = 10 //trailing will start @trailinstart points profittrailingstep = 30 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFEndifSET 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
08/04/2022 at 9:56 AM #19847908/04/2022 at 10:18 AM #19848012345678910111213141516171819202122232425262728293031323334353637383940414243444546// 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 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = Average[20](close)indicator4 = Average[100](close)c2 = (indicator3 CROSSES OVER indicator4)If c2 Then// Stops and targetstrailingstart = 10 //trailing will start @trailinstart points profittrailingstep = 30 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFEndifSET STOP pLOSS 500Disregard 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
08/04/2022 at 10:30 AM #19848108/04/2022 at 10:41 AM #19848208/04/2022 at 10:46 AM #19848408/04/2022 at 1:08 PM #19849108/04/2022 at 1:34 PM #198494Used 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)
08/04/2022 at 7:02 PM #198499have +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! 🙂
1 user thanked author for this post.
08/04/2022 at 7:15 PM #19850108/04/2022 at 8:00 PM #198502I 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)
08/04/2022 at 8:04 PM #19850608/04/2022 at 8:12 PM #198508But 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?
08/04/2022 at 8:17 PM #198510 -
AuthorPosts
Find exclusive trading pro-tools on