Hello, after following the discussion on the forum about trailing stops, I think this is way too complicated, so I made a simplified version. We start with a trail stop a few points below our entry price, so that if things start immediately against us, we keep a good mood. If the trade comes our way, the trail stop will be increased. Furthermore, we always sell our trades “at market” so that we do not have to take restrictions from the broker into account (especially when announcing important economic data, for example)
Moving stoploss
/////////////////////////////////////////////////////////////////////
//// values for DAX ////////
////////////////////////////////////////////////////////////////////
SET TARGET pPROFIT 100 // max profit
SET STOP pLOSS 35 // max loss
///trailing stop function
trailingstep = 25 // trailing step to move the "stoploss"
firstStep = 10 // set newSL at x points under buying price by start
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
OpenAtpriceL=1000000
OpenAtpriceS=0
ENDIF
//////////////////////////////////////////////////////////////////////
/// managing positions /////
//////////////////////////////////////////////////////////////////////
//manage long positions
IF LONGONMARKET THEN
//first move (a tiny bit under buying price)
IF newSL=0 THEN
OpenAtPriceL= close
newSL = OpenAtPriceL - firstSTep
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
IF newSL=0 THEN
OpenAtPriceS= close
newSL = OpenAtPriceS + firstSTep
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
// exit the positions
IF newSL>0 and LongOnMarket THEN
IF close < newSL THEN
SELL AT Market
ENDIF
ENDIF
IF newSL>0 and ShortOnMarket THEN
IF close > newSL THEN
EXITSHORT AT Market
ENDIF
endif
Don’t copy the first line. (1. moving stoploss)
Hi Deathmetal,
thanks for this. I’ve experienced problem with stop loss, especially stop limit order refused by broker during the trailing. is it this kind of problem that it overcomes? thanks
Alessio
Interesting. I will amend my trailing “stops” without orders at market.
JSParticipant
Senior
Using “market orders” in a trailing stop is fine, but only on a fast time frame… you don’t want to wait too long for your Trailing Stop Market Orders to be executed…