Skip to content
All library documents

Automating Triangle and Rectangle Detection from Price Swings

Article MQL5 articles

Summary

This article presents a modular approach to detecting geometric structures in price data, focusing on triangles and rectangles. It motivates automation as a way to replace manually drawn chart objects with repeatable rules, using swing highs and lows as anchor points. Triangle boundaries are formed from converging lines, while rectangles are identified from repeated touches near horizontal support and resistance. The implementation is organized around reusable MQL5 classes, with an Expert Advisor example that detects patterns and annotates them on a chart.

The article explains common textbook interpretations of these structures, such as consolidation and possible breakouts, but cautions that expected directions are not reliable on their own. Price context before the formation matters, and patterns can resolve opposite to conventional expectations. The material is primarily an implementation and visualization framework; it does not provide a trading rule evaluation, performance results, or evidence that detected formations predict future returns. It suggests possible future extensions, including volume or oscillator confirmation, multiple-timeframe validation, and execution logic, which remain proposals rather than tested features.

Key ideas

  • Swing highs and lows can serve as reference points for constructing geometric chart patterns.
  • A triangle is represented by converging boundary lines, while a rectangle uses approximately parallel support and resistance boundaries.
  • Object-oriented classes can make pattern detection reusable across indicators and Expert Advisors.
  • Conventional breakout expectations are not guarantees, so price context around a pattern matters.
  • The article demonstrates detection and chart annotation but does not validate a trading strategy's performance.

Tags

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