Buongiorno Roberto,
sarebbe possibile aggiungere al tuo codice di trailing stop un primo step che porta a breakeven (es. al raggiungimento di 30 punti di guadagno = sl a breakeven +1 punto, lasciando la variabile PointsToKeep )
successivamente solo al raggiungimento step2 (es. + 60 punti) inizia il trailing stop con step di n. punti (es. 20 punti)
successivamente al raggiungimento step3 (es. + 120 punti) modifica il trailing stop con step di n. punti (es. 10 punti)
Ti ringrazio anticipatamente per l’aiuto e per il grande lavoro per il forum.
//trailing stop function
IF NOT ONMARKET THEN
TrailingStart = 20 //20 trailing will start @trailinstart points profit
TrailingStep = 5 //5 trailing step to move the “stoploss”
Distance = 7 //7 pips Distance from caurrent price (if required by the broker)
PointsToKeep = 1 //1 pips to be gained when breakeven is set
//reset the stoploss value
newSL=0
ENDIF
IF (BarIndex – TradeIndex) >= 0 THEN //0
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND high-TradePrice(1)>=(TrailingStart*PipSize+PointsToKeep*PipSize) THEN
newSL = TradePrice(1)+TrailingStep*PipSize+PointsToKeep*PipSize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=TrailingStep*PipSize THEN
newSL = newSL+TrailingStep*PipSize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND TradePrice(1)-low>=(TrailingStart*PipSize+PointsToKeep*PipSize) THEN
newSL = TradePrice(1)-TrailingStep*PipSize+PointsToKeep*PipSize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=TrailingStep*PipSize THEN
newSL = newSL-TrailingStep*PipSize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + Distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close – Distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + Distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close – Distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//**************************************