Mean Reverting Strategy on AUDCAD on h1 timeframe
Forums › ProRealTime English forum › ProOrder support › Mean Reverting Strategy on AUDCAD on h1 timeframe
- This topic has 36 replies, 13 voices, and was last updated 6 years ago by Yngve.
-
-
03/05/2018 at 11:27 AM #64053
This is a mean reverting strategy that I currently run live on AUDCAD.
Enjoy, comment and improve 🙂
1234567891011121314151617181920212223242526272829303132333435//-------------------------------------------------------------------------// Main code : audcad_meanrevert_v2//-------------------------------------------------------------------------defparam cumulateorders = falsen = 1m = 3l = 90cs= summation[n](close>open) = ncs = cs and close>bollingerup[20](close) and close>dlow(2)cl= summation[m](close<open) = mcl = cl and close<bollingerdown[20](close) and close<Dhigh(2)size = 2//entry conditionsif cs thensellshort size contract at marketendifif cl thenbuy size contract at marketendif//exit conditionsif shortonmarket and close<average[l](close) thenexitshort at marketendifif longonmarket and close>average[l](close) thensell at marketendif03/05/2018 at 11:37 AM #64416Thank you Francesco, going back to mid 2010, the strategy is still quite good in tick by tick backtesting. Did you try some WalkForward analysis since you seem to have optimized the variables? I know there are only 3 of them, but should be interesting to know how it performs with WF. I launched one just now, I’ll get back with results.
03/05/2018 at 12:10 PM #64424I threw my Heuristics Algorithm in there to optimize the average[l] variable;
Now results are looking good on other AUD pairs like AUDUSD as well.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Main code : audcad_meanrevert_v2//-------------------------------------------------------------------------defparam cumulateorders = false// Heuristics Algorithm Startonce OPT = 1If OPT < 2 and onmarket thenOPT = 0ElsIf countofposition = 0 ThenOPT = 1EndIFIf OPT = 0 Thenoptimize = optimize + 1OPT = 2EndIf////////////////////////////////////////once periods = 100Increment = 14MaxIncrement = 4Reps = 20 //Number of bars to use for analysisonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce Optimize = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsonce WinCountB = 0 //Initialize Best Win Countonce StratAvgB = 0 //Initialize Best Avg Strategy ProfitIf Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + positionperf(i)NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = PeriodsEndIfIf WinCountA >= WinCountB ThenWinCountB = WinCountA //Update Best Win CountBestB = PeriodsEndIfIf WinCountA > WinCountB and StratAvgA > StratAvgB ThenMode = 0ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenPeriods = Periods - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenPeriods = Periods + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenPeriods = Periods + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA > WinCountB or StratAvgA > StratAvgB and Mode = 2 ThenPeriods = Periods - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2EndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement ThenIf BestA = BestB ThenPeriods = BestAElsePeriods = (BestA+BestB)/2EndIfNIncPos = 1PIncPos = 1EndIFOptimize = 0EndIfGRAPH Periods AS "Periods"// Heuristics Algorithm Endn = 1m = 3l = periods//90cs= summation[n](close>open) = ncs = cs and close>bollingerup[20](close) and close>dlow(2)cl= summation[m](close<open) = mcl = cl and close<bollingerdown[20](close) and close<Dhigh(2)size = 2//entry conditionsif cs thensellshort size contract at marketendifif cl thenbuy size contract at marketendif//exit conditionsif shortonmarket and close<average[l](close) thenexitshort at marketendifif longonmarket and close>average[l](close) thensell at marketendif4 users thanked author for this post.
03/05/2018 at 12:11 PM #64425Hi Nicolas, yes I did WF test of course.
Ill be curious to see the results since 2010. Many thanks
Francesco
03/05/2018 at 1:50 PM #64435Sorry, I forgot to attach the result in my first post.
You’ll find attached 3 different pictures, first with WF non anchored, second one with WF anchored and the last one with the variables you are using but with 200k bars backtest.
As you can see all the OOS periods make huge gain while the IS period is not performing so well, it is a sign of overfit. It doesn’t mean that the strategy is bad, it means that it should need refining with some extra filters or more OOS periods to optimize more often.
@juanj Thank you, will study this version.1 user thanked author for this post.
03/05/2018 at 9:31 PM #64503Thank you Nicolas, can you claryfy for my own benefit why you think that adding filter in this case could be effecting on reducing overfitting?
Thanks!
03/06/2018 at 10:45 AM #64559The question is, why does the strategy is not performing as well in first IS as in OOS? 2012 crisis? I meant to study entries depending of the market behavior in this case, of course, more variables mean more overfit… But as I said, maybe it could be solved by adding more IS+OOS repetitions.
03/15/2018 at 8:45 AM #65330Well, I think it could be now added to the library, with the WFA attached, what do you think @Francesco78 ?
03/15/2018 at 11:13 AM #65358Thank you, I am fine with it, let me know if you want me to make some amendments on my original post.
03/17/2018 at 12:35 PM #6549003/17/2018 at 6:03 PM #65528Hey Francesco, I’ll do it for you on Monday 😉
1 user thanked author for this post.
04/23/2018 at 8:54 PM #69022For what it is worth I tried tackling the large value of drawdowns compared to winning trades. I noticed the losing trades tend to have a larger number of bars so I optimized bars to < 80 bars which on 100000 bars reduced profit slightly 11384.4 down to 11015.20. It did reduce the maximum loss to 415.2o from 761.00.
The code for this change is attached
12345678910111213141516171819202122232425262728293031323334353637defparam cumulateorders = falsen = 1m = 3l = 90once Trade = 1cs= summation[n](close>open) = ncs = cs and close>bollingerup[20](close) and close>dlow(2)cl= summation[m](close<open) = mcl = cl and close<bollingerdown[20](close) and close<Dhigh(2)size = 2//entry conditionsif cs thensellshort size contract at marketendifif cl thenbuy size contract at marketendifif Barindex - Tradeindex < 80 thenTrade =1elseTrade = 0endif//exit conditionsif shortonmarket and close<average[l](close) or Trade = 0 thenexitshort at marketendifif longonmarket and close>average[l](close)or Trade = 0 thensell at marketendif1 user thanked author for this post.
05/04/2018 at 8:19 PM #69796Thank you very much, Francesco, for the strategy, which seems solid and robust !
I tried this on AUD CAD 30 minutes and it works also quite well.
Extended variables : S for short average close
With 15.000 bars from 7 February till 4 May 2018 it gives a robust profit of 2.945 CAD in 3 months (I did no IS/OOS testing) with M=3, N=2, L = 50 and S = 40, in 398 trades, spread 1,7 pips calculated
I also tried a maximum of one trade per day, with adding the condition ” OneTradePerDay = IntradayBarIndex < (Barindex – TradeIndex(1)) ”
This reduces the amount of trades with more then half, 180 trades, giving a robust profit of 2.354 CAD, with M=3, N=5, L = 50 and S = 90 (also I did no IS/OOS testing so far)
========================================================
For other currencies and indices I am still testing
So far for the FTSE with 2 contracts, exposure more than 30.000 GBP (!), it gives interesting profit of 3.900 GBP on the 15 minutes bar chart with 15.000 bars, from an a maximum of one trade per day, from 6 september 2017 till 4 May 2018, with M=1, N=3, L = 50 and S = 40 (also I did no IS/OOS testing so far !!)
The risk of overfitting for this kind of short periods is very big !! When testing for 100.000 bars the profit especially in the beginning, completely deminish !!!!!!!, but the endresult is quiet the same !
When testing the FTSE for 100.000 15 minutes-bars with not restricted trades per day, the NON- robust profit is a bit lower as when restricted to one trade per day, but not robust and a bit lower.
Kind regards,
Jan
1 user thanked author for this post.
05/04/2018 at 8:22 PM #6979805/12/2018 at 9:00 AM #70240Really nice strategy !
I’m running it in my demo account to try it out.
Thanks Francesco.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on