Loading…

Last Digit Bias Analyzer

A quoting engine that genuinely picks its final digit at random should show each of the ten digits (0 through 9) roughly equally often over a large enough sample. Some dealing-desk or synthetic feeds visibly do not - a last digit that favours round numbers, or clusters on a handful of values, is a real and previously documented pattern, and it is exactly the kind of thing a frequency table alone tempts a trader into either overreading noise as bias or dismissing real bias as noise. This script settles the question properly. It samples the live Bid feed for a chosen duration, buckets every observed price by its final digit, and runs a genuine chi-square test against the uniform-digit null hypothesis, with nine degrees of freedom (ten categories minus one). MQL4 has no built-in chi-square distribution function, so the p-value is approximated with the Wilson-Hilferty cube-root normal transform feeding an Abramowitz & Stegun normal-tail polynomial - a standard, well- documented approximation accurate to roughly two significant figures, which is ample for answering "is this biased at the 5%/1% level" rather than needing an exact p-value to the fourth decimal. The raw chi-square statistic is always printed alongside the approximate p-value, so a result near a significance boundary can be checked by hand against a printed chi-square table rather than trusted blindly. Notes and limitations - Only the current chart's symbol is watched, and only the Bid stream. - The p-value is an approximation (Wilson-Hilferty), not an exact chi-square CDF evaluation - accurate enough for a significance call but not for reporting a precise p-value in a paper. - A short sampling window on a quiet symbol may not collect enough distinct ticks for the test to be meaningful; the script warns when the sample falls below InpMinSampleSize but does not refuse to report. - The script occupies the calling thread for its entire duration and cannot run in the background the way an indicator or expert can.

Script · MT4 · v1.0 · Free

About Last Digit Bias Analyzer

Last Digit Bias Analyzer is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Duration minutes, Poll interval ms and Min sample size. MQL source code included.

Files in the download: LastDigitBiasAnalyzer.mq4, LastDigitBiasAnalyzer.txt.

Settings

SettingDefaultWhat it does
Duration minutes10How long to sample the feed, minutes
Poll interval ms50Poll frequency for new ticks, milliseconds
Min sample size100Minimum ticks required before the test is trusted
Save csvtrueWrite the digit frequency table to a CSV

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: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria