Loading…

Tick, Volume And Dollar Imbalance Bars

A time bar samples the market every N minutes regardless of what actually happened in that window - dead during a quiet session, badly undersampled during a spike. Information-driven bars sample by activity instead: a bar closes the instant enough signed order flow has accumulated, whatever that takes in wall-clock time. This header implements the imbalance family from "Advances in Financial Machine Learning" chapter 2 - tick imbalance bars, volume imbalance bars and dollar imbalance bars are the same algorithm, parametrised only by what each tick is weighted by: 1, traded volume, or traded value. Every tick is signed with the classic tick rule: a price higher than the previous tick is +1, lower is -1, and an unchanged price carries the previous sign forward - ticks never go unsigned. The running signed, weighted sum inside the forming bar is theta. A bar closes when the absolute value of theta crosses an EXPECTED threshold, and the threshold is not a fixed constant - it is re-estimated after every completed bar from an exponential moving average of how many ticks recent bars took and how imbalanced they typically were. Markets that suddenly get more one-sided produce shorter bars automatically; markets that calm down produce longer ones, without touching a parameter. The algorithm needs a warm-up: the very first bar has no prior bars to estimate a threshold from, so it closes on a plain tick-count floor instead, and every bar after that adapts. This is stated as an explicit two-branch condition in the code rather than papered over with an arbitrary starting guess, because a wrong starting guess would silently bias the first several bars. Neither MT4 nor MT5 exposes a real trade tape by default, only quote ticks, and only some symbol types report non-zero tick volume. This header applies the tick rule to the traded price and uses tick volume as the size proxy for the volume and dollar weightings on both platforms identically - the same practical compromise most retail Forex implementations of this technique make. It is stated here plainly rather than left implicit, because pretending otherwise would misrepresent what the numbers mean. Notes and limitations - The tick rule and the imbalance weighting are both computed from Bid/tick volume, not from an actual trade tape - neither MT4 nor MT5 provides one by default. Treat the output as a well-established proxy, not a literal reconstruction of the order book. - Symbols that report zero tick volume make IMBALANCE_VOLUME and IMBALANCE_DOLLAR degenerate to a constant zero weight; use IMBALANCE_TICK on such symbols, or verify SymbolInfoTick().volume is genuinely non-zero first. - The demo's four-ticks-per-bar replay from O/H/L/C is a reasonable stand-in for missing tick history, not a claim that real intrabar movement only ever visits those four points - a live OnTick feed gives a materially richer signal than this demo can show from stored M1 bars alone. - The adaptive threshold takes a handful of bars to settle after Reset() or after switching symbols; expect the first few post-reset bars to vary more in length than later ones. - This header only classifies and buckets ticks into bars - it does not compute indicators or trade signals from the resulting bar series.

Script · MT4 · v1.0 · Free

About Tick, Volume And Dollar Imbalance Bars

Tick, Volume And Dollar Imbalance Bars is a script for MetaTrader 4. It has 3 settings, such as Lookback bars, Initial ticks per bar and Ewma alpha. MQL source code included.

Files in the download: InformationDrivenBars.mqh, InformationDrivenBars.txt, InformationDrivenBarsDemo.mq4.

Settings

SettingDefaultWhat it does
Lookback bars300How many M1 bars of history to replay as synthetic ticks
Initial ticks per bar40Warm-up bar length before the adaptive threshold kicks in
Ewma alpha0.15EWMA speed for the adaptive threshold, 0..1

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Volume · Trading Sessions · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria