Loading…

Time Weighted Average Price Executor

A classic TWAP schedule: pick a total size, a number of slices, and a window of time, and the EA divides the position into equal clips fired at equal intervals across that window. This is a scheduling discipline, not a concealment technique - the size and cadence are meant to be even and predictable, the opposite design choice from a randomised iceberg slicer. It trades a large single-moment entry for an average price closer to however the market actually traded across the chosen period. The schedule is index-based rather than "wait, then fire": slice number N is due at the start time plus N times the fixed interval, computed from the absolute start rather than accumulated from the previous slice. A slow tick, a busy CPU moment, or Strategy Tester's own timing quirks therefore cannot make the whole run drift progressively later - each slice still fires at its correct scheduled time. Slice size is recalculated each time from what actually remains divided by slices left, so a rejected or partially-filled earlier slice is made up rather than silently lost. Notes and limitations - Building the target across the window still carries the same total market exposure as one large order once it is complete - spreading the entry over time changes the average entry price, not the size of the finished position's risk. - Each slice pays its own spread and, on a commission account, its own commission. - No stop loss or take profit is attached to any slice. Pair this with a separate risk-management EA if the built position needs protecting. - If the terminal or EA stops running mid-schedule, whatever has already filled remains open and unmanaged; the remainder of the schedule simply never fires. - The clock starts the first time InpStartTrading is seen true after the EA is attached, not at the moment it is dragged onto the chart. - MQL5, netting accounts only: refuses to arm if a foreign-magic position already sits on the chart symbol, to avoid a silent merge.

Expert advisor · MT5 · v1.0 · Free

About Time Weighted Average Price Executor

Time Weighted Average Price Executor is an expert advisor (trading robot) for MetaTrader 5. It has 9 settings, such as Direction, Target lots and Slice count. MQL source code included.

Files in the download: TimeWeightedAveragePriceExecutor.ex5, TimeWeightedAveragePriceExecutor.mq5, TimeWeightedAveragePriceExecutor.txt.

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

Settings

SettingDefaultWhat it does
DirectionTWAP_BUYDirection to build
Target lots1.00Total position size to build
Slice count10Number of equal slices
Duration minutes60Total window the slices are spread across
Start tradingfalseMust be true for the EA to actually send orders
Magic number20261202Magic number identifying this build
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per slice before giving up on it
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria