Spread Profile by Hour

  • Utilitaires
  • Quoc Dat Quach
    Quoc Dat Quach
    Software engineer with 8 years in fintech and mobile, writing MQL4/MQL5 since 2017. I build Expert Advisors, indicators, trade and risk-management panels and utilities for MT4/MT5, and I trade forex and gold on MT5 myself.
  • Version: 1.0

Spread Profile by Hour builds the spread distribution of one symbol for every hour of the server day from your broker's own tick history, and draws it as 24 bars. The solid part of a bar is the median spread of that hour, the lighter cap reaches the 90th percentile. Enter the stop size you normally use and every bar is labelled with its median spread as a share of that stop, so the cost is in the same unit as your risk.

It is a measuring tool. It places no orders, uses no DLL and no WebRequest, and writes no file except the CSV export you switch on.

Why it exists: for intraday and scalping rules the spread, not the entry signal, often decides whether an edge survives. The terminal shows the spread of this moment, and bar history keeps a single spread value per bar, which hides what happened inside the hour. The same rules can work in quiet hours and lose at the daily rollover or at a session open simply because the spread there is several times wider. This indicator reads the quotes themselves - every bid and ask tick of the last N calendar days through CopyTicksRange - and groups them by the hour of the day in server time.

What it computes for every server hour, over the last N calendar days with today excluded, so the picture does not shift while you are trading:

  • Median and 90th percentile spread in points for every hour on the panel; mean, maximum and the number of quotes behind each hour in the CSV export.
  • Two sampling modes. Tick count: every quote counts once. Time-weighted: every quote counts for the time it stayed valid, up to 60 seconds. Tick counting over-represents fast markets, and fast markets often carry wide spreads; time weighting answers what spread you would have met at a random moment of that hour.
  • A weekday filter, Monday to Friday, for rules that trade only one day of the week; raise the history depth with it, since 20 calendar days hold only two or three of one weekday.
  • The cost view: with a stop size in points entered, every bar is labelled with the median spread as a percentage of that stop, and the header shows the current hour's median and 90th percentile in the same unit. When the window is too narrow for a label on every bar, only the bar with the highest median keeps its label.
  • The median spread of the current hour in account currency per 1.00 lot, from the symbol's tick value and tick size.
  • The hours at both ends of the median ranking, up to three each, in the header. Hours that share a median are listed together or summarised, for example "Cheapest: 23 hours at 6 pt", so equal values are never presented as a ranking; if every hour has the same median the header says so.
  • The current server hour highlighted and the live spread drawn as a dashed line across the bars.
  • Optional CSV export of the per-hour table to MQL5\Files\SpreadProfile_<symbol>_<yyyymmdd>.csv in UTF-8, written after each calculation.

How it treats the tick history, which is the part that decides whether the numbers can be trusted: one day is loaded per timer step and released straight away, so the chart stays responsive on gold or crypto with more than 100,000 ticks a day. A day the terminal is still downloading is retried for a few seconds, and a day whose ticks do not cover its own M1 bars is retried before it is used. Days are read from the most recent backwards. When three trading days in a row return no ticks (with a weekday filter, three consecutive days of that weekday), or ten in a row have neither ticks nor M1 bars, those days are read a second time after a pause, and if they are still empty the load stops and the header shows the date of the oldest day actually used; a gap of that length inside the broker's tick storage ends the load the same way. The header also counts days used as partial, meaning ticks that did not reach the last M1 bar, and days unavailable, meaning M1 bars but no ticks. A symbol with no tick history at all reports that within about twenty seconds instead of drawing an empty panel. The journal gets one summary line per calculation - days used, ticks read, hours filled - plus one line naming the CSV file when the export is on.

How to read the panel. Each bar is one hour of the day in server time. The solid part is the median: half of the quotes, or half of the time in time-weighted mode, had a spread at or below it. The lighter cap is the 90th percentile: one quote in ten was wider than that. Measurements from the screenshots, taken on a demo account over 20 calendar days of which 17 had ticks:

  • EURUSD, tick count, 50-point stop: the median is 6 points in 23 of the 24 hours. At 21:00 server time, the daily rollover, it is 34 points with a 90th percentile of 58. That is 12 percent of the stop for most of the day and 68 percent in that one hour.
  • GBPUSD, time-weighted, no stop entered: 7 points in 23 hours, median 46 and 90th percentile 94 at 21:00. In tick-count mode the same hour reads 54 and 100, because quotes cluster around the rollover, where the spread is wide.
  • XAUUSD, tick count, 1500-point stop: the median is 182 points in every hour that has data, which is 12 percent of the stop and 18.20 USD per 1.00 lot, so the header states that instead of ranking equal values. The daily break at 21:00 has fewer than the minimum ticks and is shown as a dash.

The practical use is a decision about hours: if your system trades in an hour where the median spread is a large share of your stop, either skip the hour, widen the stop, or check that the expected move pays for it. The 90th percentile shows what a bad but not rare fill looks like.

Independent check. The per-hour statistics were recomputed from the same raw ticks by a separate Python implementation. Median, 90th percentile, mean, maximum and tick count matched for every hour in both sampling modes, for example EURUSD 20:00 with 10,692 ticks and 21:00 with 8,097 ticks, and GBPUSD 21:00 in both modes. Load tests on the same machine: 20 days of XAUUSD, 4.29 million ticks, in 1 to 3 seconds; 60 days filtered to Mondays, 2.60 million ticks, in 1.3 seconds; 365 days of EURUSD, 9.37 million ticks over 232 days with ticks, in about 30 seconds including the second reading of the days before the tick history begins. Your times depend on your broker's tick density and on whether the ticks are already on disk.

Inputs: history depth in calendar days (1 to 365, default 20), sampling mode, weekday filter, histogram range in points with an overflow bin, minimum ticks for an hour to be shown, stop size in points (0 turns the percentage labels off), window height, seven colours of which four are derived automatically when left on None (background from the chart, text and grid from that background, the 90th-percentile cap from the bar colour), font size, and the CSV switch. Every input is documented by its own comment in the terminal.

Notes and limits. Tick history depth depends on your broker and on what the terminal has already downloaded. On the very first run over a long depth the terminal may still be downloading ticks; a day that is still arriving is retried for a few seconds and then used as partial or skipped, so if the load stops early, re-attach the indicator once the download has finished - the second run reads from disk. All hours are server hours, so an event such as the rollover can move by one server hour between summer and winter time, and a window that spans the switch shows it split across two neighbouring hours. Demo and live accounts, and standard, raw and zero account types, can have very different spreads for the same symbol - measure on the account you trade. Spread history does not predict future spreads: news, holidays and thin liquidity can produce spreads well above the 90th percentile shown here. The cost per lot uses the current tick value, which for cross pairs moves with the exchange rate. The profile is recalculated once per new server day and whenever the inputs, the symbol or the timeframe change. The indicator opens in a separate window and several copies can run on one chart, each in its own window.

Plus de l'auteur
A local trade copier for MetaTrader 5. It copies positions between MT5 terminals on the same Windows PC or VPS and sizes each copy from both brokers' contract specifications (contract size, tick value, account currency), so a copy carries the same exposure even when the two brokers define a lot differently. It never opens a second copy of the same master position. What it does You attach the same EA to one chart in each terminal: In the master terminal, set the Mode input to Master. In each rece
Symbol Spec Auditor puts the part of a symbol's contract specification that decides position size and trading cost into one panel on the chart: point value, spread cost, margin, swap, execution rules and trading sessions. Raw specification values are converted into money per 1.00 lot in the account currency, and the broker settings that quietly break lot-size code are listed as warnings. One button exports the same audit for every Market Watch symbol to a CSV file. It is a checking tool. It plac
FREE
Repaint Inspector measures whether an indicator repaints instead of taking the claim on trust. You attach it to a chart, name any custom indicator and its parameter list, and it re-reads that indicator's buffers on bars that have already closed, counting every value that moves, every value that appears and every value that disappears, together with how far back in history that still happens. It is a measuring tool. On a chart it never sends an order. In the Strategy Tester it opens and closes on
FREE
An account ledger for MetaTrader 5 that splits your results by magic number, symbol, weekday and hour, shows price P/L, commission, swap and fees in separate columns, and measures the spread paid at each fill and the slippage against the price you asked for. The totals are checked against the account balance on every update. It never trades on a chart. What it does Attach it to one chart. It reads the account's deal history, rebuilds every position from its deals and shows the result on a panel:
Filtrer:
Aucun avis
Répondre à l'avis