I am wondering how to code a system that allows me to set a stop loss tight in case market goes against me first 1-3 bars after i execute my order, then change it to a larger one after that. I am cureently using the excellent nicolas trailing stop – the MFE version.
Although i didn’t write it obviously this seems to execute sell or sellshort rather than changing the stop ie it doesnt actually set a trailing or other stop.
I have tried with a variable that resets as it cycles but im not sure this is the best way?
There you go. You need to set SL1 (tigther SL) and SL2 (the greater one) and the number of bars (N):
SL1 = 20 //initial SL
SL2 = 50 //larger SL
N = 3 //number of bars to keep the tighter SL
IF MyLongConditions AND NotOnMarket THEN
BUY 1 CONTRACT AT MARKET
SET STOP pLOSS SL1
Count = 1
ENDIF
IF OnMarket AND Count > 0 THEN
Count = Count + 1
IF Count > N THEN
SET STOP pLOSS SL2 //Switch to a larger SL after N bars
Count = 0
ENDIF
ENDIF