Trailing stop – aggiunta steps breakeven + steps incremento

Forums ProRealTime forum Italiano Supporto ProOrder Trailing stop – aggiunta steps breakeven + steps incremento

  • This topic has 2 replies, 2 voices, and was last updated 1 year ago by avatarSimon.
Viewing 3 posts - 1 through 3 (of 3 total)
  • #207881

    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

    //**************************************

    #208065

    Eccolo (non l’ho provato):

     

    #208180

    Grazie Roberto,

    gentilissimo!

    Allego codice modificato con variabili, lo sto testando.

    Buona giornata

    1 user thanked author for this post.
Viewing 3 posts - 1 through 3 (of 3 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login