Loading…

Candle Sequence Dictionary Builder

Traders name individual 3-bar candlestick patterns constantly, but rarely test the full set at once with a single consistent method. This script classifies every bar as Up, Down or Doji, encodes each rolling window of three consecutive bars as a base-3 digit (0..26 - 27 possible 3-bar shapes), and for every occurrence of each code measures the price return a fixed number of bars after the sequence completes. The result is a ranked dictionary: 27 rows, each with a sample count, a frequency percentage, and an average forward return in pips. A bar is classified as a Doji when its body is small RELATIVE TO ITS OWN RANGE, not against a fixed pip threshold. A fixed pip cutoff would call every bar Up/Down on a volatile instrument and every bar a Doji on a quiet one; using the bar's own range keeps the classification meaningful across very different symbols without retuning the input each time. Every possible 3-bar shape is reported, not just the "interesting" ones a human might name - including the codes that turn out to carry almost no edge, which is itself useful information when deciding which named patterns are worth watching for. Notes and limitations - The pattern code and its 3-letter label (D = Down, . = Doji, U = Up, oldest bar first) both identify the same shape; the label is there so the log reads without a lookup table on hand. - A zero-range bar (a data feed glitch with identical high and low) is treated as a Doji rather than causing a division by zero. - The output table is ranked by the absolute size of the average forward return, so the top rows are the most informative sequences, not necessarily the most frequent ones. - This is a descriptive study, not a trading signal. Codes with a small sample count can show a large average return purely by chance - check the count column before trusting a row.

Script · MT4 · v1.0 · Free

About Candle Sequence Dictionary Builder

Candle Sequence Dictionary Builder is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message and marks candlestick patterns. It has 7 settings, such as Symbol, Timeframe and Max bars. MQL source code included.

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

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_H1Timeframe to study
Max bars8000Most recent bars to include
Doji body ratio0.15Body/range fraction at or below which a bar is a Doji
Forward bars5Bars after the sequence completes measured for the forward return
Save csvtrueWrite the full 27-code frequency/return table to a CSV file
DelimiterDelimiterCommaCSV column separator

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

MQL4 & MQL5 scripts · PolyMaria