Aiuto con definizione Stop Loss

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #37214 quote
    Giggetto82
    Participant
    New

    Buongiorno a tutti,

    sono nuovo del forum, quindi anzitutto complimenti per il lavoro che fate qui, è già da qualche settimana che vi leggo e ho trovato diversi spunti interessanti per le mie piccole programmazioni in ProReal.

    Avrei bisogno di supporto per la creazione di un doppio stop su un sistema che sto testando. Mi spiego meglio, il sistema sfrutta le inversioni di mercato quindi oltre ad uno stop in pips, vorrei che il sistema chiudesse l’operazione se la candela di apertura non va in direzione del trade (anche se non ha ancora raggiunto lo stoploss). Spero di essermi espresso correttamente.

    Vi metto di seguito l’intero codice, così forse rendo più chiare le cose…

    Defparam cumulateorders = false
    
    DEFPARAM FLATBEFORE = 090000
    DEFPARAM FLATAFTER = 110000
    
    //Vincolo di ritracciamento al 50% del movimento iniziale
    SetupRangeLong= (open[3]- close[1])*0.5
    MyRangeLong= close-open
    
    IF MyRangeLong>= SetupRangeLong then
    allowtradelong= 0
    endif
    
    if MyRangeLong<= SetupRangeLong then
    allowtradelong= 1
    endif
    
    SetupRangeShort= (close[1]- open[3])*0.5
    MyRangeShort= open-close
    
    IF MyRangeShort>= SetupRangeShort then
    allowtradeshort= 0
    endif
    
    if MyRangeShort<= SetupRangeShort then
    allowtradeshort= 1
    endif
    //fine
    
    // REV4B long
    ca1 = close > open and close[1] < open[1] and close[2] < open[2] and close[3] < open[3]
    ca2 = LOW[1]< LOW[2] AND LOW[2]< LOW[3]
    
    IF NOT ONMARKET AND ca1 AND ca2 and allowtradelong= 1 THEN
    Buy at market nextbaropen
    ENDIF
    
    // Rev4B Short
    cv1 = close < open and close[1] > open[1] and close[2] > open[2] and close[3] > open[3]
    cv2 = HIGH[1]> HIGH[2] AND HIGH[2]> HIGH[3]
    
    IF NOT ONMARKET AND cv1 AND cv2 and allowtradeshort= 1 THEN
    sellshort at market nextbaropen
    ENDIF
    
    // Stop e target in pips
    SET STOP pLOSS 10
    SET TARGET pPROFIT 10

    Grazie in anticipo a chiunque riesca a darmi una mano!

    #37243 quote
    robertogozzi
    Moderator
    Master

    Penso questa versione modificata possa andare bene, io l’ho provata solo per evitare errori di scrittura.

    Ho modificato le tue righe 10-16 e 21-27 con una semplice espressione.

    Ho pure tolto alla linee 34 e 42 la verifica ONMARKET perché avendo richiesti di non effettuare più di un trade, all’inizio, sono superflue:

    Defparam cumulateorders = false
    DEFPARAM FLATBEFORE     = 090000
    DEFPARAM FLATAFTER      = 110000
    //Vincolo di ritracciamento al 50% del movimento iniziale   -  LONG
    SetupRangeLong= (open[3]- close[1])*0.5
    MyRangeLong = close-open
    //IF MyRangeLong>= SetupRangeLong then
    //allowtradelong= 0
    //endif
    //if MyRangeLong<= SetupRangeLong then
    //allowtradelong= 1
    //endif
    allowtradelong = (MyRangeLong <= SetupRangeLong)                      //allowtradelong = 0 if false, 1 if true
    //Vincolo di ritracciamento al 50% del movimento iniziale   -  SHORT
    SetupRangeShort= (close[1]- open[3])*0.5
    MyRangeShort= open-close
    //IF MyRangeShort>= SetupRangeShort then
    //allowtradeshort= 0
    //endif
    //if MyRangeShort<= SetupRangeShort then
    //allowtradeshort= 1
    //endif
    allowtradeshort = (MyRangeShort <= SetupRangeShort)                  //allowtradeshort = 0 if false, 1 if true
    //fine
    // REV4B long
    ca1 = close > open and close[1] < open[1] and close[2] < open[2] and close[3] < open[3]
    ca2 = LOW[1]< LOW[2] AND LOW[2]< LOW[3]
    IF ca1 AND ca2 and allowtradelong = 1 THEN
    Buy at market nextbaropen
    ENDIF
    // Rev4B Short
    cv1 = close < open and close[1] > open[1] and close[2] > open[2] and close[3] > open[3]
    cv2 = HIGH[1]> HIGH[2] AND HIGH[2]> HIGH[3]
    IF cv1 AND cv2 and allowtradeshort= 1 THEN
    sellshort at market nextbaropen
    ENDIF
    // ------ close positions when conditions reverse
    IF LongOnMarket THEN
    IF (NOT ca1) OR (NOT ca2) THEN
    Sell at market                              //close LONG  trades before SL is triggered
    ENDIF
    ENDIF
    IF ShortOnMarket THEN
    IF (NOT cv1) OR (NOT cv2) THEN                 //close SHORT trades before SL is triggered
    Exitshort at market
    ENDIF
    ENDIF
    // Stop e target in pips
    SET STOP   pLOSS   10
    SET TARGET pPROFIT 10
    
    #37451 quote
    Giggetto82
    Participant
    New

    Ciao Robertogozzi,

    grazie per la risposta!

    Testo subito le modifiche che mi hai indicato e ti faccio sapere.

     

    Grazie ancora!

    #37456 quote
    Giggetto82
    Participant
    New

    Ciao Robertogozzi, le modifiche che mi hai indicato funzionano alla perfezione! Ti ringrazio moltissimo!

    Scusami se approfitto, ma visto che sto testando questo sistema anche in multiday (con le relative modifiche) e sto trovando difficoltà a impostare il divieto di apertura la domenica, possiamo parlarne qui o devo aprire un altro topic?

     

    Grazie ancora e buona giornata!

    #37473 quote
    robertogozzi
    Moderator
    Master

    Puoi visitare https://www.prorealcode.com/documentation/dayofweek/, anche se non indica il numero dei giorni restituiti, che è:

    1 = lunedì
    2 = martedì
    3 = mercoledì
    4 = giovedì
    5 = venerdì

    Non so se:
    6 = sabato
    7 = domenica

    Perché ho provato a crere un indicatore con la semplice riga:

    return DayOfWeek

    ma ottengo risultati strani.

    Ad ogni modo puoi testare che

    DayOfWeek

    sia maggiore di 5 per saltare il fine settimana.

    Per gli orari, puoi usare le altre funzioni apposite oppure per essere certi che nessuna operazione (anche in presenza di condizioni soddisfatte)  inizi prima di un certo orario o/e sia sempre chiusa ad un certo orario puoi utilizzare, all’inizio della strategia:

    DFEPARAM FlatBefore = 070000 //non aprire operazioni  prima delle 07:00:00
    DEFPARAM FlatAfter  = 230000 //chiudi ogni operazione aperta alle 23:00:00

    La documentazione PRT non è molto esaustiva, ma puoi utilizzare l’apposito strumento Google Search sulla barra in alto per trovare esempi, informazioni ecc… Buon trading.

    #37474 quote
    robertogozzi
    Moderator
    Master

    Scusa, sopra la riga 1 è errata, quella corretta è:

    DEFPARAM FlatBefore = 070000 //non aprire operazioni  prima delle 07:00:00

    Ciao.

    #37486 quote
    Giggetto82
    Participant
    New

    Ci lavoro subito!

     

    Grazie ancora!

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

Aiuto con definizione Stop Loss


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Giggetto82 @giggetto82 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Giggetto82
8 years, 8 months ago.

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