After a little
If you aren’t acquainted with concept of the
In short, the
The expert advisor is available only for MetaTrader 4, because I still have a lot of issues with the MetaTrader 5 order handling. Because it’s not profitable, I didn’t add it to the list of MT4 EAs on my site.
How to use it:
- Download and copy to your MetaTrader’s /experts/ folder.
- You’ll need to create a
map-file with the market “knowledge” for EA. - Open the EA in MQL Editor and comment out lines 59 and 87–106.
- Compile it.
- Run it in a strategy tester on EUR/USD, H1, Open prices only, any period (the longer is the better).
- “rl.txt” file will be created inside /tester/files/ folder of your MetaTrader.
- Copy it to /experts/files/ folder.
- Open the EA in MQL Editor and uncomment lines 59 and 87–106.
- Compile it.
- You can now attach it to EUR/USD H1 chart. It will trade and continue learning. On deinitialization it will save its data to “rl.txt” located in your /experts/files/ folder.
There are three known problems with this Forex expert advisor that make its use unprofitable:
- Basing the market knowledge on the OHLC patterns of the previous bars proved to be ineffective.
- If the market significantly changes its behavior compared to the period of learning, the EA fails to trade profitably.
- If the range of prices changes significantly, the previous data proves to be pretty useless.
Possible ways to improve this
- Find better market parameters to store as the EA’s knowledge (
Heiken-Ashi , various pivots, indicator values, etc.) - Provide better learning pattern — not just buy, sell or hold if the
Close-Open difference of the next candle after the pattern was inside/outside a certain range of pips. - Find better coefficient system to weight the older data compared to the newer.
- Add more maps with different data that can’t be compared with the data stored in the primary map (for example, a separate map for Volume data).
- Use other distance measuring method instead of Euclidean (Mahalanobis, Manhattan, Chebyshev, Minkowski, etc.)
- Find a different way of applying the distance — using the average distance, using the shortest distance, using the median distance, etc.
You can freely modify, upgrade and use the pieces of code from this EA as long as you leave the credit to the original author (me) inside the MQL file. If you manage to get something worthy out of it, please let me know.
If you have any questions or comments regarding this
All that said is fine, but let’s not forget about other things that are important to take into account. Based on my experience, the Forex market is constantly changing and evolving so you want a software program program that changes with you. There are many software, you need to pick something that fits well with your knowledge and strategy and consider risk.
▼Reply
Andrei Reply:
April 19th, 2010 at 9:27 am
Yeah, that’s why such self-learning EAs are good. They are constantly learning as the market changes.
▼Reply
Hi there,
please tell me how to comment out and uncomment lines in editor as you said(59 and 87-106).
And after running the tester it is not saving any ‘rl.txt’ file or any file in the tester/files folder,
Now please tell me what to do??
▼Reply
admin Reply:
October 4th, 2010 at 9:52 am
To comment a line, just add “//” in front of it. Or use “/*” and “*/” to comment many lines at once. To uncomment, remove “//” or “/*” and “*/”.
The file will be created after you do all the steps up to step 6 listed above. If it’s not created, please, check if there were any errors in the Journal or the Expert tab during the back-test.
▼Reply
Can you give an visual example on how to comment line 59 so I can make sure to do it right?
▼Reply
Erick Reply:
November 6th, 2012 at 4:55 pm
I keep getting errors
▼Reply
admin Reply:
November 6th, 2012 at 8:30 pm
What kind of errors?
▼Reply
admin Reply:
November 6th, 2012 at 4:56 pm
Uncommented line:
Commented line:
// LoadKohonenMap();
▼Reply
Erick Reply:
November 6th, 2012 at 5:05 pm
Thanks
▼Reply
I’m trying to do a backtest but its not showing and buying or selling during the visual. Is that suppose to happen?
▼Reply
admin Reply:
November 6th, 2012 at 9:59 pm
When you comment out the lines 59 and 87–106, you put the EA into a learning mode. Running a backtest creates a file named “rl.txt”. Now you can uncomment those lines and run it on demo (make sure to copy “rl.txt” from /tester/files/ to /experts/files/) or run it on some different backtest date range. That’s all actually written in the post above.
▼Reply
I got everything worked out…Do you know any other good EA thats self-learning or self-adapting thats good?
▼Reply
admin Reply:
November 10th, 2012 at 7:59 pm
By googling for “better ea” you will find a lot of clones of the neural network expert advisor used by the trader Better, who was rather successful in MetaQuotes’ automated trading championships.
▼Reply
ok thanks
▼Reply
admin Reply:
November 10th, 2012 at 9:48 pm
Welcome! I would appreciate if you could share anything interesting you find :-).
▼Reply
Hi Admin,
thanks for giving me such an easy and explanatory way to study selflearning systems. I would have thought those systems much more complicated than you’ve solved this.
But: Where is the place in “TeachMap()” where the EA “forgets” values?
I mean: It introduces new values, until the entire map is filled and never ever forgets any learned state, except the highest X. Or did I miss something from your code?
Thanks for the explanation
Tom.
▼Reply
Andriy Moraru Reply:
December 19th, 2014 at 12:23 pm
Yes you are right, it does not forget anything. When the entire map is filled it will be rewriting vector number (MAPBASE – 1) or (HOLDBASE – 1).
▼Reply
Tom Reply:
December 23rd, 2014 at 10:40 pm
Ah – thanks for the clarification.
This system trades a “known” month with a 90% hit rate and a 1:2 risk/reward.
But it fails – as you already mentioned it – on a unknown month. After it “learned” this losing month it trades it as mentioned above.
It is – so you can say a wonderful patternmatcher which trades a known month with a superb accuracy.
All we have to do is, to get the system to forget failures and to keep them forgotten, I assume?
▼Reply
Andriy Moraru Reply:
December 24th, 2014 at 9:48 am
No, there is no reason to forget anything on purpose. It does not record ‘failures’, it only records conditions that led to some directed market movement. Of course, there is no guarantee that the next such market conditions will lead to the same direction in future.
I would not treat this EA as some money-making opportunity. It is just a basic example of a self-learning algorithm in MT4.
▼Reply
Hi Sir,
I’m very much interested in the self learning trading systems. Can you please explain a little more about the trading logic of the “RowLearnerCorrectedFinal ” EA. I’m fascinated with the subject and putting serious efforts in learning and coding such systems. Any help will be highly valuable.
Regards,
Harish
▼Reply
Andriy Moraru Reply:
December 16th, 2017 at 4:17 pm
The trading logic is pretty much explained in the 5th paragraph of this blog post. The provided source code is also quite explicit. What exactly don’t you understand in its working?
▼Reply