Simulation Seam Template
Testing whether an EA's WIRING is correct - does it call the right functions in the right order, does it size and log correctly - usually means either running Strategy Tester (slow to iterate on, and only available offline) or attaching to a live/demo chart and waiting for the market to move. This template adds a third option: a synthetic data source you can watch tick on any chart, market open or closed, without ever risking a real order. The mechanism is a seam - a small set of functions (SeamGetBid, SeamGetAsk, SeamGetTickValue, SeamGetTickSize, SeamSubmitOrder, SeamSma) that the strategy function (EvaluateStrategy) calls exclusively. Which concrete source answers those calls is decided in one place, SeamAdvance, based on InpDataSource: LIVE reads real MarketInfo()/Bid/Ask and sends real orders through OrderSend with normal risk-percent sizing. MOCK generates a deterministic synthetic price walk from a seeded linear congruential generator - the same InpMockRandomSeed always produces the same sequence, so a "mock run" is reproducible run to run, unlike MathRand() which reseeds from the system clock. FILE replays bid;ask;tickvalue;ticksize rows from a CSV in MQL4\Files\ (or MQL5\Files\ on the native MQL5 build), useful for feeding a specific historical or hand-crafted sequence through the exact same strategy code. MOCK and FILE never send a real order - they run a paper ledger entirely in memory (one position at a time, SL/TP checked against the seam's own price on every tick) and log simulated fills to the Experts log. Only LIVE ever reaches the trade server. This is not a substitute for Strategy Tester's historical accuracy; it exists specifically to validate that the strategy's OWN CODE behaves correctly against a controlled, watchable feed, independent of what the real market happens to be doing right now. Notes and limitations - MOCK and FILE sources never place a real order - they maintain an in-memory paper ledger and print simulated fills. Only LIVE reaches the trade server; check this input carefully before attaching to a funded account. - The paper ledger's P/L estimate reads the real MODE_LOTSIZE for the attached symbol so it is not a hardcoded contract size, but it is still an estimate - it does not model spread cost beyond the mock/replay spread itself, swap, or commission. - The seam's SMA (SeamSma) is computed over its own rolling buffer, not real historical bars, so its warm-up period is measured in ticks received since attach, not calendar time - it will read as "not warmed up" for a while after every attach, including on LIVE. - FILE source stops (SeamAdvance returns false) once the CSV is exhausted; the EA then holds its last known state on-chart rather than looping the file automatically.
Expert advisor · MT4 · v1.0 · Free
About Simulation Seam Template
Simulation Seam Template is an expert advisor (trading robot) for MetaTrader 4. It opens a grid of orders at fixed price steps and can size trades from your balance and risk percent. It has 12 settings, such as Data source, Replay file name and Mock start price. MQL source code included.
Files in the download: SimulationSeamTemplate.ex4, SimulationSeamTemplate.mq4, SimulationSeamTemplate.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Data source | SOURCE_MOCK | Which seam implementation drives the strategy |
| Replay file name | SimulationSeamTemplate_ticks.csv | FILE source: bid;ask;tickvalue;ticksize rows |
| Mock start price | 1.10000 | MOCK source: starting synthetic price |
| Mock step pips | 0.8 | MOCK source: max random step per tick, in pips |
| Mock spread pips | 1.2 | MOCK source: fixed synthetic spread, in pips |
| Mock random seed | 20260817 | MOCK source: seed, so a "mock run" is reproducible |
| Fast ma period | 5 | Strategy: fast SMA period, computed over the seam's own price buffer |
| Slow ma period | 20 | Strategy: slow SMA period |
| Risk percent | 1.0 | LIVE only: risk per trade, percent of equity |
| Stop loss pips | 25 | Stop-loss distance in pips (real order or paper ledger alike) |
| Take profit pips | 50 | Take-profit distance in pips |
| Magic number | 49200 | Magic number for LIVE orders |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Grid · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code