Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Candlestick Pattern Scanner with honest statistics (engulfing, pin bar, stars, no repaint) - indicator for MetaTrader 5

Muhammad Muqeem Korejo
Muhammad Muqeem Korejo
Hi, I'm Muhammad Muqeem Korejo, an MQL4/MQL5 developer from Pakistan with 1.5 years of trading experience.
I build and fix trading tools for MetaTrader 4 and MetaTrader 5:
• Expert Advisors (EAs) built from your strategy rules
• Custom indicators, alerts and on-chart panels
Views:
35
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Most candlestick indicators fill the chart with labels and never tell you if the patterns work on your market. This one does three things differently: every pattern has an exact rule, filters keep only the patterns in a sensible place, and a table shows how each pattern really did on the chart you are looking at - next to the result of a random bar, so you can see if the pattern adds anything.

Candlestick Pattern Scanner on a EURUSD H1 chart: filtered patterns and the statistics table against the base rate

Patterns (bullish and bearish, each can be switched off)

  • Engulfing: a long body covers the previous, smaller body of the other colour.
  • Pin bar (hammer / shooting star): the tail is at least 66 percent of the candle, the body is in the opposite third.
  • Harami: a small body inside the previous long body of the other colour.
  • Morning / evening star: a long candle, a small body (under half the average body), then a long candle the other way that closes past the middle of the first.
  • Tweezer bottom / top: two candles of different colour with the same low or high (within 5 percent of the average body).
  • Piercing line / dark cloud cover: opens beyond the previous close and closes past the middle of the previous long body, but not past its open.
  • Three white soldiers / three black crows: three long candles of one colour, each closing further and opening inside the previous body.

"Long" and "small" mean above or below the average body (an exponential average of the last 14 bodies).

Filters against clutter (all on by default)

  • Trend: reversal patterns only after a move against them (bullish below the 50 SMA, bearish above it). Soldiers and crows are continuation patterns and use the opposite rule.
  • Swing: the pattern must make the lowest low (bullish) or the highest high (bearish) of the last 10 bars.
  • Size: the last candle must be at least 0.5 ATR, so tiny candles in quiet hours are ignored.

The statistics table

  • For every pattern: how often price reached +1 ATR before -1 ATR within the next 5 bars (all three are inputs), and how many patterns that is based on.
  • The same test from every bar of the chart (the base rate). A pattern is only interesting if it does clearly better than the base rate.
  • The difference to the base rate and a margin (+/-) that shows how uncertain the number is with this few patterns. Small samples are common, so the margin is often larger than the difference.
  • A candle that touches both the target and the stop is counted as a loss, because the order inside the candle is unknown. Only finished outcomes are counted.

To be honest about what to expect: on the EURUSD H1 chart of the screenshot most patterns are within their margin of the base rate. Patterns are context, not a trading system on their own.

No repaint

A pattern is decided when its last candle has closed. It is marked on that candle and never moved or removed. The open candle is never used.

For Expert Advisors (4 buffers)

0 bullish pattern (the low of the candle), 1 bearish pattern (the high), 2 bullish pattern number, 3 bearish pattern number (1 engulfing, 2 pin bar, 3 harami, 4 star, 5 tweezer, 6 piercing / dark cloud, 7 soldiers / crows). Read bar 1: if the buffer is not EMPTY_VALUE, a pattern was found on the last closed candle.

Inputs: each pattern on / off, average body length, pin bar tail percent, tweezer tolerance, trend filter and SMA length, swing filter and bars, minimum candle size, ATR length, statistics (distance in ATR, bars, bars to calculate), labels, font size, table colour, alerts.

How it was tested

  • An independent calculation in Python (own code) rebuilt every pattern rule and filter from the exported bars and compared them with the buffers on EURUSD H1, XAUUSD M15 and GBPUSD H4: 16,194 candle checks, 608 patterns, 0 differences.
  • The statistics table of a live EURUSD H1 demo chart (5,000 bars) was rebuilt in Python: every row, including the base rate, the differences and the margins, matched.
  • Repaint test: on every new bar, a test Expert Advisor saved the buffers of the bar that had just closed. At the end of the test the same bars were read again. 30,396 values compared, 0 changed.
  • Validator-style runs in the Strategy Tester: EURUSD H1, XAUUSD D1, GBPUSD M30 and EURUSD M1 (663,241 bars): no errors. Nothing is drawn in a Strategy Tester run without visualization, but all buffers are calculated.
  • The screenshot is a real EURUSD H1 chart of a demo account.
ADR Levels: Average Daily Range, range used in percent, projected high and low (no repaint) ADR Levels: Average Daily Range, range used in percent, projected high and low (no repaint)

Average Daily Range from finished days, ADR high / low projected from today's low and high or from the open, range used in percent, a small panel and alerts at 80 / 100 percent. Day from broker or New York time. No repaint.

Broker Time Panel - server clock, local zone, measured offset, candle close countdown Broker Time Panel - server clock, local zone, measured offset, candle close countdown

The panel prints the broker's server clock, your local clock with its GMT zone, the offset between the two to the minute, and the countdown to the close of the chart's current candle. The offset is measured from the terminal's own clocks on every pass, so nothing is typed in and no broker zone is assumed. If you set a lead in seconds and enable a channel, it sends one alert per candle while a bid is available, with the seconds left and the bid; its eight objects stay out of the object list and cannot be selected.

Broker Symbol Compatibility Scanner Broker Symbol Compatibility Scanner

Scans the broker's complete MT5 symbol catalogue, resolves common prefixes, suffixes and aliases, checks trading specifications and exports a compatibility report to CSV.

MACD Signals MACD Signals

Indicator edition for new platform.