Loading…

Cost Stress Tester

A backtest run on a demo feed with a tight spread and no commission can report an edge that a live account, with a wider real spread and a per-lot commission, would not actually deliver. This EA does not change how orders are executed - it estimates, per closed trade, what that same trade would have cost under harsher, user-specified assumptions, and keeps a running "stress-adjusted" total next to the broker's own reported profit. The estimate is built from four inputs: extra spread (charged once per round turn), extra slippage (charged on both the entry and the exit), a flat commission per lot, and a swap-like cost per lot per day held. All four convert to money through the symbol's tick value and tick size rather than a hardcoded contract size, and all four scale with the trade's own lot size - never a flat number - so the estimate stays correct whether the strategy trades 0.01 lots or 5. Each closed trade is counted exactly once by tracking the highest order ticket already folded into the totals, because MODE_HISTORY is not guaranteed to list closed orders in ticket order and re-scanning the whole history on every tick would otherwise double count. The underlying strategy is a plain fast/slow EMA crossover, deliberately unremarkable - the point of this EA is the cost model, not the signal. Notes and limitations - The stress cost is an estimate layered on top of what actually happened, not a change to execution - real spread, slippage and swap from the broker or tester are still whatever they were. - One position at a time under this magic number. - The placeholder signal has no claimed edge; it exists only to generate trades for the cost model to stress. - Swap direction (long vs short, positive vs negative) is not modelled separately - InpStressSwapPerLotPerDay is applied as a flat extra cost regardless of trade direction. - Requires AutoTrading enabled when run live rather than in the tester. MQL4 checks IsTradeAllowed(); MQL5 checks TERMINAL_TRADE_ALLOWED, ACCOUNT_TRADE_ALLOWED and ACCOUNT_TRADE_EXPERT, since MQL5 has no single equivalent call. - The MQL5 ledger assumes each position closes in one exit deal (no partial closes); see MQL4 VERSUS MQL5 DIFFERENCES above.

Expert advisor · MT4 · v1.0 · Free

About Cost Stress Tester

Cost Stress Tester is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It has 13 settings, such as Lots, Fast ma period and Slow ma period. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Lots0.10Fixed lot size for the placeholder signal
Fast ma period10Fast EMA period for the placeholder signal
Slow ma period30Slow EMA period for the placeholder signal
Stop loss pips30Stop loss per trade, in pips
Take profit pips45Take profit per trade, in pips (0 = none)
Stress extra spread pips2.0Extra spread simulated on top of the broker's own, in pips
Stress extra slippage pips1.0Extra slippage simulated per entry AND exit, in pips
Stress commission per lot7.0Extra round-turn commission simulated, in account currency per lot
Stress swap per lot per day0.0Extra overnight cost simulated, in account currency per lot per day held
Magic number20260831Magic number for orders opened by this EA
Slippage pips3Real slippage tolerance sent with orders, 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: Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria