Tick-Based Spread Distribution Profiler: Analyzing Historical Tick Data
Info
The Tick-Based Spread Distribution Profiler: Analyzing Historical Tick Data is a Indicator for MetaTrader 5 that tick-based spread distribution profiler (mql5 indicator)core ideamost retail spread indicators display only the current live spread or bar-level minimum spreads from m1 bars. This approach fails to account for critical spread behaviors such as rollover widening, news spikes, and execution risk during volatile periods.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Indicator works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Indicators folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Tick-Based Spread Distribution Profiler: Analyzing Historical Tick Data
1. Installation: Place your file in the MQL/Indicators folder via "Open Data Folder" and restart your terminal.
2. Loading: Find the indicator in the Navigator, drag it onto your chart, and configure the input parameters in the popup window.
3. Customization: Press Ctrl+I to open the indicator list, select your tool, and click "Properties" to change colors, levels, or visual styles.
4. Updating: Replace the old file in the Indicators folder with the new version and restart the platform to apply changes.
Frequently Asked Questions
Q: Why is my indicator not showing? A: Verify the file is in the MQL/Indicators folder, or try right-clicking the "Indicators" tree in the Navigator and clicking "Refresh."
Q: Do custom indicators slow down the platform? A: Too many complex indicators can impact performance; remove unused ones via the "Indicator List" (Ctrl+I).
Q: Can I use MT4 indicators on MT5? A: No, MQL4 and MQL5 are distinct languages; ensure the indicator is compiled specifically for your platform version.
What this tool does
Tick-Based Spread Distribution Profiler (MQL5 Indicator)Core IdeaMost retail spread indicators display only the current live spread or bar-level minimum spreads from M1 bars.
Typical Use Case
This Indicator excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Indicator works on MetaTrader 5. Place the file in the MQL5/Indicators folder and restart the terminal.
Description & Settings
Related: Candle Timer and Spread Indicator - another powerful indicator for MetaTrader 5 traders.
Tick-Based Spread Distribution Profiler (MQL5 Indicator)Core Idea
Also recommended: Ezo Candle Timer: Real-time Candle Expiry, Spread, and Daily Range - similar indicator with strong performance on MetaTrader 5.
Most retail spread indicators display only the current live spread or bar-level minimum spreads from M1 bars. This approach fails to account for critical spread behaviors such as rollover widening, news spikes, and execution risk during volatile periods. The Tick-Based Spread Distribution Profiler addresses this by extracting historical Bid/Ask ticks directly from your broker using the CopyTicksRange() function over a specified period (InpLookbackDays). It then constructs an empirical 24-hour spread distribution, showing P50 (median), P90, and P99 (extreme tail) values in a separate indicator subwindow.
To manage multi-week tick histories efficiently and prevent memory overflow, while also ensuring early data does not skew the results, each broker server hour employs an unbiased, deterministic reservoir sampling method (InpMaxSamplesPerHour).
How to Interpret the Indicator
1. Three Subwindow Plots (in Broker Points):
- Hourly P50 Median (Blue Histogram): Represents the typical spread encountered during each hour of the trading day.
- Hourly P90 (Orange Line): Indicates the 90th percentile spread. This value is useful for setting an Expert Advisor's (EA) MaxSpread filter. By setting the filter slightly above the active session's P90, 90% of trades can execute during liquid conditions while blocking trades during illiquid spikes.
- Hourly P99 (Crimson Dotted Line): Shows the extreme tail spread, which typically occurs during rollover periods or significant macroeconomic events.
2. Closed-Bar Spread / ATR Friction Ratio:
- This metric evaluates the Indicator Average True Range (iATR) strictly on the last closed bar (shift=1) of the specified InpAtrTimeframe. It reports the P50 spread as a percentage of the ATR (P50 / ATR %).
- This is helpful for intraday and scalping traders to assess whether broker spread costs represent an excessive portion of the typical candle range (e.g., exceeding 15% - 20%).
3. Compact Subwindow HUD:
- This display provides a summary of key metrics, including the total number of ticks profiled, the live spread, global P50/P90/P99 values, the current hour's P50/P90, the Spread/ATR ratio, and the best (lowest) P50 and worst (highest) P90 server hours.
External Input Parameters
- InpLookbackDays (default 14): The number of past days for which historical broker tick data will be requested via CopyTicksRange().
- InpMaxSamplesPerHour (default 50000): The maximum reservoir sample size per server hour (00-23) to ensure bounded memory usage.
- InpAtrTimeframe (default PERIOD_M15): The reference timeframe used for the closed-bar ATR friction calculation.
- InpAtrPeriod (default 14): The ATR averaging period, evaluated at shift=1 to avoid repainting.
- InpRefreshMinutes (default 60): The interval in minutes between full tick-history recalculations. The indicator does not run calculations on every tick.
- InpShowSummaryHUD (default true): A toggle to show or hide the summary panel within the indicator subwindow.
- InpExportCSV (default false): If enabled, exports the 24-hour spread profile data (Min, P50, P90, P99, Max, tick counts) to a CSV file located in MQL5\Files\SpreadProfile_
Recommended Usage
Attach this indicator to any symbol and timeframe (M15 or H1 are commonly recommended). The indicator requires the broker to provide historical tick data for the selected symbol. All allocated handles and graphical objects are properly released in the OnDeinit() function.
You may also like: Spread and Liquidity Clock: Time-of-Day Cost-to-Range Profile - excellent alternative for indicator users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_label1 "Hourly P50 Spread (pts)"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrSteelBlue
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.