Loading…

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

SettingDefaultWhat it does
Corner0Panel corner: 0=top-left 1=top-right 2=bottom-left 3=bottom-right
X offset12Panel offset from the chosen corner, X pixels
Y offset18Panel offset from the chosen corner, Y pixels
Symbol filterOnly trades on this symbol; blank = every symbol in history
Magic filter0Only trades with this magic number; 0 = every magic
Max trades2000Cap on how many most-recent closed trades are pulled from history
Cost min points0.0Smallest EXTRA round-turn cost swept, in points
Cost max points50.0Largest EXTRA round-turn cost swept, in points
Cost steps11Number of cost levels swept between min and max (inclusive)
Bar width px18Pixel width of each bar in the chart-drawn curve
Max bar height px100Pixel height of the tallest bar (auto-scaled to the largest |value|)
Write report filetrueAlso write the full swept curve to MQL5\Files\ as CSV
Report file nameCostSensitivityCurve.csvOutput file name (only used if InpWriteReportFile)

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria