Hello everyone,
I have the pleasure to share with you this simple but practical, universal daily strategy (for Forex, Indices, and Stocks), optimized on the CAC from 1992 to today. I hope that this opensource contribution can bring more developments in the field of automatic trading strategies on prorealtime, and demonstrate once and for all that a strategy to work does not necessarily have to be complicated, indeed (as I see it) the simpler it is, the more likely it is to work in the future as in the past.
- Brief explanation
The strategy has 3 fundamental parameters to optimize primarily which are: Period, Mode, and invertsignal. Once these have been chosen, we move on to the optimization of the two filters: filter1 and filter2. Finally, if you want you can add, a stop loss based on the average true average.
Here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
//Universal XBody STrategy // instrument: CAC40 // timeframe : Daily // Spread: 4 // created and coded by davidelaferla //————————————————————————- //------------------------------------------------------------------------- defparam cumulateorders=false //*********************************************************************************************************** N = 1 //------------------ SYSTEM VARIABLES--------------------------------------- //CAC40 Values: -------------------------------------------- Ottimization info period=978// Optimize best value for each Symbol, range=1-1000, with step=1 mode=1// Optimize the best trading mode , range=1-4, with step=1 invertsignal=1// 1=positive signal, -1=negative signal, range=-1-1, with step=2 //*********************************************************************************************** //------------------ SYSTEM FILTER--------------------------------------- filter1=51// to set after the variable optimization, range=1-100, with step=1 filter2=0// to set after the variable optimization, range=1-100, with step=1 //------------------ INDICATOR --------------------------------------- body=close-open var=(body-body[1]) sumvar=summation[period](var) if sumvar>filter1*pipsize then green=(sumvar) endif if sumvar<-filter2*pipsize then red=(sumvar) endif if mode=1 then c1=red<red[1] c2=green>green[1] endif if mode=2 then c1=red>red[1] c2=green<green[1] endif if mode=3 then c1=red<red[1] c2=green<green[1] endif if mode=4 then c1=red>red[1] c2=green>green[1] endif if c1 then signal=1*invertsignal elsif c2 then signal=-1*invertsignal endif // Conditions for entering long positions and exit short positions IF signal>0 then BUY n contract AT market ENDIF // Conditions for entering short positions and exit long positions IF signal<0 THEN SELLSHORT n CONTRACTs AT market ENDIF |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hello David, thanks for sharing this strategy that gives good results for many different instrument types.
A couple of questions if you don’t mind.
The range of Filter2 is from 1-100 but the value is 0.
Are you trading this strategy live? I’m asking as it is always on the market, the number of trades is important. With the slippage in real trading, I wonder if the results are close from the backtests.
Talking backtests, I tried various trailing strategies but have not found a good one yet. Have you?
If you are trading it live, are you using the parameters optimized on the whole time? I’m asking because when I try various walk-forward optimizations the results are not as good.
Hello Lavalette! The filter interval starts from 0, and not from 1, in fact when period and mode are optimized, it must remain 0. I trade with this strategy in real and I’m not finding substantial differences with the backtest at least in this or higher timeframes of the daily . I mostly don’t use trailing, as I wrote in the post it is better to use a simple stop loss. I always use the optimized parameters especially when they work in many years of backtesting at least 10-15 years, and return a graphically constant equity.
The most interesting finding about this strategy is that natural selection of the best parameters is observed over time, so that after a sufficiently long time the best parameter stabilizes.
Ciao David, sto provando il tuo ottimo codice sulla coppia EUR/USD TF un giorno test esteso a 10 anni e i risultati sembrano buoni (allego foto), ma nell’ottimizzare facendo come dici tu , il valore del filtro 2 che dovrebbe essere 0 , mi da invece 28. Non ho cambiato nulla, ho solo aggiunto un SL e TP che lavorano sull’ATR.
Ciao Franco! Non riesco a vedere la foto allegata (è meglio se me la mandi tramite link) . Il valore del filtro 1 e del filtro 2 , devono rimanere a 0 solo durante l’ottimizzazione del period e del mode, infatti sono solo un perfezionamento della strategia e quindi vanno ottimizzati dopo. E’ normale che il valore del filtro 2 ottimizzato dia un valore diverso da zero, nel tuo caso 28.
Grazie per la risposta, non riesco (o non sono capace) a mandarti il link , comunque farò come dici tu per l’ottimizzazione. Sto continuando a provare in demo, da dei buoni risultati, ma se l’entrata è sbagliata, il loss funziona solo a fine giornata ed è un guaio, si può ovviare?
Grazie
Lo Stop loss, come anche il target profit, essendo funzioni native di prorealtime, funzionano in tempo reale e non solo a fine giornata. Chiaramente lo stop loss, può essere eseguito una sola volta a candela , e non deve interferire con il target profit, quindi controlla bene che la modalità tick per tick ti risulti 0, o comunque un numero molto basso in confronto al numero totale dei trade. Ti saluto e ti auguro profitti costanti.
Hai ragione, mi dava valori alti perchè usavo questo loss “SET STP LOSS 1xAverageTrueRange{10} (close)”, ho provato a mettere un un semplice loss in punti e le cose sono diventate ragionevoli. Almeno questo è quello che è successo e non so il motivo, forse tu capirai.
Grazie
Grazie
Hello davidelaferla, how do you put a stop loss and where exactly ? the moment you enter on the market I suppose ? how many distance with the tradeprice ?.
I tried to find optimized parameters in low time units 1mn 5mn, 15mn, to do daytrading, but I suppose they dont remain the same from one day to another, or one week to another ?
Thank you and have a good day
Buongiorno Davide
a quale distanza inserire stop loss e tp nella strategia?
grazie