Cost Sensitivity Curve Builder
A backtest's assumed spread and commission are rarely what a strategy actually pays live - real conditions are usually worse, and it is easy to not know by how much before the edge disappears. This tool pulls this account's closed-trade history (profit + swap + commission per trade, filtered by symbol/magic), then sweeps an ADDITIONAL round-turn cost assumption in points across a configurable range, recomputing the mean net expectancy per trade at each level. The result is drawn as a small bar chart - green bars above a zero line for a still-profitable cost level, red bars below it once the extra cost tips the mean negative - plus a reported "breakeven extra cost" found by linear interpolation across the first sign change. Every cost figure is converted to money through that specific trade's OWN symbol's live MODE_TICKVALUE/MODE_TICKSIZE/MODE_POINT and its own lot size, never a single assumed points-to-money ratio - this matters as soon as the trade history spans more than one instrument, since a JPY cross, an index CFD and a majors pair can have very different money-per-point figures. Notes and limitations A trade whose symbol is not currently available in Market Watch (so MarketInfo returns 0 for tick value/size) is silently excluded from the sample rather than mispriced - this can understate the trade count for a multi-symbol history checked on a chart with few symbols subscribed. The sweep only models an EXTRA round-turn cost on top of whatever the trades already paid; it cannot separate out how much of the original recorded cost was spread versus commission versus slippage, so it answers "how much more room is there" rather than "what was the original cost breakdown." The bar chart uses screen-pixel-anchored rectangle label objects, not price-anchored lines, so it stays legible regardless of chart scroll or zoom.
Expert advisor · MT5 · v1.0 · Free
About Cost Sensitivity Curve Builder
Cost Sensitivity Curve Builder is a script for MetaTrader 5. It has 13 settings, such as Corner, X offset and Y offset. MQL source code included.
Files in the download: CostSensitivityCurveBuilder.ex5, CostSensitivityCurveBuilder.mq5, CostSensitivityCurveBuilder.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Corner | 0 | Panel corner: 0=top-left 1=top-right 2=bottom-left 3=bottom-right |
| X offset | 12 | Panel offset from the chosen corner, X pixels |
| Y offset | 18 | Panel offset from the chosen corner, Y pixels |
| Symbol filter | Only trades on this symbol; blank = every symbol in history | |
| Magic filter | 0 | Only trades with this magic number; 0 = every magic |
| Max trades | 2000 | Cap on how many most-recent closed trades are pulled from history |
| Cost min points | 0.0 | Smallest EXTRA round-turn cost swept, in points |
| Cost max points | 50.0 | Largest EXTRA round-turn cost swept, in points |
| Cost steps | 11 | Number of cost levels swept between min and max (inclusive) |
| Bar width px | 18 | Pixel width of each bar in the chart-drawn curve |
| Max bar height px | 100 | Pixel height of the tallest bar (auto-scaled to the largest |value|) |
| Write report file | true | Also write the full swept curve to MQL5\Files\ as CSV |
| Report file name | CostSensitivityCurve.csv | Output file name (only used if InpWriteReportFile) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT5 Expert Advisor · MQL5 Source Code