Hallo, kann man in dem Code von Roberto aus Post #172745 eine Funktion hinzufügen, dass der Trailingstop erst beginnt zu arbeiten wenn eine andere Bedingung erfüllt ist?
Zum Beispiel für LONG: Close>MA5, der Code beginnt Gewinne zu sichern.
Selbiges für SHORT: Close<MA5, der Code beginnt Gewinne zu sichern.
Da ist er:
//************************************************************************
//trailing stop function
trailingstartL = 20 //LONG trailing will start @trailinstart points profit
trailingstartS = 20 //SHORT trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
Distance = 6 * PipSize
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
MyTScondition = close < .......
IF MyTScondition OR NewSL > 0 THEN
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
newSL = tradeprice(1)+trailingstep*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)-close>=trailingstartS*pipsize THEN
newSL = tradeprice(1)-trailingstep*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 LIMIT
ELSIF (close + Distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//************************************************************************
Weisen Sie der Variablen MyTScondition die Bedingung Ihrer Wahl zu.
Aber muss nicht MYTScondition verschiedener Art sein wenn ich für Long und Short unterschiedliche Merkmale habe?
Für mein Verständnis müßte es nicht in die beiden „if longonmarket… if shortonmarket…“ Blöcke?
Ich glaub, ich habe es mir gerade selbst beantwortet:
“if longonmarket and mylongTScondition then“
Und dann halt nochmal für Short.
Oder habe ich einen Denkfehler?
Natürlich können Sie, ändern Sie einfach die Zeilen 13-15 wie folgt:
MyTSconditionL = close < .......
MyTSconditionS = .............
IF MyTSconditionL OR MyTSconditionS OR NewSL > 0 THEN
Danke Dir. Ich versuche es.