Loading…

Moving Average Crossover EA

The two-MA crossover is the oldest trend-following idea in the book: when the fast average crosses above the slow one the trend is assumed to have turned up, and vice versa. It is included here in its plainest possible form, with method and applied price both exposed as inputs, so the next person can turn it into a starting template by changing inputs rather than by editing source. Both the entry and the exit come from the same crossover - there is no separate take-profit logic beyond an optional fixed distance, and no secondary filter to reduce whipsaw. That is deliberate: this project exists to show the mechanism cleanly, not to present a curve-fitted variant as if it were reliably profitable. It trades constantly in a ranging market and that is expected, not a bug. Stop loss and take profit are fixed pip distances, converted to points per-symbol from the broker's own digit count. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - No trend or volatility filter of any kind - in a ranging market the crossover fires repeatedly and trades the chop, which is the well-documented weakness of a bare MA crossover. That weakness is exactly what the other EAs later in this catalogue address one at a time. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled and trading permitted at the terminal, account and expert level; if trading is disabled the EA logs it and skips the entry.

Expert advisor · MT4 · v1.0 · Free

About Moving Average Crossover EA

Moving Average Crossover EA is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It can size trades from your balance and risk percent. It has 13 settings, such as Fast period, Slow period and Ma method. MQL source code included.

Files in the download: MaCrossoverEa.ex4, MaCrossoverEa.mq4, MaCrossoverEa.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Fast period10Fast MA period
Slow period30Slow MA period
Ma methodMODE_EMAMA method (both lines share it)
Applied pricePRICE_CLOSEPrice the MAs are built from
Stop loss pips50Stop loss distance, in pips
Take profit pips100Take profit distance, in pips (0 = none)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260801Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Moving Average · Buy/Sell Arrows · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria