Skip to content
All library documents

Applying Dijkstra’s Algorithm to Swing-Point Trading

Article MQL5 articles

Summary

The article describes an MQL5 Expert Advisor that represents chart swing highs and lows as graph nodes. It detects swings by comparing each bar with neighboring bars, assigns price-distance weights to paths between swings, then applies Dijkstra’s shortest-path procedure to select a route through the graph. The proposed trading logic uses the resulting path to derive directional signals and set stop-loss and take-profit levels, while chart objects display swing points and paths.

The text explains graph terminology, swing detection, path costs, and configurable EA inputs, alongside implementation details for order handling and visualization. Its evidence is an implementation walkthrough and code, not a reported backtest, out-of-sample evaluation, or comparison with a benchmark. The claim that the chosen path is the most likely future price trajectory is not established by the method described: absolute price distance measures movement size, not probability, and the article does not specify a validated probabilistic edge model. The strategy should therefore be read as a coding example rather than evidence of predictive trading performance.

Key ideas

  • The EA models detected swing highs and lows as nodes in a price graph.
  • It uses absolute price differences as edge costs and applies Dijkstra’s algorithm to find low-cost paths.
  • Swing points are identified by comparing each bar with a configurable number of neighboring bars.
  • The proposed signals and risk levels are derived from graph paths, but the article reports no empirical performance evaluation.

Tags

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