Loading…

VWAP Reversion EA

Neither platform has a built-in VWAP indicator, so this EA computes it directly: for every closed bar, it finds the start of the current calendar day, sums typical price times volume across that day's bars, and divides by the summed volume. That sum is rebuilt from scratch each bar rather than kept as a running total across ticks - a running total can silently drift after a terminal restart or a history gap, and recomputing from known-closed history each bar cannot drift, at the cost of a short loop that is irrelevant at one calculation per bar. Most forex data feeds carry tick volume rather than genuine traded volume, so tick volume is used as the best available weight; this is a tick-volume approximation of VWAP, not a true traded-volume calculation, and is documented as such rather than oversold as the genuine article. A fade is taken once the last closed bar's price has moved more than an ATR multiple away from the session VWAP, targeting a return to that VWAP value. New entries are capped at InpMaxTradesPerSession per calendar day: the VWAP edge is anchored to the current session, so once that anchor resets overnight, a fresh deviation early the next day is a new piece of evidence, not confirmation of the one from the day before - repeatedly re-fading the same session's VWAP would not be. The protective stop loss sent to the broker is set in ATR multiples from entry, not a fixed pip distance, so it scales with how volatile the symbol was at the moment of entry. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to that stop distance, using the broker's own tick value and tick size 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 - VWAP here is weighted by tick volume, the only volume most forex feeds provide, not genuine traded volume - treat it as a close approximation, not an institutional-grade VWAP. - The reversion target is checked once per closed bar against that bar's close, not against live intrabar price, so an exit can lag a brief intrabar touch of VWAP. - Day boundaries are read from the terminal's bar timestamps; on a symbol or broker where the server day does not match the trading session you care about, the session start will not line up with your intended session. - 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; if trading is disabled the EA logs it and skips the entry. - On MQL5 netting accounts, a foreign-magic position already on the symbol blocks every new entry rather than merging into it - see above.

Expert advisor · MT4 · v1.0 · Free

About VWAP Reversion EA

VWAP Reversion EA is an expert advisor (trading robot) for MetaTrader 4 based on ATR. It can size trades from your balance and risk percent. It has 11 settings, such as Atr period, Deviation atr mult and Stop atr multiple. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Atr period14ATR period used for the deviation band and the stop
Deviation atr mult1.5Distance from VWAP that triggers a fade, in ATR multiples
Stop atr multiple2.0Stop loss distance from entry, in ATR multiples
Max trades per session1Maximum new entries allowed per calendar day
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 number20260706Magic 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: ATR · VWAP · Volume · Trading Sessions · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria