DAX CASH 2H

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #55805 quote
    Gianluca
    Participant
    Master
    //-------------------------------------------------------------------------
    // Codice principale : Dax Cash 2h V2(1)
    //-------------------------------------------------------------------------
    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 080000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER = 200000
    // Impedisce al sistema di tradare in giorni specifici della settimana
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Position size module, 2 is the default. Can be adapted to scale with the profits
    positionsize=3//+2*round((strategyprofit*2)/10000)
    maybe= positionperf(1)<0
    losses = positionperf(1)<0 and positionperf(2)<0
    
    if losses then
    PositionSize  = 4//+3*round((strategyprofit*2)/10000)
    elsif not losses then
    PositionSize  = 3//+2*round((strategyprofit*2)/10000)
    Endif
    if maybe and not losses then
    positionsize=4//+3*round((strategyprofit*2)/10000)
    endif
    if positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0 then
    positionSize=3//+2*round((strategyprofit*2)/10000)
    endif
    if positionperf(1)>0 and positionperf(2)>0 then
    positionsize=2//+1*round((strategyprofit*2)/10000)
    endif
    
    if positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0 and positionperf(4)<0 and positionperf(5)<0 and positionperf(6)<0 then
    positionsize=6
    endif
    
    if positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0 and positionperf(4)>0 and positionperf(5)>0 and positionperf(6)>0 then
    positionsize=1
    endif
    //////////////////////////////////////////////////////
    
    // Condizioni per entrare su posizioni long
    if not onmarket then
    indicator11 = Average[21](close)
    c11 = (close CROSSES over indicator11)
    indicator21 = Stochastic[34,34](close)
    indicator31 = Average[14](indicator21)
    c21 = (indicator21 >= indicator31)
    indicator41 = AverageTrueRange[14](close)
    c31 = (indicator41 >= 25)
    indicator51 = AverageTrueRange[14](close)
    indicator61 = ExponentialAverage[50](AverageTrueRange[14](close))
    c41 = (indicator51 >= indicator61)
    
    IF c11 AND c21 AND c41 AND C31 and not daysForbiddenEntry THEN
    buy positionsize SHARES AT MARKET
    ENDIF
    endif
    // Condizioni per uscire da posizioni long
    indicator111 = ExponentialAverage[7](close)[1]
    exitlong = (close CROSSES UNDER indicator111[4])
    IF exitlong THEN
    sell AT MARKET
    ENDIF
    
    
    // Condizioni per entrare su posizioni short
    if not onmarket then
    indicator1 = Average[21](close)
    c1 = (close CROSSES UNDER indicator1)
    indicator2 = Stochastic[34,34](close)
    indicator3 = Average[14](indicator2)
    c2 = (indicator2 <= indicator3)
    indicator4 = AverageTrueRange[14](close)
    c3 = (indicator4 >= 25)
    indicator5 = AverageTrueRange[14](close)
    indicator6 = ExponentialAverage[50](AverageTrueRange[14](close))
    c4 = (indicator5 >= indicator6)
    
    IF c1 AND c2 AND c4 AND C3 and not daysForbiddenEntry THEN
    SELLSHORT positionsize SHARES AT MARKET
    ENDIF
    endif
    
    // Condizioni per uscire da posizioni short
    indicator111 = ExponentialAverage[7](close)[12]
    exitsho = (close CROSSES OVER indicator111[30])
    IF exitsho THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop e target
    set stop ploss 150
    set target pprofit 230
    
    //************************************************************************
    //trailing stop function
    trailingstart = 55 //trailing will start @trailinstart points profit
    trailingstep = 55 //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
    //************************************************************************
    // Sell at end of day
    if time>215300 then
    exitshort at market
    sell at market
    endif
    // Earlier friday exit. Insurance against accidental holding over weekends
    if dayofweek=5 and time>212300 then
    exitshort at market
    sell at market
    endif
    

    Ciao a tutti, spero possiate darmi suggerimenti ed aiutarmi ad ottimizzare questo trading system, è uno dei primi che provo a fare, ho anche tagliuzzato qualche funzione qua e la da altri trading system presenti sul sito.

    Il Ts è ottimizzato volutamente per fare poche operazioni cercando di minimizzare i downtrend

    #55837 quote
    Gianluca
    Participant
    Master

    @robertogozzi che ne pensi?

    #55838 quote
    Gianluca
    Participant
    Master
    #55839 quote
    robertogozzi
    Moderator
    Master

    Fino a lunedì tardo pomeriggio non ho possibilità di provarla.

    Gianluca thanked this post
    #56007 quote
    robertogozzi
    Moderator
    Master
    Su quale TF lo usi, nel codice c’è scritto 2h (2 ore), ma a me sembra potrebbe risultare qualòche profitto su h1. Dall’esame dei tuoi IF per farlo uscire la sera sembra tu utilizzi i minuti!? Ad ogni modo le righe 136-145 sono inutili, tanto ci pensa la riga 9 a terminare le operazioni all’ora li indicata.
    #56016 quote
    Gianluca
    Participant
    Master
    Il TF è 2h, ma funziona bene anche su 1h, sempre in backtest, ho aggiunto le righe 136-145 perchè mi è capitato in real che non chiudesse le operazioni! infatti non so se ricordi ho aperto un post un paio di giorni fa su questo problema.
    #56082 quote
    Gianluca
    Participant
    Master
    @Ale che ne dici? potete darmi una mano?
    #56132 quote
    robertogozzi
    Moderator
    Master
    Posso darti consigli sul codice, ad esempio la riga
    Stochastic[34,34](close)
    è ripetuta più volte, come altre del resto, dovresti metterla una sola volta ed usare sempre quella stessa variabile per farvi riferimento. In questo modo quando vorrai provare settaggi diversi li dovrai cambiare su una sola riga! Inoltre, specialmente quanto le righe di codice aumentano, è opportuno usare nomi significativi, non C1 o C11 o INDICATOR1 o INDICATOR21 ecc… (il facilitatore fa così per semplicità, poi ognuno deve adattare il codice a se stesso) ma un nome che indichi a cosa serve, ad esempio la riga
    indicator11 = Average[21](close)
    sarebbe più comprensibile per chiunque se fosse
    Media21 = Average[21](close)
    oppure, se è la media più veloce nel tuo codice
    MediaVeloce = Average[21](close)
    Alla riga 60 calcoli una media esponenziale a 7 periodi sulla chiusura della barra precedente, può andare bene, è un metodo per shiftare di una posizione orizzontale. La riga 86 fa lo stesso, ma con uno scostamento di 12 barre, mi pare un pò eccessivo, è un effetto voluto o è un errore di codifica? La riga 87 testa la condizione di uscita sull’incrocio della media di cui sopra (già spostata di 12), tra il prezzo di chiusura corrente e quello di 30 (+12) barre prima! Anche questo è incomprensibile; a meno che non sia parte di una strategia ben precisa mi sembra un errore. In conclusione, per poterti aiutare (non solo io, ma chiunque, anzi, man mano che ognuno progredisce è caldamente incoraggiato ad aiutare i meno esperti) devi dare un’indicazione dettagliate su cosa vuoi, su quale strumento e TF desideri operare. E’ ovvio che l’aiuto, quando viene dato, non è detto che sia immediato, magari può capitare che qualcuno che ti ha dato suggerimenti possa essere occupaato per una giornata o più, magari andare in vacanza ecc… occorre pazienza. Attendo tue precisazioni. Roberto
    #56140 quote
    Gianluca
    Participant
    Master
    Grazie mille Roberto, sono tutte condizioni volete, nel pomeriggio lo riscrivo e spiegherò ogni singolo passaggio così potremo lavorarci meglio, grazie per la comprensione 🙂
    #57576 quote
    Gianluca
    Participant
    Master
    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate
    DEFPARAM FLATBEFORE = 090000
    DEFPARAM FLATAFTER = 210000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    // Position size module
    positionsize=1
    //Indicatori//
    mm21= Average[21](close)
    stoc34 = Stochastic[34,34](close)
    mmstoc = Average[14](stoc34)
    atr= AverageTrueRange[14](close)
    emaatr = ExponentialAverage[50](AverageTrueRange[14](close))
    ema7 = ExponentialAverage[7](close)[1]
    ema7short = ExponentialAverage[7](close)[12]
    //Condizioni entrata long
    c1= (close CROSSES over mm21)
    c2 = (stoc34 >= mmstoc)
    c3 = (atr >= 25)
    c4 = (atr >= emaatr)
    oklong = (c1 and c2 and c3 and c4)
    //uscitalong
    exitlong = (close CROSSES UNDER ema7[4])
    
    // LONG POSITION
    if oklong and not daysForbiddenEntry THEN
    buy positionsize SHARES AT MARKET
    set stop ploss 50
    set target pprofit 225
    ENDIF
    // EXIT LONG
    IF exitlong THEN
    sell AT MARKET
    ENDIF
    
    //CONDIZIONI ENTRATA SHORT
    S1 = (close CROSSES UNDER mm21)
    S2 = (STOC34 <= MMSTOC)
    S3 = (ATR >= 25)
    S4 = (ATR >= EMAATR)
    okshort = (s1 and s2 and s3 and s4)
    exitsho = (close CROSSES OVER ema7short[30])
    // Condizioni per entrare su posizioni short
    if okshort and not daysForbiddenEntry THEN
    SELLSHORT positionsize SHARES AT MARKET
    // Stop e target
    set stop ploss 150
    set target pprofit 230
    ENDIF
    
    // Condizioni per uscire da posizioni short
    IF exitsho THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop e target
    //************************************************************************
    //trailing stop function
    trailingstart = 70 //trailing will start @trailinstart points profit
    trailingstep = 20 //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
    
    Ciao @Robertogozzi l’ho riscritto, ma riguardandolo sono molto deluso perchè è come se avesse guadagnato solo nel 2015-2016 e da un anno e mezzo è praticamente fermo il TS quindi l’ho quasi accantonato, posso chiederti una cosa riguardo le ottimizzazioni? Sto cominciando a pensare che converrebbe lanciare ed ottimizzare i sistemi di 6 mesi in 6 mesi o al massimo 18 mesi, senza andare troppo indietro, perchè c’e’ sempre il rischio che ne esca una sistema che lavora bene in alcune fasi di mercato e non in quelle attuali. Nel sistema ho inserito molti filtri per evitare operazioni in perdita dato che non ho grossi capitali qualsiasi perdita per me è pesante, ma da ciò ne e’ uscito un TS che non performa bene negli ultimi 16 mesi.
    #58684 quote
    robertogozzi
    Moderator
    Master
    L’ho provato, così come l’hai pubblicato senza modifiche,  sul DAX ed ho visto che i migliori risultati si ottengono su H4. Una verifica potresti farla anche sugli orari, magari in certe fasce orarie lavora meglio. Addirittura potresti provare ad abbinare le fasce orarie ai giorni, chissà che il lunedì mattina non sia meglio farlo partire dalle, dico a caso, 14, o magari terminarlo il venerdì poimeriggio alla 12, ecc… sono tutte prove da fare a cui dedidarci ore e ti aiuta anche ad apprendere meglio la codifica. Ad ogni modo, puoi anche lasciare il backtest per tutto il periodo, ma rieseguirlo bene ogni mese per aggiustare qualche parametro e renderlo adeguato al momento attuale, oppure, come hai detto tu, ridurre il backtest all’ultimo anno o due. Serve tempo da dedicarci e molta pazienza.
    #58766 quote
    Gianluca
    Participant
    Master
    Mi sembra strano quello che dici riguardo il TF migliore, io ho questo backtest sul 2h
    #58774 quote
    robertogozzi
    Moderator
    Master
    Non so cosa dirti, ho riprovato ed ottengo gli stessi risultati di prima.
Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

DAX CASH 2H


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Gianluca @altares Participant
Summary

This topic contains 12 replies,
has 2 voices, and was last updated by robertogozzi
8 years ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 12/16/2017
Status: Active
Attachments: 4 files
Logo Logo
Loading...