Forex
EA

EA: OsMA Cross Expert Advisor

Last updated 2026-07-20

An Expert Advisor (EA) is different from every other download on this site — an indicator only plots or alerts, while an EA actually sends orders on your behalf. This free EA trades a single, transparent strategy built around the OsMA histogram crossing its zero line: it enters the moment the MACD line crosses its signal line, then manages Stop Loss, Take Profit, and position size automatically from the same risk tools taught elsewhere on this site.

How the Strategy Works

The entry signal is the zero-line cross of the OsMA histogram — the Moving Average of Oscillator explained in the OsMA lesson. OsMA is the distance between the MACD line and its signal line: positive when the MACD line is above its signal, negative when it's below. So an OsMA zero cross is exactly the same event as a MACD signal-line crossover, just read off a histogram instead of two lines. This EA uses the standard 12/26/9 MACD settings, so it trades the classic MACD crossover with none of the ambiguity of eyeballing where two wiggling lines meet.

Trading OsMA rather than watching the two MACD lines directly has one practical benefit even for an automated system: the signal is a single value crossing a single level, which is unambiguous to code and to backtest. There's exactly one condition to check per bar — is the histogram above or below zero, and did that just change — which keeps the strategy short and its behavior easy to reason about.

Stop Loss, Take Profit, and Position Sizing

PriceTake Profit (TP)Stop Loss (SL)BUY0OsMA histogram (MACD line minus its signal line, around a zero line)
Entry conditions: BUY when the OsMA histogram crosses back above zero — SELL on the mirrored cross back below zero — SL and TP are placed automatically from ATR

Both Stop Loss and Take Profit are sized from ATR rather than a fixed pip distance — a volatile pair or session gets a wider stop automatically, and a calm one gets a tighter stop, so the stop always reflects what the market is actually doing right now rather than an arbitrary number chosen once and left unchanged. Stop Loss distance is ATRMultiplier × ATR (default multiplier 2.0, with ATR over ATRPeriod = 14 bars), and Take Profit is set at RiskRewardRatio × Stop Loss distance (default 2.0), so every trade carries a fixed, known reward-to-risk proportion regardless of pair or timeframe.

Position size is calculated from RiskPercent (default 1.0%) against your account balance and the Stop Loss distance — the exact worked-example method from Risk Management Basics: risk amount ÷ Stop Loss distance = lot size. A wider ATR-based stop on a volatile pair automatically produces a smaller lot, and a tighter stop on a calm pair a larger lot, so the dollar risk per trade stays roughly constant even as the price distance to the stop changes trade to trade. A UseFixedLot input is available as an escape hatch for a constant lot size — useful for testing, or for small accounts where percentage-based sizing rounds to the broker's minimum lot anyway.

Entry Conditions

  • BUY — OsMA crosses from at-or-below zero to above zero on consecutive completed bars (the MACD line has just crossed above its signal line).
  • SELL — OsMA crosses from at-or-above zero to below zero — the mirrored setup (the MACD line has just crossed below its signal line).

Beyond the signal itself, three safety mechanics govern every trade: the EA only evaluates these conditions once per new bar (not on every tick, so a single crossover can't fire multiple trades within the same candle), only opens one position at a time (a new signal is ignored while a position from this EA is already open), and only manages positions tagged with its own magic number (20260802) — so it never touches trades you open manually or trades placed by a different EA on the same account. A spread filter also sits in front of every entry: if the current spread is wider than MaxSpreadPoints, the EA skips that bar entirely rather than opening a trade at a bad price during illiquid conditions.

Parameters

  • FastEMA (default 12) — the fast EMA period inside the MACD the OsMA is derived from.
  • SlowEMA (default 26) — the slow EMA period.
  • SignalSMA (default 9) — the signal-line smoothing period OsMA measures against.
  • AppliedPrice (default Close) — the price series the calculation runs on.
  • ATRPeriod (default 14) — the lookback used to calculate ATR for Stop Loss sizing.
  • ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
  • UseFixedLot — switches position sizing from risk-based to a constant lot size.
  • FixedLotSize (default 0.01) — the lot size used when UseFixedLot is enabled.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade. Ignored if UseFixedLot is enabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this.
  • MagicNumber (default 20260802) — tags every order this EA places so its management logic never touches other trades.
  • EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.

Why Trade the Histogram Cross Instead of the Histogram Turn

The OsMA lesson explains that the histogram turns (stops growing and starts shrinking) one step earlier than it crosses zero. This EA deliberately trades the later, more conservative event — the zero cross — rather than the earlier turn, and the reason is reliability. The histogram turning is an aggressive, early read that momentum is decelerating, but decelerating momentum frequently re-accelerates without ever crossing zero, so an EA that fired on every turn would take a large number of premature trades that the trend then invalidates. Waiting for the actual zero cross sacrifices some entry price in exchange for a signal that only fires once the MACD relationship has genuinely flipped, which is a much cleaner rule to automate.

That conservatism doesn't rescue OsMA from its core weakness, which it inherits directly from the MACD: it is a lagging, moving-average-of-moving-averages construction, so in a sharp reversal it confirms the turn well after price has moved, and in a sideways market it crosses zero over and over on meaningless wobbles. This EA therefore performs best in trending or freshly breaking-out markets and worst in tight, directionless ranges. Confirming trend vs range conditions before running it on a given pair, or layering an ADX or higher-timeframe trend filter on top, is the natural way to improve its results — the EA itself makes no attempt to detect that condition and simply trades the cross wherever it happens.

Installation and Setup

EAs install into a different folder than indicators — this is the step people miss most often.

  1. Download the file below for your platform.
  2. Open MetaTrader → click FileOpen Data Folder.
  3. Place the file in MQL4/Experts (MetaTrader 4) or MQL5/Experts (MetaTrader 5) — not the Indicators folder.
  4. Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
  6. Review and adjust the input parameters in the EA's settings dialog before confirming.

A Word of Caution

Test on a demo account first, across different market conditions, before risking real money — past performance, in backtests or live, never guarantees future results. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades. Because OsMA is derived from moving averages, its zero-cross signal lags real price turns and whipsaws badly in ranging markets, where you should expect a run of small losing trades in quick succession. Consider pairing this EA with a trend filter, or only running it on pairs and timeframes you've confirmed are trending, rather than leaving it on every chart in every condition. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.

Download the EA

How to Install — MetaTrader 4

  1. Download the osma-cross-ea.mq4 file below.
  2. Open MetaTrader 4 → click FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.

How to Install — MetaTrader 5

  1. Download the osma-cross-ea.mq5 file below.
  2. Open MetaTrader 5 → click FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.

Both files are source code — open and review the full code before using it, for your own safety.

Download osma-cross-ea.mq4

For MetaTrader 4 — this is source code (.mq4), open and review it fully before using it.

Download File

Download osma-cross-ea.mq5

For MetaTrader 5 — this is source code (.mq5), open and review it fully before using it.

Download File