In this case an error will be set which may be retrieved via the GetLastError function. Some errors are temporary and others are permanent.
For the purposes of simplicity in this tutorial the error code is simply returned and the code terminates. Retries occur whenever the buy condition is valid so permanent and temporary errors should sort themselves out.
Updating the code in the Start routine gives us the following:. By splitting the code up into functional parts, it is much easier to add specific error checking or other requirements to the individual parts without disturbing the functioning of the unrelated components.
Download the free MT4 expert advisor now! You may post this MT4 expert advisor to other sites, but if you do, you must post a link to this page directly and you may not sell this expert advisor or the source code. You are otherwise free to copy, use and distribute this MT4 expert advisor for non-commercial use. Search this site.
For updates. Report abuse. Page details.
MT4 Expert Advisor Template is a great tool however it might not be for everyone. I suggest you to consider the Expert Advisor Template if you satisfy the following conditions. Although most of the code is provided and commented, you need to be able to add your own code for the entry and exit signal and if you want to customize trailing stop and dynamic stop and take-profit. It is advisable to be familiar with compilation, which is understanding that this product is source code to be edited in the MetaEditor and that it has to be compiled to a working EA through the platform.
I would like to remind that this is not a fully working trading strategy. You will have to include your own entry and exit signals and strategy.
And it is very easy to find MT4 programmers capable of developing more personalized tools. The strategy uses a Simple Moving Average as a trend indicator. Further reverse MA crossing indicates the price movement direction change. The simplest of them is using a constant, fixed lot size. Crossing of MA 11 and MA 31 when price movement direction changes. For example, long lateral movements with strong deviations that can be traced neither to a flat nor to a trend. This variant like the variant a does not allow several orders opened in the terminal at the same time on one security.
If it doesn't make any sense to you, but you are interested to see how the code for an Expert Advisor works, then it can help you. If you are not the coding type of person and all this doesn't interest you, then probably, this isn't something for you. Together with the template you can download two fully functional expert advisors, so you can see how the code has been customized.
You can open a trading account with any of the MT4 Forex brokers to freely use the presented here expert advisor for MetaTrader 4. What Is Forex? Up to USD. Please disable AdBlock or whitelist EarnForex.