Skip to content
All library documents

Measuring Runs of Consecutive Bullish and Bearish Candles

Article MQL5 code base

Summary

This script counts consecutive runs of bullish and bearish bars over a user-selected window and plots the distribution. Each run is represented by a signed value: positive for bullish sequences and negative for bearish ones, with the magnitude equal to the number of consecutive bars. The results can also be printed for verification and the chart can be saved as an image.

The document describes configurable inputs for the number of bars, diagnostic output, screenshot saving, and display delay, and illustrates charts for several instruments and timeframes. It excludes the most recent run because that sequence may still be in progress, so the counts describe completed runs only. The examples are descriptive rather than evidence of a profitable strategy: the document gives no statistical inference, benchmark, or trading rule based on the plotted frequencies. Such run counts can help inspect price behavior, but their interpretation depends on instrument, timeframe, and sample selection.

Key ideas

  • Bullish and bearish candle runs are encoded as positive and negative counts, respectively.
  • The script plots completed run lengths across a chosen number of recent bars.
  • The latest run is excluded because it may continue beyond the observed data.
  • The examples show distributions but do not establish predictive value or trading performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.