Hi
I’m fully aware that we can use the code below to set a stop loss of 20 points but this is visible to the broker.
SET STOP PLOSS 20
Twice now, my stop loss has been hit by 1 or 2 points and then gone on to achieve the 100 point target. This annoys me.
I’m assuming it would be possible to not set a stop loss as above but to achieve it via code. Yes I’m aware this would carry more risk but has anyone done this who could share their code?
Thanks
Rob
Does this seem correct please?
manualstoploss = 20 // manual stop loss pips/points
// LONGS
// Test if the price has moved to the manual stop loss level
IF LONGONMARKET AND close-tradeprice(1)>=manualstoploss*pipsize THEN
SELL AT MARKET
ENDIF
// SHORTS
// Test if the price has moved to the manual stop loss level
IF SHORTONMARKET AND close+tradeprice(1)>=manualstoploss*pipsize THEN
EXITSHORT AT MARKET
ENDIF
Cheers
Rob
Yes, but be aware that your code would be only read once per bar and thus the stoploss triggered much larger than your “manualstoploss” value. It would not be so important in a 1 second timeframe, but a lot more in an 1 hour one obviously 🙂