Discussing the article: "Automating Chart Patterns in MQL5 (Part 2): The Double Top and Double Bottom"

 

Check out the new article: Automating Chart Patterns in MQL5 (Part 2): The Double Top and Double Bottom.

We build a robust MQL5 detector for double tops and double bottoms that first confirms the H4 trend, then validates six conditions (point equality, neckline placement, ordering, width, height, and ATR‑based tolerances). The neckline break is timed on the chart's timeframe, and a three-state machine ensures each pattern trades once. The measured‑move target translates structure into clear exits.

The double top has five structural components.

Double top—structure and measurement


The prior trend is the H4 uptrend that precedes the pattern. Without it, the pattern has no context. "CSwingEngine" confirms this by requiring the most recently labeled H4 swing high to be HH and the most recently labeled H4 swing low to be HL before any double-top evaluation begins.

The first peak is the most recent H4 swing high in the uptrend—the high that price reached and failed to sustain. It is stored by the engine as the last confirmed swing high.

The trough is the H4 swing low between the two peaks. It defines the neckline. The neckline is the horizontal level the price must break below to confirm the reversal. The trough is stored by the engine as the swing low that occurred after the first peak.

The second peak is a subsequent H4 swing high that reaches approximately the same price level as the first peak. The tolerance for "approximately equal" is configurable—the default is 1.5 ATR, measured on H4 to match the timeframe the peaks themselves come from. If the second peak is within 1.5 H4-ATR of the first peak, the structure qualifies.

Author: Tola Moses Hector