This code snippet demonstrates how to implement a breakeven and trailing stop strategy using percentage values in ProBuilder language. The strategy adjusts the stop loss level once a trade reaches a specified profit percentage, helping to protect gains or minimize losses.
BreakEvenStop = 1 // BreakEvenStop and BreakEvenStop Minimum Gain
bs = 1.00 // % BreakEvenStop
bsm= 0.10 // % BreakEvenStop Minimum Gain
if tcShort and tcxShort then
if (s0 or s1 or s2 or s3 or s4 or s5 or s6 or s7 or s8 or s9) then
sellshort positionsize contract at market
shorttradecounter=shorttradecounter + 1
If BreakEvenStop then
SET STOP %LOSS bsm
endif
endif
endif
// BreakEvenStop
If BreakEvenStop then
if not onmarket then
newSL=0
endif
If longonmarket and close-tradeprice(1)>=((tradeprice/100)*bs)*pipsize then
newSL = tradeprice(1)+((tradeprice/100)*bsm)*pipsize
endif
If shortonmarket and tradeprice(1)-close>=((tradeprice/100)*bs)*pipsize then
newSL = tradeprice(1)-((tradeprice/100)*bsm)*pipsize
endif
If newSL>0 then
sell at newSL Stop
exitshort at newSL Stop
endif
endif
The code snippet above is structured to manage trading positions by setting breakeven and trailing stops based on percentage gains:
This approach helps in managing ongoing trades by dynamically adjusting stop levels based on market performance relative to the entry point, aiming to secure profits or reduce potential losses.
Check out this related content for more information:
https://www.prorealcode.com/topic/stoploss-stuck-after-being-set/#post-71117
Visit Link