This is a “machine learning” strategy for finding the best crossing strategy, comparing 70 different averages with each other, given a certain time frame and a certain market.
(The source of the very most of the averages is https://www.prorealcode.com/prorealtime-indicators/average-filter-regression/ posted by Laurenzo in 2017)
The strategy is simple:
If the first average crosses above the second average, go buy long
and vice versa if the first average crosses under the second average, sell short
It can be used for currencies and indices, presumably also for stocks (non-daytrading)
This strategy determines which of the 70 different averages is to be crossed with which of the same 70 different averages to give the best result in a certain market in a certain time frame, what in my opinion can be seen as a kind of “machine learning”
Further added to this strategy: (up to the user to adjust those variables if wanted)
There are 70 different types of averages, (listed below), which are used to cross each other (the first is named MAType, to be crossing the second MATypeV2)
To limit zigzagging of the averages due to market noise, an exponential average of 30 is added before the crossing condition is measured (Coded as wAFR = exponentialaverage[30](AFR) and wAFRv2 = exponentialaverage[30](AFRv2))
To limit the possibilities, the period is set for all average-types to 15 (Coded as Period = 15, Period2 = 15), periods may be adjusted.
Different stop distances can be used or a trailing stop can be used.
Be aware that if you use this “machine learning” on a small set of data, the outcome will be over- fitted and a different optimized set of averages for a different small set of data will appear (this happens with all strategies, robustness of the strategy has to be tested).
Be aware when running the given strategy, already 70 x 70 combinations has to be optimized, which is already 4.900 combinations, which makes the optimizing process (very) slow. It might be a good idea to split the combination into 5 sets, lets say from 0 to 13 averages comparing to the 69 averages, and next 14 to 26 comparing to 69 averages, and so on, then taking the best from the 5 sets.
I run the code first without In Sample/Out of Sample, to find the top 10 best average combinations, and around those top 10 run several In Sample/Out of Sample optimizations.
For In Sample/Out of Sample optimizations use 66% IS and 34% OOS, non repeated (not five runs)
The code is extremely long (> 3.600 lines), due to defining 70 and 70 different averages. Maybe it can be coded shorter ?
The crossing strategy itself can be found at the last rows !
I was not aware that PRT allows more then 3.600 lines of code as a strategy!
Please download the attached itf (200308-Averages-crossing.itf) to play around with this strategy.
You must be logged in to post a comment.
Hi Ian, hope you still use PRT and so you can read this post. I have tested a lot your work and i think it is a very good idea. So, i have tried to improve it modifying a little bit your work. First of all i have Inserted some variables to make more easy the backtesting to find the best options for each financial instrument. In detail, i have added the following: 1. MinLotti, MaxLotti,MultiplierLot, LotMngt - To automate a Lot calculation where if the last trade was in loss the next trade will have a Lot increased by the MultiplierLot. If the last trade was in gain, nothing happen. 2. The Time to start and close was substituted by 2 variable so, it is possible to find the better time frame for any kind of symbol, future, etc... and it is adaptabe to the various markets who open at different time. Obviously for the point 1. i have added some code to make this strategy working fine. I'm also working to make dinamic Period and Period2 but as you know PRT has limit on the number of possible combination so i'm trying to find a smart way and i want to raise a question to you. Normally the cross between two or more MA is made using different period and if the period of the first MA is 10 (for example) we need at least a double period for the second MA. So i'm thinking to a mechanism that choose automatically Period2 based on Period so we could limitate the combinations. What do you think ? Do you have another idea ? In the meantime i would to share with you and the other friends my version of the script you create but in this interface it is not possible attach .itf files so, who want the code can contact me directly and i'll send it immediately or if you wants, you can ask me the file and add it to your original thread. My email is: alex.furlani@gmail.com Let me know
Per lasciare che la strategia venga eseguita (dopo aver importato il file): Basta eliminare MAType e MATypeV2 ai parametri di ottimizzazione (direttamente sopra la prima riga del codice) Quindi digitare il codice Once MAType = ciò che si desidera selezionare Once MATypeV2 = ciò che si desidera selezionare Spero che ti aiuti. Ho letto questo post e avendo lo stesso problema, chiedo dove si trova MAType e MATypeV2, io non riesco a trovarlo. Grazie
I have now played around with this strategy for a while and my gut feeling is that it suffers from over-optimization. If you evaluate all the possible combinations you will find many that give fantastic results, but none of them provided any meaningful robustness upon closer inspection. So, did any of you find any combination on any index/time frame that provided you with any robustness?
Dear Jan, Thanks for your great work. I just tested the code and manage to follow the whole process except that I am blocked at this last step (as many of us it seems). I use PRT V11.1. Could you please let me know what has to be corrected in line 22 ? See attached picture for details Many thanks for your support. BR Philippe [url=https://postimg.cc/1fcBLjJj][img]https://i.postimg.cc/SNHPz08k/temp.png[/img][/url]
To activate it, I read that I have to remove the first 2 rows of code MATV1 and MATv2 ... I can't figure out where I am and if I need to delete the whole row or replace with other parameters Can you paste the code exactly by mentioning the line numbers? Thanks
Sorry, I found where I need to set MatV1 and 2 But to have it exactly identical to the BackTest with the 69 averages, how should I set it?
Hi Jan! In your opinion is it possible to set an instruction that every day, at a certain time f.e. 07am, automatically set the best value for the day?
Some late response of my site: same kind of question also asked in the beginning by MaoRai54, Your idea is to quasi optimise the "best" crossing every day. Therefore you should also determine the period to be back-tested every day. Please bear in mind that a short period with only a few trades is not very reliable, a different period with more trade may give completely different best crossings. The main assumption is that the / a short last period gives the best guidance for short term future movements, which I tend to believe is true. Program code concept could be as follows (not worked out yet), maybe the community gives excellent tips. When time = 70000 then Do for x bars backwards until now (period choosen for optimise crossing) For Avg1 to Avg 67 do For Avg21 to Avg2 67 do determine trade result for the period, given the crossing Next Next Select Avg and Avg2 which have given the best trade result Run the av crossing trading algo with the daily selected best Avg and Avg2 Be aware that running this kinds of code could be (terrible) slow ! This is true if you test this, I have not yet tested it in a strategy. Lots of discussion can be found at topic https://www.prorealcode.com/topic/machine-learning-in-proorder/
Hi Jan, wondering i you can help please, can you let me know how i now implement the strategy the system has found please. Great code by the way and would LOVE to talk to you more about it. Please let me know if we can chat about it more. But i am struggling to "Use" the strategy that i feel fits my portfolio and way.. Many thanks.
Hello, Please can you help. I use 10.3 and are not able to set the strategy live. "Folgende Veränderung müssen vor der Übermittlung des Codes an Proorder vorgenommen werden: Ersetzen Sie die Variable durch spezifische Werte. ( MA Type is set 10 & 30) Thanks Olli
It might be a good idea to reduce the average to 15 instead of 30 to reduce market noise effects, especially at higher timeframes. "To limit zigzagging of the averages due to market noise, an exponential average of 30 is added before the crossing condition is measured (Coded as wAFR = exponentialaverage[30](AFR) and wAFRv2 = exponentialaverage[30](AFRv2))"
Hallo zusammen, gibt es schon eine neue Version des codes? Alesandro?