Modifica Stop Loss

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #73957 quote
    traderwin
    Participant
    Average

    Salve, supponiamo di avere un trade long, ad esempio: lond dax 13000, stop 12900, target 13300

    Come faccio a spostare lo stop loss su di 40  punti (sopra lo stop loss iniziale) quando ad esempio il trade mi sta guadagnando 70 punti?

    Quindi la gestione dovrebbe essere cosi’: quando la mia posizione arrivera in area 13070, lo stop loss si deve spostare in area 12940.

    Spero di essere stato chiaro e grazie a chi mi aiutera’ 🙂

    #73959 quote
    robertogozzi
    Moderator
    Master

    Puoi utilizzare il codice, pronto per l’uso, scritto da Nicolas, mettendo nel tuo esempio uno start di 70 ed uno step di 40 https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    #73961 quote
    traderwin
    Participant
    Average

    Ciao Roberto, ho provato il codice di Nicolas. Ma se faccio uno start di 70 punti, e step da 40, mi inserisce lo stop 40 punti spra il prezzo di entrata trade e non 40 punti in piu’ rispetto lo stop loss statico di apertura posizione

    #74057 quote
    robertogozzi
    Moderator
    Master

    Ho modificato il codice di Nicolas affinché faccia quello (o quasi) che vuoi tu. Inizia ad applicare lo start dallo SL originale, solo che lo step lo fa ad ogni barra successiva anche se ha fatto meno pips, basta che sia maggiore del nuovo SL.

    Dal tuo esempio:

    • long dax 13000, stop 12900, target 13300, con start 40 e step 20
    • appena il prezzo arriva a 13041, quindi supera lo start, lo SL lo mette a 12940
    • alla barra successiva, anche se il prezzo scende a 13030, oppure sale a 13045, siccome ci sono più di 20 pips di distanza, contibua a fare salire di 20 lo SL portandolo a 12960

    Non è quello che volevi esattamente, perché dovrebbe farlo salire di altri 20 solo quando sale almeno a 13061, ecc…

    //************************************************************************
    // trailing stop function (versione modificata #1)
    //
    trailingstart = 40   //20   trailing will start @trailinstart points profit
    trailingstep  = 20    //5    trailing step to move the "stoploss"
    mainSL        = 100  //100  initial SL
    //
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    InitialSL=0
    ENDIF
    //manage long positions
    IF LONGONMARKET THEN
    IF InitialSL = 0 THEN
    InitialSL = tradeprice(1) - (mainSL * pipsize)
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    //newSL = tradeprice(1)+trailingstep*pipsize
    newSL = InitialSL+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
    IF InitialSL = 0 THEN
    InitialSL = tradeprice(1) + (mainSL * pipsize)
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    //newSL = tradeprice(1)-trailingstep*pipsize
    newSL = InitialSL-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
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************

    quest’altra versione, invece, dovrebbe fare esattamente quello che chiedi tu, fai delle verifiche e vedi quale può andarti meglio:

    //************************************************************************
    //     trailing stop function  (versione modificata #2)
    //
    trailingstart = 30   //30   trailing will start @trailinstart points profit
    trailingstep  = 20   //10   trailing step to move the "stoploss"
    mainSL        = 100  //100  initial SL
    //
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    InitialSL=0
    MyPrice=0
    ENDIF
    //manage long positions
    IF LONGONMARKET THEN
    IF InitialSL = 0 THEN
    InitialSL = tradeprice(1) - (mainSL * pipsize)
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    //newSL = tradeprice(1)+trailingstep*pipsize
    newSL = InitialSL+trailingstart*pipsize
    MyPrice=close
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize AND (close > (MyPrice + trailingstep * pipsize)) THEN
    newSL = newSL+trailingstep*pipsize
    MyPrice=close
    ENDIF
    ENDIF
    //manage short positions
    IF SHORTONMARKET THEN
    IF InitialSL = 0 THEN
    InitialSL = tradeprice(1) + (mainSL * pipsize)
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize AND (close < (MyPrice - trailingstep * pipsize)) THEN
    //newSL = tradeprice(1)-trailingstep*pipsize
    newSL = InitialSL-trailingstart*pipsize
    MyPrice=close
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    MyPrice=close
    ENDIF
    ENDIF
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Modifica Stop Loss


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
traderwin @traderwin Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
7 years, 7 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 06/21/2018
Status: Active
Attachments: No files
Logo Logo
Loading...