Golden Cross Trend Filter EA (50/200 SMA)

Golden Cross Trend Filter EA (50/200 SMA)
Download ALL MT5 experts (1777)
YouTube Video Thumbnail



Similar MetaTrader Tools

Golden Cross Trend Filter EA (50/200 SMA)

Info

The Golden Cross Trend Filter EA (50/200 SMA) is a Expert Advisor for MetaTrader 5 that the golden cross is a well-known trend following strategy: maintain a long position while the 50-day simple moving average (sma) of daily closes is above the 200-day sma, and exit to a flat position when it crosses below (a "death cross"). This Expert Advisor (EA) precisely implements this rule, making it suitable for testing and operation on any symbol with sufficient daily historical data.

Usage

This tool is typically used for trend following strategies across multiple currency pairs.

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 Golden Cross Trend Filter EA (50/200 SMA)

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

The Golden Cross is a well-known trend following strategy: maintain a long position while the 50-day simple moving average (SMA) of daily closes is above the 200-day SMA, and exit to a flat position when it crosses below (a "death cross").

Typical Use Case

This Expert Advisor excels in trend following 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: Moving Average Crossover Expert Advisor for Gold (XAUUSD) - another powerful expert for MetaTrader 5 traders.

The Golden Cross is a well-known trend following strategy: maintain a long position while the 50-day simple moving average (SMA) of daily closes is above the 200-day SMA, and exit to a flat position when it crosses below (a "death cross"). This Expert Advisor (EA) precisely implements this rule, making it suitable for testing and operation on any symbol with sufficient daily historical data.

Also recommended: EMA Trend Cross Strategy for XAUUSD M30 - similar expert with strong performance on MetaTrader 5.


How it Works
The moving averages are calculated using data from the last completed daily bar (shift 1), ensuring that decisions are not influenced by bars that are still forming. This prevents look-ahead bias in the Strategy Tester. The EA compares the fast and slow SMAs once at the beginning of each new daily bar: if the fast SMA is greater than the slow SMA, it signals a long position. If InpAllowShort is enabled, it will open a short position when the fast SMA is below the slow SMA. There are no explicit stop-loss or take-profit levels, as the Golden Cross/Death Cross rule itself dictates entry and exit points.

Session Handling
For many CFDs, the new daily bar opens while the market is closed (e.g., index CFDs at midnight server time). To address this, the EA checks the symbol's defined trading sessions. If the market is closed or an order is rejected, it will retry on subsequent ticks within the same day. Attach this EA to an H1 (or lower) timeframe chart. In the Strategy Tester, use an H1 chart with either "Open prices only" or "Every tick" mode. Using a D1 chart in "Open prices only" mode will result in only one tick being received per day, at midnight.

Testing on a US500 CFD
A test was conducted on a US500 CFD using the Golden Cross rule (long only) from January 2015 to November 2026, starting with 10,000 USD and a 50% notional position size. The EA entered and exited trades consistent with the major Golden Cross and Death Cross events observed in the S&P 500 index. While the price movements during these trades were profitable, the extended holding periods (up to 954 days) resulted in substantial swap costs that exceeded the price gains. The following table illustrates this:

Trade
Days Held
Price Profit
Swap
Net

2016.04 – 2018.12, 2.3 lots
954
+1,389.84
−4,472.90
−3,083.06

2019.03 – 2020.03, 1.2 lots
367
−403.32
−898.62
−1,301.94

2020.07 – 2022.03, 0.8 lots
609
+884.72
−992.67
−107.95

2023.01 – 2025.04, 0.6 lots
805
+813.80
−983.25
−169.45

2025.07 – 2026.11, 0.4 lots
499
+561.16
−408.47
+152.69

Total
+3,246.20
−7,755.91
−4,509.71

Two important considerations arise from this test. Firstly, the swap cost was uniformly applied at 2.04 USD per lot per day across all trades. The Strategy Tester applies the symbol's current swap rate to historical data. In earlier periods, when the index value was significantly lower, the swap cost relative to the position's value might be overstated. Secondly, even with current pricing, a daily swap cost equivalent to approximately 10% per year of the position value can erode most of the returns generated by a slow-moving trend strategy. Testing the same rule on the S&P 500 price index itself (1993–2026, with no costs) yielded a Compound Annual Growth Rate (CAGR) of 8.41%, compared to 8.93% for a buy-and-hold strategy, with a maximum drawdown of −33.9% versus −56.8%. The difference highlights the impact of swap costs when holding CFD positions for extended durations. It is crucial to verify the swap rates of your chosen symbol before implementing any long-term holding EA.

Inputs

InpFastPeriod (50): The period for the fast Simple Moving Average, measured in daily bars.

InpSlowPeriod (200): The period for the slow Simple Moving Average. This value must be greater than InpFastPeriod.

InpAllowShort (false): If true, the EA will also hold short positions when the fast SMA is below the slow SMA.

InpNotionalPct (50): The desired position value as a percentage of the account balance. Set to 0 to use a fixed lot size instead.

InpFixedLot (0.10): The fixed lot size used when InpNotionalPct is set to 0.

InpMagic: A unique magic number to ensure the EA only manages its own trades.

InpDeviation (50): The maximum allowed slippage in points.

Note: Historical results presented here are based on this specific rule and symbol. They do not guarantee future performance.

You may also like: Fx Craft Example EA: MA Cross Strategy Explained - excellent alternative for expert users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#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 int    InpFastPeriod  = 50;
input int    InpSlowPeriod  = 200;
input bool   InpAllowShort  = false;
input double InpNotionalPct = 50.0;
input double InpFixedLot    = 0.10;
input long   InpMagic       = 205020;

.......

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.