Skip to content
All library documents

Using a K-Nearest Neighbors Classifier to Filter Trades

Article MQL5 code base

Summary

The document outlines a trade filter based on k-nearest neighbors. It stores vectors describing past trades or market conditions, labels outcomes as profitable or unprofitable, and uses Euclidean distance to find nearby examples for a new situation. The share of profitable neighbors becomes an estimated probability; entry thresholds can require a probability above a chosen level, while optional inverse-position rules allow trades when the estimated chance of profit is low. Moving-average ratios are suggested as input features, with MACD settings and stop-loss and take-profit parameters included in the example.

The author says the approach did not produce the desired result and presents it for discussion. They identify feature selection and the computational cost of repeated distance calculations as unresolved problems. The suggested workflow builds a historical vector file and then tunes probability thresholds, but provides no performance figures or validation methodology. The estimates therefore depend on the chosen features, labels, and thresholds, and the document does not establish forward-test effectiveness.

Key ideas

  • The classifier labels historical trade vectors by whether their outcomes were profitable.
  • Euclidean distance selects the nearest examples, and their profitable share estimates the new trade’s success probability.
  • Moving-average ratios are proposed as features, with probability thresholds used to filter or invert positions.
  • The author reports unsatisfactory results and flags feature selection and computational cost as problems.
  • The described workflow includes historical data construction and threshold tuning but gives no validation results.

Tags

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