The First Program We Never Forget (Metatrader MQL4)
Today I'm celebrating with myself!
For some days I have been thinking about learning how to program (Thank you @cryptoctopus), mainly because it is a skill that I believe that, regardless of the professional field, it can be very useful.
I've always been involved since I was a kid with computers (my dad had an MSX), but for some reason learning to program has never piqued my curiosity enough so far.
After a few days wondering which language would be most interesting for my personal goals, I had an epiphany: Why not learn MQL, metatrader programming language, and who knows maybe one day learn to program a good trading robot?
And so I did, and today, less than a week after starting to try to understand how to create a program in Metatrader 4, I was able to finish the programming of an Expert Advisor(Trading Robot). In the end, the small interest I had about programming Basic in MSX, some courses during adolescence, and a subject of Object Oriented Programming in college were very useful.
And in the end it turned out to be easier than I expected.
This robot is not a new marvel of the trade, I'm not sure if it's going to be profitable, and it probably has a lot of code optimization flaws, but it's a good feeling to know that it's possible to learn a programming system with a certain dose effort and achieve effective results.
The logic of the robot is very simple, using three exponential moving averages (200,26,12):
Uses the comparison between EMA 26 and EMA 200
* If EMA 26> EMA 200 - High Trend
* If EMA 26 <EMA 200 - DowntrendIf you are in a bullish trend, buy in one of three conditions
* EMA 16 crosses EMA 26 from bottom to top
* Close the purchase when the price touches EMA 16
* EMA 26 crosses EMA 200 from bottom to top
* Purchase date when EMA 16 crosses EMA 26 from top to bottom
* When EMA 16> EMA 26, buy when price touches EMA 26
* Purchase date when EMA 16 crosses EMA 26 from top to bottomIf you are in a downtrend, sell in one of three conditions
* EMA 16 crosses EMA 26 from top to bottom
* Close the purchase when the price touches EMA 16
* EMA 26 crosses EMA 200 from top to bottom
* Close buy when EMA 16 crosses EMA 26 from bottom to top
* When EMA 16> EMA 26, buy when price touches EMA 26
* Close buy when EMA 16 crosses EMA 26 from bottom to top
In a future post I explain the strategy better, with drawings for better understanding.
WARNING: I am using this strategy for learning purposes only. Use it at your own risk.
The code in MQL is based on C ++, so some knowledge about this language makes learning a lot easier.
If you read this article you are aware of MQL or C ++, feel free to criticize, and suggest improvements in how to write the code. I really appreciate any guidance.
Without further ado, I present to you, MY ROBOT! (Part of the code was not I that wrote, but I copied the tutorials, after all it is part of the learning):
The code has been completely bugged here, so if you want to take a look at it, see here
Posted from my blog with SteemPress : http://tradingpassoapasso.com.br/index.php/2018/02/14/o-primeiro-programa-agente-nunca-esquece-metatrader-mql4/
You have collected your daily Power Up! This post received an upvote worth of 0.43$.
Learn how to Power Up Smart here!