148 lines
5.9 KiB
Markdown
148 lines
5.9 KiB
Markdown
# Article-22572-Megaphone-Pattern-Detection-In-MQL5
|
|
|
|
This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.
|
|
|
|
## Overview
|
|
|
|
This project documents the MQL5 implementation of a custom indicator for automatic megaphone pattern detection, also known as a broadening formation. The article describes a rule-based workflow for:
|
|
|
|
- detecting swing highs and swing lows,
|
|
- refining detected swings to true local extremes,
|
|
- drawing upper and lower expanding trend lines,
|
|
- validating structure integrity,
|
|
- confirming bullish breakout conditions,
|
|
- projecting stop loss and take profit levels from pattern geometry.
|
|
|
|
The article focuses primarily on the bullish detection path, while stating that the bearish variant follows similar logic.
|
|
|
|
## Original Article
|
|
|
|
- **Article ID:** 22572
|
|
- **Author:** Israel Pelumi Abioye
|
|
- **Publication date:** 2026.05.27
|
|
- **Category:** Indicators
|
|
- **URL:** https://www.mql5.com/en/articles/22572
|
|
|
|
## Repository Purpose
|
|
|
|
This repository should be treated as a reference or reconstruction project derived from the article text and embedded code excerpts.
|
|
|
|
Its purpose is to preserve the technical design and partial implementation details of an MQL5 indicator that detects megaphone formations on-chart. It is useful for:
|
|
|
|
- studying pattern-detection logic in MQL5,
|
|
- reconstructing an indicator from article snippets,
|
|
- understanding chart-object-based visualization and validation,
|
|
- extending the logic toward bearish structures or Expert Advisor workflows.
|
|
|
|
## Key Concepts
|
|
|
|
- **Megaphone / broadening formation**
|
|
- **Swing point detection** using fixed left/right confirmation depth
|
|
- **Lookback-window scanning** over recent bars only
|
|
- **Sequential structure building** with four anchors:
|
|
- S1: first swing high
|
|
- S2: first swing low
|
|
- S3: second swing high, higher than S1
|
|
- S4: second swing low, lower than S2
|
|
- **Swing refinement** to true extremes within each leg
|
|
- **Trend line integrity validation** using candle close checks
|
|
- **Proportional expansion filter** to reject distorted formations
|
|
- **Breakout confirmation** after pattern completion
|
|
- **SL/TP projection** based on distance between trend line boundaries
|
|
- **Chart object management** with prefixed object names and cleanup on deinitialization
|
|
|
|
## Algorithm / Architecture Summary
|
|
|
|
The article presents the indicator as a staged detection pipeline:
|
|
|
|
1. **Scan a fixed historical window**
|
|
- Example value shown: `look_back = 300`
|
|
- Processing runs once per newly completed bar using a stored bar timestamp.
|
|
|
|
2. **Detect initial swing structure**
|
|
- Swing highs/lows are validated with a configurable depth such as `SwingLookback = 3`.
|
|
- A bullish candidate is formed by finding:
|
|
- a swing high,
|
|
- then a swing low,
|
|
- then a higher swing high,
|
|
- then a lower swing low.
|
|
|
|
3. **Refine anchor points**
|
|
- The initial swing points are adjusted to the actual highest high / lowest low inside each swing leg.
|
|
- The article uses `ArrayMaximum`, `ArrayMinimum`, and `Bars()` to locate these true extremes.
|
|
|
|
4. **Draw trend lines**
|
|
- Upper boundary connects the refined first and second highs.
|
|
- Lower boundary connects the refined first and second lows.
|
|
- Objects are created only if they do not already exist.
|
|
|
|
5. **Validate structure integrity**
|
|
- The upper line is invalidated if any candle closes above it before the breakout stage.
|
|
- The lower line is invalidated if any candle closes below it before breakout.
|
|
- A proportional growth rule limits overexpansion; the article example uses a 150% threshold relative to the initial range.
|
|
|
|
6. **Monitor for breakout**
|
|
- After the fourth swing forms, the lines are extended rightward.
|
|
- A bullish breakout is confirmed when a candle closes above the upper trend line.
|
|
- An additional check ensures the lower boundary was not violated before that breakout.
|
|
|
|
7. **Project management levels**
|
|
- Stop loss is placed at the midpoint of the vertical breakout-region range.
|
|
- Take profit is projected by adding the full structure height above the upper boundary.
|
|
- Both are visualized using chart objects and text labels.
|
|
|
|
The snippets indicate a chart-window custom indicator using object-based visualization rather than indicator buffers.
|
|
|
|
## Mentioned or Attached Files
|
|
|
|
### Explicitly attached files
|
|
|
|
No attached source files were available in the processed input.
|
|
|
|
### Files mentioned in text only
|
|
|
|
The article includes inline MQL5 code fragments for an indicator implementation, including examples of:
|
|
|
|
- `OnInit`
|
|
- `OnCalculate`
|
|
- `OnDeinit`
|
|
- `IsSwingHigh`
|
|
- `IsSwingLow`
|
|
- `DrawTrend`
|
|
- `DrawObject`
|
|
|
|
A text-drawing helper named `DrawTxt` is referenced in the stop loss / take profit section, but its implementation was not included in the provided material.
|
|
|
|
## Statistics
|
|
|
|
No article statistics were available in the provided input.
|
|
|
|
## Tags
|
|
|
|
`MQL5`, `MetaTrader 5`, `indicator`, `pattern detection`, `megaphone pattern`, `broadening formation`, `swing highs`, `swing lows`, `trend lines`, `breakout confirmation`, `technical analysis`
|
|
|
|
## Difficulty
|
|
|
|
**Intermediate**
|
|
|
|
The described implementation requires familiarity with:
|
|
|
|
- MQL5 custom indicators,
|
|
- timeseries array indexing,
|
|
- nested historical scans,
|
|
- chart object APIs,
|
|
- structural validation logic,
|
|
- state control across new bars.
|
|
|
|
## Limitations
|
|
|
|
- The full original source code is unavailable in the provided input.
|
|
- Only article text and partial code excerpts were available.
|
|
- Article metadata such as article ID, author, category, publication date, and URL was not included in the provided material.
|
|
- The bearish implementation is described conceptually but not fully shown in code.
|
|
- Some helper functionality is referenced but not fully defined in the excerpts, such as text-label drawing.
|
|
- This repository should not be presented as a verified production-ready trading system without further reconstruction, testing, and validation.
|
|
|
|
## Reference
|
|
|
|
Original source: https://www.mql5.com/en/articles/22572
|