Pattern di Gramza

Viewing 15 posts - 16 through 30 (of 54 total)
  • Author
    Posts
  • #44637 quote
    Nicolas
    Keymaster
    Master

    Congratulazioni per tutto questo lavoro che hai fatto qui! Grazie mille Roberto! 😉

    #44645 quote
    robertogozzi
    Moderator
    Master

    Grazie Nicolas, mi piace aiutare qualcuno quando mi è possibile, anch’io a volte ho bisogno d’aiuto, specialmente agli inizi ne ho avuto tanto!!!

    #44646 quote
    robertogozzi
    Moderator
    Master

    Scusami R05, al post #44632 ho indicato erroneamente “ed indichi 60 nelle parentesi”, mentre era corretto scrivere “ed indichi 540 nelle parentesi”.

    #44647 quote
    R05
    Participant
    Veteran

    Ok grande grazie, gentilissimo. In questo fine settimana potrò approfondire e fare un pò di backtest.

    #44652 quote
    robertogozzi
    Moderator
    Master

    Scusami ancora, ma ho trovato nel mio codice un errore logico, perché

    highest[540](high)

    alle 090000 mi restituisce il valore più alto della candela delle 000001 (se siamo sul TF a 1 minuto), NON il massimo di ieri. Per avere il massimo occorrerebbe scrivere

    x   = highest[1440](high) //in 24 ore ci sono 1440 minuti
    Max = x[540]              //Max conterrà il valore di cui sopra spostato indietro alla mezzzanotte (se siamo alle 090000)

    ma è un meccanismo un pò complicato ed inoltre durante il giorno il valore 540 andrà variato ad ogni candela che passa (inoltre IG considera il nuovo giorno a partire dalle 010000)!!!

    C’è la soluzione più facile ed ovvia, cui non avevo pensato, che è di usare DHIGH e DLOW (vedi https://www.prorealcode.com/documentation/dhigh/):

    Max = Dhigh(0) //0 per la barra appena chiusa (la corrente), 1 per quella del giorno precedente e così via...
    Min = Dlow(0)

    ch restituiscono i valori Minimi e Massimi del giorno.

    Buon fine settimana.

    #45053 quote
    R05
    Participant
    Veteran

    Gent.mo Roberto, riguardo il pattern di Gramza, dopo aver fatto le opportune verifiche con più calma, devo anzitutto scusarmi con te in quanto il primo codice che avevi riportato sullo stop e sul trailing stop erano corretti. Sbagliavo io: troppo frettoloso e poco capace. E quindi ti ringrazio tantissimo.

    Ora il secondo passo è cercare di vedere se può essere migliorato ulteriormente aggiungendo dei filtri, tipo entrare in posizione se il pattern si verifica in presenza di un max o min del giorno fatto a quel momento o anche se supera la banda inferiore o superiore di Bollinger o anche fermare il sistema nel momenti della giornata poco movimentati tipo dalle 11:30-12:00 alle 14:30-15:00. Mi piace cercare di entrare il più possibile vicino ai massimi o minimi per avere bassi stop e in teoria alti profitti (in trailing stop). Speriamo che prorealtime implementi subito la possibilità anche di poter entrare nella stessa barra in cui si verifica il setup in modo anche da poter sfruttare il turtle soup o le sue varianti.

    Allego la versione del codice (ho solo apportato piccole modifiche tipo nel trailing stop ho messo esplicitamente 2 altrimenti non mi metteva lo stop sotto o sopra 2 punti il min o max, e poi occorre aggiungere, come dicevi tu, pipsize per il forex).

    Grande. E grazie di nuovo.

    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    defparam flatbefore = 080000
    defparam flatafter = 220000
    
    Hammer = Close<Open AND (close-Low) >= 2*(Open-Close)
    Hammer2 = Close>Open AND (high-close) >= 2*(Close-Open)
    ShootingStar = close>open and (high-close)>=2*(close-open)
    ShootingStar2 = close<open and (close-low)>=2*(open-close)
    Candelarossa = (open>close)
    Candelaverde = (open<close)
    
    s = high
    t = high[1]
    z = high[2]
    
    // Condizioni per entrare su posizioni long
    IF NOT OnMarket and s<t and t<z and (hammer or hammer2 or ShootingStar or ShootingStar2 or candelaverde) THEN
    buy 1 CONTRACTS at high+1 stop
    ENDIF
    
    s = low
    t = low[1]
    z = low[2]
     
    // Condizioni per entrare su posizioni short
    IF NOT OnMarket and s>t and t>z and (hammer or hammer2 or ShootingStar or ShootingStar2 or candelarossa) THEN
    sellshort 1 CONTRACTS at low-1 stop
    ENDIF
    
    // Stop e target
    
    IF close > open THEN               //LONG
    MinLow   = low
    StopLoss = low - 2  //2 pips sotto il minimo
    ELSE                               //SHORT
    MaxHigh  = high
    StopLoss = high + 2 //2 pips sopra il massimo
    ENDIF
    
    
    SET STOP PLOSS StopLoss
    
    
    IF LongOnMarket THEN         //per i LONG
    IF low > MinLow THEN      //verificare che sia un MINIMO più alto
    MinLow = Low           //aggiornare la variabile
    ENDIF
    SELL AT MinLow - 2 STOP       //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    IF ShortOnMarket THEN        //per gli SHORT
    IF high < MaxHigh THEN    //verificare che sia un MASSIMO più basso
    MaxHigh = high         //aggiornare la variabile
    ENDIF
    EXITSHORT AT MaxHigh + 2 STOP //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    
    #45070 quote
    robertogozzi
    Moderator
    Master

    Ho modificato il codice:

    DEFPARAM CumulateOrders     = False
    defparam flatbefore         = 080000
    defparam flatafter          = 220000
    
    ONCE TimeLimit              = 180000          //Nessun nuovo TRADE dopo le 18:00:00
    ONCE TimeFriday             = 140000          //Nessun trade DOPO le 14 del Venerdì
    ONCE TimeMonday             = 123000          //Nessun trade PRIMA delle 103000 di Lunedì
    ONCE TimeOff                = 123000          //Inizio pausa pranzo, nessun trade
    ONCE TimeOn                 = 133000          //Fine pausa pranzo, ricominciare a tradare
    
    //***************************************************************************
    TimeFlag = 1
    IF time > TimeLimit THEN
    TimeFlag = 0
    ENDIF
    IF (CurrentDayOfWeek = 5) THEN                       //5 = Venerdi
    IF time >= TimeFriday THEN
    TimeFlag = 0
    ENDIF
    ELSIF (CurrentDayOfWeek = 1) THEN                    //1 = Lunedì
    IF time < TimeMonday THEN
    TimeFlag = 0
    ENDIF
    ELSIF (time > TimeOff) AND (time < TimeOn) THEN      //nessun trade in pausa pranzo
    TimeFlag = 0
    ENDIF
    //TimeFlag = 1
    //***************************************************************************
    //     trailing stop function
    trailingstart = 3     //3    trailing will start @trailinstart points profit
    trailingstep  = 27    //27   trailing step to move the "stoploss"
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*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>=trailingstart*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
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
    
    Hammer        = Close<Open AND (close-Low) >= 2*(Open-Close)
    Hammer2       = Close>Open AND (high-close) >= 2*(Close-Open)
    ShootingStar  = close>open and (high-close)>=2*(close-open)
    ShootingStar2 = close<open and (close-low)>=2*(open-close)
    Candelarossa  = (open>close)
    Candelaverde  = (open<close)
     
    s = high
    t = high[1]
    z = high[2]
     
    // Condizioni per entrare su posizioni long
    IF NOT OnMarket and s<t and t<z and (hammer or hammer2 or ShootingStar or ShootingStar2 or candelaverde) and TimeFlag THEN
    buy 1 CONTRACTS at high+1 stop
    ENDIF
     
    s = low
    t = low[1]
    z = low[2]
     
    // Condizioni per entrare su posizioni short
    IF NOT OnMarket and s>t and t>z and (hammer or hammer2 or ShootingStar or ShootingStar2 or candelarossa) and TimeFlag THEN
    sellshort 1 CONTRACTS at low-1 stop
    ENDIF
     
    // Stop e target
     
    IF close > open THEN               //LONG
    MinLow   = low
    StopLoss = low - 2  //2 pips sotto il minimo
    ELSE                               //SHORT
    MaxHigh  = high
    StopLoss = high + 2 //2 pips sopra il massimo
    ENDIF
     
     
    SET STOP PLOSS StopLoss
     
     
    IF LongOnMarket THEN         //per i LONG
    IF low > MinLow THEN      //verificare che sia un MINIMO più alto
    MinLow = Low           //aggiornare la variabile
    ENDIF
    SELL AT MinLow - 2 STOP       //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    IF ShortOnMarket THEN        //per gli SHORT
    IF high < MaxHigh THEN    //verificare che sia un MASSIMO più basso
    MaxHigh = high         //aggiornare la variabile
    ENDIF
    EXITSHORT AT MaxHigh + 2 STOP //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    
    #45071 quote
    robertogozzi
    Moderator
    Master

    Le lineee 5-27 servono a selezionare certi orari, ad esempio l’inizio del lunedì mattina, la chiusura del venerdì pomeriggio e la pausa pranzo; ma si possono diversificare ulteriormente, ovviamente.

    Basta mettere, come ho messo, alle linee 77 e 86 la variabile TIMEFLAG ed eventualmente modificare/aggiungere altri orari alle righe 5-9.

    Vi sono poi le righe 29-62 che sono un codice per gestire il TRAILING STOP, indicando da quanti pips partire e di quanto incrementare lo stop. E’ un codice sviluppato da Nicolas, che lo ha messo a disposizione qui: https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    Buon trading.

    #45305 quote
    R05
    Participant
    Veteran

    Gentilissimo Roberto, ti disturbo riguardo al seguente codice che è una variante del turtle soup, dove si entra in posizione se il prezzo di chiusura è sotto il minimo/sopra il Massimo del minimo/max precedente a 20 periodi, e quindi si piazza un ordine alla candela successiva qualora il prezzo superi il min/max precedente. Ma come faccio ad impostare che il max/min precedente deve essere più di tre barre prima?

    Ti ringrazio.

    DEFPARAM CumulateOrders = False
     
    n = 1
     
    // Condizioni per aprire una posizione long
    c1 = close < lowest[20](low)[1]
    ctime = time > 060000 and time < 220000
     
    IF c1 AND ctime THEN
    BUY n CONTRACT AT lowest[20](low)[1] + 1 stop
    ENDIF
     
    // Condizioni per uscire da una posizione long
    c2 = low < lowest[5](low)[1]
     
    IF c2 THEN
    sell AT MARKET
    ENDIF
    
    // Condizioni per aprire una posizione short
    c1 = close > highest[20](high)[1]
    ctime = time > 060000 and time < 220000
     
    IF c1 AND ctime THEN
    SELLSHORT n CONTRACT AT highest[20](high)[1] - 1 stop
    ENDIF
    
    // Condizioni per uscire da una posizione di vendita
    c3 = high > highest[5](high)[1]
     
    IF c3 THEN
    exitshort AT MARKET
    ENDIF
    
    // Stop e target
    
    IF close > open THEN               //LONG
    MinLow   = low
    StopLoss = low - 2  //2 pips sotto il minimo
    ELSE                               //SHORT
    MaxHigh  = high
    StopLoss = high + 2 //2 pips sopra il massimo
    ENDIF
    
    
    SET STOP PLOSS StopLoss
    
    
    IF LongOnMarket THEN         //per i LONG
    IF low > MinLow THEN      //verificare che sia un MINIMO più alto
    MinLow = Low           //aggiornare la variabile
    ENDIF
    SELL AT MinLow - 2 STOP       //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    IF ShortOnMarket THEN        //per gli SHORT
    IF high < MaxHigh THEN    //verificare che sia un MASSIMO più basso
    MaxHigh = high         //aggiornare la variabile
    ENDIF
    EXITSHORT AT MaxHigh + 2 STOP //aggiornare l'ordine di STOP ad ogni candela
    ENDIF
    
    #45336 quote
    robertogozzi
    Moderator
    Master

    Con

    c1 = close < lowest[20](low)[1]

    verifichi il valore più basso (o alto con HIGHEST) di 20 barre indietro, iniziando non da quella corrente, ma dalla precedente.

    basta fare una somma della condizione per le ultime, ad esmpio, 4 barre:

    c1 = summation[4](close < lowest[20](low))
    //         oppure (come fatto tu)
    c1 = summation[4](close < lowest[20](low)[1])

    se c1 conterrà 0 significa che per tutte e 4 le barre precedenti la condizione non era verificata (quindi l’evento si è verificato prima delle 4 barre).

    #45337 quote
    R05
    Participant
    Veteran

    Dovrei aver trovato il codice. Lo riporto. Sembra funzionare.

     

    DEFPARAM CumulateOrders = False
     
    n = 1
    
    t = low[1]
    v = low[2]
    y = low[3]
    z = low[4]
     
    // Condizioni per aprire una posizione long
    c1 = low < lowest[20](low)[1]
    ctime = time > 060000 and time < 220000
    
    IF c1 AND ctime and t>z and v>z and y>z THEN
    BUY n CONTRACT AT lowest[20](low)[1] + 1 stop
    ENDIF
     
    // Condizioni per uscire da una posizione long
    c2 = low < lowest[5](low)[1]
     
    IF c2 THEN
    sell AT MARKET
    ENDIF
    
    // Condizioni per aprire una posizione short
    
    t1 = high[1]
    v1 = high[2]
    y1 = high[3]
    z1 = high[4]
    c1 = high > highest[20](high)[1]
    ctime = time > 060000 and time < 220000
     
    IF c1 AND ctime and t1<z1 and v1<z1 and y1<z1 THEN
    SELLSHORT n CONTRACT AT highest[20](high)[1] - 1 stop
    ENDIF
    
    // Condizioni per uscire da una posizione di vendita
    c3 = high > highest[5](high)[1]
     
    IF c3 THEN
    exitshort AT MARKET
    ENDIF
    
    set target pprofit 10
    
    #45338 quote
    robertogozzi
    Moderator
    Master

    Hai scritto tu il posta contemporaneamente a me.

    #45339 quote
    robertogozzi
    Moderator
    Master

    Il tuo sistema dovrebbe funzionare, con il mio è più semplice aumentare o dominuire le barre a 3 o 5, semplicemente cambiando il numero tra le parentesi quadre di SUMMATION.

    #45340 quote
    R05
    Participant
    Veteran

    Si infatti. Grazie comunque Roberto. Gentilissimo.

    #45341 quote
    R05
    Participant
    Veteran

    Si nel mio codice da togliere il target profit e rimettere il trailing stop. Facendo le prove ho copiato quello senza trailing.

Viewing 15 posts - 16 through 30 (of 54 total)
  • You must be logged in to reply to this topic.

Pattern di Gramza


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
R05 @r05 Participant
Summary

This topic contains 53 replies,
has 5 voices, and was last updated by volpiemanuele
7 years, 7 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 08/21/2017
Status: Active
Attachments: 7 files
Logo Logo
Loading...