Forex
EA

EA: Williams %R Reversal Expert Advisor

Last updated 2026-07-17

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 mean-reversion strategy built on Williams %R: it watches for %R to snap back out of the Overbought or Oversold zone, then opens a trade with an ATR-based Stop Loss, an RR-multiple Take Profit, and a risk-based position size — all calculated automatically, with no manual chart-watching required.

How the Strategy Works

Williams %R runs on a scale that trips up a lot of traders coming from RSI or Stochastic: instead of 0-to-100, it reads 0 down to -100. A reading near 0 means price is closing right at the top of its recent range — as strong as price can look. A reading near -100 means price is closing right at the bottom of its recent range — as weak as it can look. This EA uses a 14-period Williams %R (WPRPeriod) and treats -20 as the Overbought line and -80 as the Oversold line, the same thresholds taught in the site's own Williams %R lesson, just mirrored onto the negative scale from Stochastic's familiar 80/20.

The signal the EA actually trades is not the moment %R first touches an extreme, it's the moment %R turns back out of one. A BUY setup forms when %R crosses back above -80 after having been at or below it — not the bar where price first looks oversold, but the bar where the sell-off visibly runs out of steam and momentum starts climbing again. A SELL setup is the mirror case: %R crossing back below -20 after having been at or above it. Touching an extreme only tells you the move was stretched; the cross back out is the first real evidence that the stretch is unwinding. Trading the touch itself, rather than the turn, is a common beginner mistake, and this EA is built to avoid it mechanically — it only fires on the cross-back bar.

Stop Loss, Take Profit, and Position Sizing

PriceTake Profit (TP)Stop Loss (SL)BUY-20-80OverboughtOversoldWilliams %R (0 to -100)
Entry conditions: BUY when %R turns up out of the oversold zone (below -80) — SELL on the mirrored turn out of the overbought zone (above -20) — SL and TP are placed automatically from ATR

Every trade's Stop Loss is sized from ATR rather than a fixed pip distance: SL distance = ATR × ATRMultiplier (default 2.0, with ATRPeriod defaulting to 14). A volatile pair or session gets a wider stop automatically; a quiet one gets a tighter stop — the stop always reflects what the market is actually doing right now, rather than an arbitrary fixed number that's too tight on some pairs and too loose on others. Take Profit is then set at RiskRewardRatio (default 2.0) times that same SL distance, so every trade this EA opens carries a fixed, known risk-to-reward ratio, win or lose, regardless of how wide or narrow the ATR-based stop happens to be on that particular trade.

Position size is calculated the same way it's taught in Risk Management Basics: RiskPercent (default 1.0%) of account balance, divided by the Stop Loss distance (converted through the symbol's tick value and normalized to the broker's lot step), gives a lot size where a losing trade costs roughly the same fraction of the account no matter how wide or narrow that particular Stop Loss happens to be. Traders who'd rather trade a constant lot size regardless of account balance or stop width can flip on UseFixedLot, which overrides the risk-based calculation with a flat FixedLotSize instead.

Entry Conditions

  • BUY — Williams %R crosses from at or below -80 (Oversold) on the previous bar to above -80 on the current bar.
  • SELL — Williams %R crosses from at or above -20 (Overbought) on the previous bar to below -20 on the current bar.

On top of the signal itself, the same safety mechanics every EA on this site relies on keep it well-behaved on a live account. It opens one position at a time — before considering a new entry, it counts existing positions filtered by symbol and magic number, and skips the signal entirely if one is already open. Every order it places is tagged with its own magic number (20260724), so it never touches trades opened manually or by a different EA sharing the same chart or account. It evaluates entry logic once per new bar only, tracking the timestamp of the last bar it processed, rather than re-checking on every incoming tick — without this, a single %R cross could otherwise fire the same signal dozens of times before the bar closes. And before opening anything, it checks the current spread against MaxSpreadPoints, skipping the entry if the market is too illiquid at that moment.

Parameters

  • WPRPeriod (default 14) — the lookback period for the Williams %R calculation; shorter reacts faster and crosses zones more often, longer is smoother and more selective.
  • Overbought (default -20.0) — the upper threshold on the -100-to-0 scale; a SELL fires when %R crosses back below this level.
  • Oversold (default -80.0) — the lower threshold on the -100-to-0 scale; a BUY fires when %R crosses back above this level.
  • ATRPeriod (default 14) — the lookback period used to calculate ATR for the Stop Loss distance.
  • ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size. Ignored if UseFixedLot is enabled.
  • UseFixedLot (default false) — when enabled, every trade uses FixedLotSize instead of the risk-based calculation.
  • FixedLotSize (default 0.01) — the flat lot size used only when UseFixedLot is enabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, avoiding entries at a bad price during illiquid conditions.
  • EnableTrading (default true) — a master on/off switch, useful for pausing the EA without removing it from the chart.
  • MagicNumber (default 20260724) — the unique identifier tagged on every order this EA opens, used to isolate its positions from manual trades and other EAs.

Why Williams %R Instead of RSI for This Strategy

This site also ships an RSI-based reversal EA that trades the exact same idea — a cross back out of an extreme zone — so it's worth being precise about what actually changes when the oscillator underneath is Williams %R instead. RSI smooths its calculation over its lookback period, which damps noise but also lags a little before it signals a turn. Williams %R uses the same kind of highest-high/lowest-low range calculation as Stochastic but applies no smoothing at all, so it tends to reach its extremes and turn back out of them slightly earlier than RSI does on the same data. That speed is the whole trade-off: an earlier signal means an earlier entry (and a comparatively smaller move already spent by the time this EA reacts), but it also means more of the raw noise in price action reaches the entry logic unfiltered, so a wider ATR-based stop and a strict one-position-at-a-time rule matter more here than they might on a slower oscillator.

The -20/-80 thresholds aren't arbitrary either — they mirror Stochastic's 80/20 zones, just flipped onto %R's negative scale, and they mark the outer fifth of the indicator's range on each side, which is roughly how far price needs to stretch within its recent high-low range before a bounce becomes statistically interesting rather than routine noise. A WPRPeriod of 14 is the same convention Larry Williams originally used and the default most trading platforms ship with, which keeps the EA's behavior easy to reason about and easy to compare against how the indicator is taught elsewhere on this site.

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. Mean-reversion EAs like this one are built on the assumption that an extreme reading snaps back toward the middle, and that assumption breaks down badly in a strong, sustained trend: Williams %R can pin near -100 for an extended stretch while price keeps grinding lower bar after bar, and this EA's "turn back above -80" signal can fire on nothing more than a brief pause before the downtrend resumes — a classic falling-knife entry that stops out as price simply continues rather than reverting. There is no trend filter built into this version; consider pairing it with a manual read of trend vs range conditions, or restricting it to pairs and timeframes known to chop rather than trend, before relying on it in a strong directional market. 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 williams-r-reversal-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 williams-r-reversal-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 williams-r-reversal-ea.mq4

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

Download File

Download williams-r-reversal-ea.mq5

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

Download File