Forums › ProRealTime English forum › ProOrder support › Trailing Stop and Breakeven codes › Reply To: Trailing Stop and Breakeven codes
10/17/2021 at 10:05 AM
#179813
This is the code for breakeven from https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
trailingstart = 30 //breakeven will be set at this profit level points2keep = 10 //points to keep at breakeven //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)+points2keep*pipsize ENDIF ENDIF //manage short positions IF SHORTONMARKET THEN //first move (breakeven) IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN newSL = tradeprice(1)-points2keep*pipsize ENDIF ENDIF //stop order to exit the positions IF newSL>0 THEN SELL AT newSL STOP EXITSHORT AT newSL STOP ENDIF |