Loading…

Tick Run Length Sampler

Many tools that filter on "N ticks in the same direction" or trigger after a streak quietly assume tick-to-tick direction behaves like a coin flip. Real feeds usually do not - short runs of same-direction ticks are more or less common than pure randomness would predict, broker to broker and symbol to symbol, and the only way to know which is to measure it on the actual feed being traded. This script does that directly: every time the Bid price changes, it is classed as an uptick or a downtick, and consecutive same-direction ticks are counted as one run. A tick with no price change (Ask-only or volume-only updates that some feeds send) neither extends nor breaks a run, since counting those as reversals would understate real run lengths for no good reason. At the end of the sampling window the script reports, separately for up-runs and down-runs, how many runs occurred, the longest one, and the average run length - and can optionally write the full length histogram to a CSV for closer inspection. Notes and limitations - Only the current chart's symbol is watched. - Runs longer than 50 ticks are folded into the length-50 bucket in the CSV histogram so the bucket table stays a fixed size; the longest-run summary line in the Experts log is not capped and always shows the true longest run. - The script occupies the calling thread for its entire duration and cannot run in the background the way an indicator or expert can. - This measures the Bid stream only.

Script · MT5 · v1.0 · Free

About Tick Run Length Sampler

Tick Run Length Sampler is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Duration minutes, Poll interval ms and Save csv. MQL source code included.

Files in the download: TickRunLengthSampler.ex5, TickRunLengthSampler.mq5, TickRunLengthSampler.txt.

Settings

SettingDefaultWhat it does
Duration minutes10How long to watch the feed, minutes
Poll interval ms50Poll frequency for new ticks, milliseconds
Save csvtrueWrite the run-length histogram to a CSV

How to install

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

MQL4 & MQL5 scripts · PolyMaria