Skip to content
All library documents

Using K-Means Clustering to Discover Patterns in Trading Time Series

Article MQL5 articles

Summary

The article explains unsupervised learning and applies k-means clustering to trading data. Without labeled target values, clustering groups observations represented as feature vectors by assigning them to nearby centers. The cluster count is a model hyperparameter: it may be selected from domain knowledge or visualization, or assessed through repeated fits and comparison of the loss as the count changes. The article also places clustering alongside anomaly detection and dimensionality reduction as unsupervised learning tasks, while distinguishing it from supervised classification and regression.

For a trading example, the author represents historical market states as vectors and tests clustering to identify recurring variations in price behavior. The reported experiment analyzes 98,641 states and finds a broad transition in the loss curve around 400 to 500 clusters, interpreted as roughly that many candidate patterns. This is exploratory evidence, not proof that the clusters are profitable signals; the article says their practical trading use is deferred. Results depend on feature design, cluster count, and the data used.

Key ideas

  • Unsupervised learning can group observations without labeled target outputs.
  • K-means represents each market state as a vector and assigns it to a nearby cluster center.
  • The number of clusters must be selected using prior knowledge or model evaluation.
  • The example analyzes 98,641 historical states and suggests roughly 400 to 500 clusters from the loss curve.
  • Identified clusters are candidate patterns and do not by themselves demonstrate useful trading signals.

Tags

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