Hello everyone, hope you are well! 🙂
I have a problem that I can’t figure out…
Bellow is the code I’d like to use to get my SL. I’d like it to follow the trade if it become positive otherwise, I’d like that if the price crosses the SSpanB it stops. (I tried only for the long for now)
Can you help me a bit? 😀
Thanks!
PointsToKeep = 10 //
startBreakeven = 6 //Pas en dessous de 6
once breakeven = 1//1 on - 0 off
//reset the breakevenLevel when no trade are on market
if breakeven>0 then
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven THEN
//calculate the breakevenLevel
breakevenLevel = price - PointsToKeep
Elsif LONGONMARKET and price crosses under SSpanB THEN
EXITSHORT at market
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
endif
To exit from a Long trade you have to use SELL (not EXITSHORT).