Fx Craft Example EA: MA Cross Strategy Explained

Fx Craft Example EA: MA Cross Strategy Explained
Download ALL MT5 experts (1732)
YouTube Video Thumbnail



Similar MetaTrader Tools

Fx Craft Example EA: MA Cross Strategy Explained

Info

The Fx Craft Example EA: MA Cross Strategy Explained is a Expert Advisor for MetaTrader 5 that an educational example of a simple trend-following expert advisor. It demonstrates structuring a trading robot in MQL5, including signal generation on closed bars, order execution with robust checks and retries, and safe handling of terminal restarts.

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use Fx Craft Example EA: MA Cross Strategy Explained

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

An educational example of a simple trend-following Expert Advisor.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.

Description & Settings

Related: Fx Craft Example EA: Bollinger Bands Mean Reversion - another powerful expert for MetaTrader 5 traders.

An educational example of a simple trend-following Expert Advisor. It demonstrates structuring a trading robot in MQL5, including signal generation on closed bars, order execution with robust checks and retries, and safe handling of terminal restarts.

Also recommended: Fx Craft Example EA: Range Breakout with Pending Orders - similar expert with strong performance on MetaTrader 5.


Strategy Details

A BUY signal is generated when the fast Moving Average (MA) crosses above the slow MA on closed bars (fast MA value less than or equal to slow MA on the second-to-last bar, and fast MA value greater than slow MA on the last closed bar). A SELL signal is generated conversely. The signal is evaluated once at the opening of a new bar. Upon initialization, the EA does not open a trade immediately; it waits for the first valid crossover signal. The EA manages only one open position at a time. An incoming opposite signal will close the existing position and open a new one in the opposite direction. If an order fails to open due to reasons such as spread or requotes, the EA will retry on subsequent ticks. This retry mechanism is active only until the end of the current signal bar.

Code Functionality Demonstrated

- Free margin check using OrderCalcMargin before every order placement.
- Lot size normalization to adhere to the symbol's minimum, maximum, and step requirements.
- Stop Loss (SL) and Take Profit (TP) levels are adjusted to meet the broker's minimum distance requirement (SYMBOL_TRADE_STOPS_LEVEL).
- Spread filtering is implemented.
- Retries for requotes and price changes are handled.
- Indicator handles are properly released in OnDeinit.
- Messages are displayed in English or Polish, adapting to the terminal's language setting.

EA Inputs

- TimeFrame: Sets the timeframe for signal generation (defaults to the current chart). - Fast MA period / Slow MA period: Set to 10 / 30 respectively (the slow MA period must be greater than the fast MA period). - MA method / Applied price: Uses Exponential Moving Average (EMA) applied to the Close price. - Lot (fixed): Standard lot size set to 0.10. - Stop Loss / Take Profit: Specified in points; a value of 0 means no stop loss or take profit is used (default is 300 / 600 points). - Magic number: Set to 5010 for trade identification. - Max slippage: Maximum allowed slippage in points (set to 10). - Max spread: Maximum allowed spread in points; a value of 0 disables this filter (default is 30 points).

Important Considerations

This Expert Advisor is provided as an educational example and is not intended as a standalone trading system. It is designed to function exclusively on demo accounts and within the Strategy Tester. On a live trading account, it will display a message and cease operation. The EA is provided "as is", without any form of warranty. It does not constitute investment advice. Trading Forex and CFDs carries a high risk of capital loss. License: FxCraft Example EA License (refer to the source code header for details).

You may also like: Indicator Parameters Usage Example - excellent alternative for expert users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version     "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include <Trade\Trade.mqh>
input group "=== Signal ==="
input ENUM_TIMEFRAMES    InpTimeframe    = PERIOD_CURRENT;
input int                InpFastPeriod   = 10;
input int                InpSlowPeriod   = 30;
input ENUM_MA_METHOD     InpMAMethod     = MODE_EMA;

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.