Tollgate Spread Atlas
- Utilities
-
Syarief Azman Bin Rosli
Hello and welcome to my official MQL5 profile!
I am Syarief Azman Bin Rosli, an algorithmic trading systems developer and quantitative software engineer with over a decade of specialized experience creating robust automated trading solutions for MetaTrader 5 and MetaTrader 4. - Version: 1.0
- Activations: 10
Tollgate Spread Atlas shows what trading really costs on your broker. It reads the real tick history of the chart symbol and up to 8 watchlist symbols, builds an hour-of-week spread map (Monday to Friday, 24 server hours), compares the live spread with the typical spread for the current hour, and turns spread, commission and swap into round-trip cost and cost as a share of ATR on six timeframes. It is read-only: it never opens, modifies or closes trades.
Quick Start
- Attach the utility to any chart (for example XAUUSD or EURUSD). No Algo Trading permission is needed because it never trades.
- The cockpit shows SCANNING TICK HISTORY with a SCAN percentage while it reads the history (Lookback Window, default 28 days). The first scan can take a minute while the terminal downloads ticks.
- When the scan ends, the live card shows LIVE SPREAD, TYPICAL, RATIO and a status: CHEAP, NORMAL, WIDE or SPIKE.
- Set Cost Calculator Lot Size to your usual lot and choose the Commission Source.
- To check it works, hover a heatmap cell (tooltip) or press CSV to save the atlas.
How the atlas is built
- Every quote's spread (ask minus bid, in whole points) counts for the seconds until the next quote, capped by Max Seconds Credited Per Quote, so gaps and closed markets add nothing. Busy and quiet minutes are weighted by time, not by tick count.
- Each cell (weekday x server hour) keeps a spread distribution. MEDIAN, P90 (90th percentile) and MEAN (time-weighted mean) come from it. Values are exact up to 31 points, then in 16 steps per doubling (the lower edge is shown).
- Typical spread = median of the current cell. If the cell has less than Minimum Coverage For A Cell, the same hour on all weekdays is used, then the whole week. The source is shown as [CELL], [HOUR] or [WEEK].
- With Add Live Quotes To The Atlas on, the current spread of every symbol is added once per second while its quote is fresh.
- The atlas is rebuilt from history once per server day at Daily Rebuild Hour (to roll the window), and when you press RESCAN.
Status rules
RATIO = live spread / max(typical, 1 point). Excess = live minus typical.
- SPIKE: RATIO at or above SPIKE From and excess at or above Minimum Excess For WIDE / SPIKE.
- WIDE: RATIO at or above WIDE From and the same excess rule.
- CHEAP: RATIO below CHEAP Below.
- NORMAL: everything else.
- NO DATA: no quote yet, or no typical spread.
The excess rule keeps raw or ECN accounts (typical 0-2 points) from flagging tiny changes.
Cockpit
Header
- LED: green or teal (NORMAL, CHEAP), amber (WIDE or scanning), red (SPIKE), grey (NO DATA).
- TOLLGATE SPREAD ATLAS, the focus symbol and SERVER TIME (all hours are broker server time).
- [-] minimizes the cockpit to a pill showing TSA, the symbol, ratio and status; [+] restores it.
Live card
- LIVE SPREAD in points (and pips on 3/5-digit symbols).
- TYPICAL with its source [CELL], [HOUR] or [WEEK]; RATIO; the status badge.
- Meter from 0 to 3x the typical spread (METER 0-3x), with white marks at CHEAP Below, WIDE From and SPIKE From.
- TODAY MAX: widest spread since server midnight; the number of quotes read; the lookback days.
Cost card (ROUND-TRIP COST, account currency)
- SPREAD: spread cost for the lot size at the live and at the typical spread (points x tick value x point / tick size x lots).
- COMMISSION per lot per side with its source: [HISTORY] (from your deals), [FIXED] or [NONE].
- TOTAL: live and typical round trip (spread + 2 x commission x lots), and the live total in points.
- SWAP / NIGHT long (L) and short (S) for the lot size and the triple-swap day (3x WED). Swaps in points or in the deposit currency are converted; other swap modes show the raw value with the unit (currency/LOT, %/YEAR or RAW). SWAP OFF when swaps are disabled.
- COST / ATR: live round-trip cost in price divided by ATR of the last closed bar, x 100, for M1, M5, M15, H1, H4 and D1. Green below 5%, amber 5-15%, coral 15% and above; the bar is full at 30%. A high value means the cost eats a large part of a typical bar on that timeframe.
Toolbar
- METRIC: MEDIAN / METRIC: P90 / METRIC: MEAN cycles the heatmap metric.
- RESCAN reloads commission and rebuilds every atlas from history.
- CSV saves the focus atlas (after the scan) to MQL5\Files\Tollgate_<SYMBOL>.csv.
- ALERTS ON / ALERTS OFF switches spike alerts for this session.
- click cell = pin: reminder that heatmap cells can be pinned.
Button changes return to the input values when the utility is re-initialized (timeframe change, re-attach, restart).
Heatmap (HOUR-OF-WEEK ... SPREAD)
- Rows MON to FRI, columns 00-23 server hours. Colour = cell value / the same metric over the whole week (shown as WEEK MEDIAN, WEEK P90 or WEEK MEAN): teal 0.6x or less, green 1.0x, gold 1.6x, coral 2.6x or more. Dark cells = no data (coverage below the minimum).
- Gold border = the current hour (now). White border = pinned cell.
- Tooltip: median, P90, mean and coverage of the cell. Click a cell to pin it; click again to unpin.
- Detail line: NOW (current cell) or PINNED with MEDIAN, P90, MEAN and COVERAGE.
- CHEAPEST HOURS and DEAREST HOURS: the three server hours with the lowest and highest time-weighted mean spread across all weekdays.
- Weekend quotes count in the HOUR and WEEK values but are not drawn. The map refreshes every 30 seconds.
Watchlist
Columns WATCHLIST, LIVE, TYPICAL, RATIO, STATUS and COST/ATR H1 (live round trip vs H1 ATR). Click a row to make that symbol the focus of the whole cockpit (highlighted row). NOT FOUND = the broker has no such symbol; SCANNING = its history is still loading; no watchlist symbols when the list is empty.
Alerts
When a symbol (chart or watchlist) stays at SPIKE for SPIKE Must Last seconds, one alert is sent per symbol per Alert Cooldown, for example: [Tollgate Atlas] XAUUSD spread SPIKE 51 pts = 5.1x typical 10 pts (THU 23:00 server) It is printed to the Experts log and sent by Terminal Pop-Up Alerts, Audible Alerts (alert.wav, only when pop-ups are off because the pop-up has its own sound) and Push Notifications To Mobile (MetaQuotes ID set under Tools, Options, Notifications).
Flags for other EAs (terminal global variables)
With Publish Terminal Global Variables on, every second after the scan, for each symbol:
- TSA_<SYMBOL>_RATIO: live / typical.
- TSA_<SYMBOL>_TYPICAL: typical spread in points (-1 = no data).
- TSA_<SYMBOL>_OK: 1 = CHEAP or NORMAL, 0 = WIDE or SPIKE, -1 = NO DATA.
They are deleted when the utility is removed.
if(GlobalVariableCheck("TSA_EURUSD_OK") && GlobalVariableGet("TSA_EURUSD_OK") == 0)
return; // spread is WIDE or SPIKE: skip new entries Side effects
- Adds watchlist symbols to Market Watch. Creates chart objects named with the Object Name Prefix (removed with the utility). Uses a 250 ms timer.
- Writes a file only when CSV is pressed: 168 rows with day, hour, median_pts, p90_pts, mean_pts, coverage_min (-1 = no data).
Inputs
- Lookback Window (28, 3-90 calendar days): history read per symbol.
- Max Seconds Credited Per Quote (60, 5-600): cap per quote.
- Minimum Coverage For A Cell (15 minutes): below it a cell is no data and the typical falls back.
- Heatmap Metric (Median Spread): Median Spread, 90th Percentile Spread or Time-Weighted Mean Spread at start.
- Add Live Quotes To The Atlas (true): live learning.
- Daily Rebuild Hour (3, server time, -1 = never): daily rebuild after rollover.
- CHEAP Below (0.85), WIDE From (1.5), SPIKE From (2.5): ratio thresholds.
- Minimum Excess For WIDE / SPIKE (5 points).
- Cost Calculator Lot Size (1.0).
- Commission Source (From Account History): From Account History, Fixed Per Lot Per Side or No Commission.
- Fixed Commission (3.5 per lot per side): also the fallback when the history has no deals.
- Commission History Window (90 days).
- ATR Period For Cost Burden (14).
- Watchlist Symbols ("EURUSD,GBPUSD,USDJPY,XAUUSD", max 8, exact broker names with suffixes).
- Alert On SPIKE (true), SPIKE Must Last (5 s), Alert Cooldown (15 minutes).
- Terminal Pop-Up Alerts (true), Push Notifications To Mobile (false), Audible Alerts (true).
- Publish Terminal Global Variables (true).
- Object Name Prefix ("TSA_"): change it to run two copies on one chart.
- HUD Chart Corner (Top Left; Top Right, Bottom Left, Bottom Right), HUD X Offset (16), HUD Y Offset (24) in pixels.
- Panel Scale (1.0, 0.5-2.5): size multiplier on top of Windows display scaling.
- Start Minimized (false).
Typical setups
- M1 scalper: Heatmap Metric 90th Percentile Spread, WIDE From 1.3, SPIKE From 2.0, Minimum Excess For WIDE / SPIKE 2; trade the CHEAPEST HOURS and check COST / ATR on M1.
- Gold: Lookback Window 42, SPIKE From 3.0, Minimum Excess For WIDE / SPIKE 15, Alert Cooldown 30, Push Notifications To Mobile true.
- Raw or ECN account: Heatmap Metric Time-Weighted Mean Spread, Commission Source From Account History, Minimum Excess For WIDE / SPIKE 5.
- EA gate: Alert On SPIKE false, Publish Terminal Global Variables true, and the snippet above in your EA.
Notes and limitations
- History depth depends on the broker; some keep only a few weeks of ticks.
- In the Strategy Tester the atlas comes from the tester's ticks: use "Every tick based on real ticks" to see real spreads.
- Spreads differ between brokers and account types, and past spreads do not guarantee future spreads. The utility measures costs; it does not predict prices or results. Trading involves risk of loss.
