Skip to content
All library documents

Using Depth-First Search to Formalize Swing-Structure Trading

Article MQL5 articles

Summary

The article proposes representing price structure as a graph in which confirmed swing highs and lows are nodes and transitions between them form edges. A depth-first search follows one directional branch as far as structural conditions allow, such as a sequence of higher highs and higher lows. A minimum path depth is required before assigning directional bias. The latest higher low or lower high serves as an invalidation boundary; if price breaches it, the algorithm backtracks and evaluates another path. The described MQL5 Expert Advisor also includes swing detection, chart visualization, target tolerance, stop-loss and take-profit settings, and optional risk-based position sizing.

The document presents this as a way to make swing analysis more explicit and testable, and describes running the EA in a strategy tester. However, the supplied text contains no backtest statistics or evidence that the path rules forecast returns. Performance would depend on swing definitions, parameter choices, execution assumptions and the quality of target selection. DFS provides a traversal procedure, but the trading rules built around it still require independent validation and realistic cost modeling.

Key ideas

  • Confirmed swing highs and lows are represented as nodes in a graph of market structure.
  • Depth-first search follows one bullish or bearish swing path before exploring alternatives.
  • A minimum structural depth is required before the system establishes directional bias.
  • The latest higher low or lower high acts as an invalidation level that can trigger backtracking.
  • The EA includes risk controls and visualization, but the article provides no quantitative performance evidence.

Tags

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