Trailing Stop

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #84214 quote

    Buongiorno,

    Avrei bisogno di codificare il trailing stop in base agli orari di contrattazione….quindi piu di un trailing stop nella stessa strategia .

    non so se è possibile …..

    vi ringrazio

    ciao mauro

    #84216 quote
    robertogozzi
    Moderator
    Master

    Puoi fare un esempio per chiarire il concetto?

    #84219 quote

    Ciao Roberto … Io uso normalmente un trailing Stop in percentuale…. Questa percentuale rimane fissa (esempio… 0.95%) nelle 24 ore di contrattazione…. Vorrei modificarla ad esempio dalle 00.00 alle 13.00.. 0.95% e dalle 13.00 alle 23.00 1.30%.

    Ciao grazie

    #84222 quote
    robertogozzi
    Moderator
    Master

    Riprendo l’esempio della documentazione e te lo modifico (https://www.prorealcode.com/documentation/percenttrailing/):

    i1 = average(close)[100]
    i2 = average(close)[5]
    
    tradeinitiate = Close>i1 AND Close<i2 AND Low[3]>Low[2] AND Low[2]>Low[1] AND Low[1]>Low
    tradeclose = Close>Close[1]
    
    IF NOT LongOnMarket AND tradeinitiate THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    If LongOnMarket AND tradeclose THEN
       SELL AT MARKET
    ENDIF
    
    //set stop loss trailing at 1.5 percent from the current average price
    IF time >= 000000 AND time <= 130000 THEN
       SET STOP %TRAILING 0.95
    ELSIF time > 130000 AND time <= 230000 THEN
       SET STOP %TRAILING 1.30
    ENDIF
    #84231 quote

    Grazie per la risposta…. Ma io uso anche il Target e lo stop con prorealtime non funziona se metti anche il trailing…. Difatti uso per il trailing questo sistemerà…

    percentagelong  = 0.45
    percentageshort  = 0.30
    TGL = (close/100)*percentagelong
    TGS = (close/100)*percentageshort
    
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    PREZZOUSCITA = 0
    ENDIF
    
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close)
    if MAXPRICE-tradeprice(1)>=TGL then
    PREZZOUSCITA = MAXPRICE-tgl
    ENDIF
    ENDIF
    
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close)
    if tradeprice(1)-MINPRICE>=TGS then
    PREZZOUSCITA = MINPRICE+tgs
    ENDIF
    ENDIF
    
    if onmarket and PREZZOUSCITA>0 then
    EXITSHORT AT PREZZOUSCITA STOP
    SELL AT PREZZOUSCITA STOP
    ENDIF

    Ciao Mauro

    #84232 quote

    Ho inserito per sbaglio questa riga che non serve…
    close/100)*percentagestepshort

    #84233 quote
    robertogozzi
    Moderator
    Master

    Per scrivere il codice , utilizza il pulsante <> “insert PRT code” in modo da rendere il codice più comprensibile. Grazie.

    E’ quasi uguale, dove hai messo le percentuali basta verificare gli orari (io ho messo le stesse percentuali, tu metti quelle che vuoi):

    IF time >= 000000 AND time <= 130000 THEN
       percentagelong   = 0.45
       percentageshort  = 0.30
    ELSIF time > 130000 AND time <= 230000 THEN
       percentagelong   = 0.45
       percentageshort  = 0.30
    ENDIF
    TGL = (close/100)*percentagelong
    TGS = (close/100)*percentageshort
    
    if not onmarket then
       MAXPRICE = 0
       MINPRICE = close
       PREZZOUSCITA = 0
    ENDIF
    
    if longonmarket then
       MAXPRICE = MAX(MAXPRICE,close)
       if MAXPRICE-tradeprice(1)>=TGL then
          PREZZOUSCITA = MAXPRICE-tgl
       ENDIF
    ENDIF
    
    if shortonmarket then
       MINPRICE = MIN(MINPRICE,close)
       if tradeprice(1)-MINPRICE>=TGS then
          PREZZOUSCITA = MINPRICE+tgs
       ENDIF
    ENDIF
    
    if onmarket and PREZZOUSCITA>0 then
       EXITSHORT AT PREZZOUSCITA STOP
       SELL AT PREZZOUSCITA STOP
    ENDIF
    #84234 quote

    Grazie Roberto nel momento che ho inviato il messaggio ci avevo pensato…. Scusa se non ho inserito PRT code ma non ci ho pensato….

    Grazie ancora
    Mauro

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Trailing Stop


ProOrder: Trading Automatico & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by Mauro T. “Algorithm System”
7 years, 3 months ago.

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