Free Forex MQL Training
Free Forex, Candlestick Charts, and MetaTrader Training
| A Sample Expert Advisor Uses Moving Averages |
|
| Written by Al Parsai | |
| Sunday, 08 March 2009 | |
|
If you are familiar with MQL programming you know how easily you could automate many of trading systems. MQL or rather MetaQuotes Language is equipped with several tools that enable the programmer/trader to turn his/her ideas into an automated system. Of course you may also use MQL to develop scripts in order to manage complex tasks or develop custom indicators to analyze the market. Nonetheless, many programmers/traders use MQL to develop fully automated trading systems or rather Expert Advisors. Click here for more information about MQL/MetaTrader programs.
The purpose of this article is to share a sample Expert Advisor with you. This is an educational EA that was first suggested by one of my students. Thanks to him I spent about two hours to develop and test the EA. It is now available to all our visitors.
Caution: This is an educational EA. Do not trade it live. The intention of this EA is to show you how you can develop an Expert Advisor not to offer you a proftable trading system.
How "Sample Moving Average EA" Enters TradesThis EA uses two exponential moving averages (EMAs) to enter trades. If the fast moving average (default period 5) crosses up the slow moving average (default period 25) then the EA enters a long trade. If the fast EMA crosses down the slow EMA it enters a short trade. The EA ignores the current bar. It uses the past two bars to spot the cross.
The EA enters one trade at a time. So if a trade with this EA on the current currency pair is already open it does not enter a new trade. You may attach this EA to any Forex chart or any time frame. If you attach it to more than one chart at a time then it could open concurrent trades on different currency pairs but not on the same currency pair.
How "Sample Moving Average EA" Exits TradesThe EA places a Stop Loss and a Take Profit for each trade. The default values of the SL and TP are 200. You may change these values. The EA closes the trade if the trade hits SL or TP. An alternative situation is when the market direction changes. For example if a long trade is open and fast moving average crosses down the slow moving average the EA closes the long trade and enters a short trade.
How "Sample Moving Average EA" Avoids Multiple TradesThe "sample_ma_trader" uses a Global Variable or GV to store the time it entered the latest trade. It then compares the open time of the current bar with the registered time. It the registered time falls into the current bar or candle then it does not enter a new trade. This is a safe approach as MetaTrader saves the value of GVs even if you shut down the platform for up to four weeks.
The EAs Input VariablesThis Expert Advisor comes with some input variables that could help in enhancing its behaviour (see image). (Click imgage to enlarge)
Other FeaturesThis is EA is compatible with fractional pips also known as fifth digit.
Download the EA [download]Click here to download the EA. I have documented the code so you may understand how it analyzes the market and enters or exits trades. The code does not include error management so if something goes wrong it may not be able to address it correctly. Please do not use it in live environment.
If you would like to learn MQL programming, click here for your options.
Important Note: This EA is not designed for live trading. I have designed it as a sample Expert Advisor to show you how you may develop one. Do not consider it as a trading system. Do not trade live with this EA. Also I do not take responsibility of the results you may get by using this Expert Advisor or any other tools published on ForexBrace.com. Neither this website nor I offer financial advice. I am also not responsible for any malfunctions of the programs offered on this website. Risk Warning!
|
|
| Last Updated ( Monday, 16 March 2009 ) |
| < Prev | Next > |
|---|






