Mastering Price Predictions with the Nearest Neighbor Indicator for MetaTrader 5

Mike 2010.07.09 19:29 80 0 0
Attachments

If you're looking to up your trading game, understanding the k-Nearest Neighbor (k-NN) algorithm can be a game changer. This clever technique digs into past trading patterns, pinpointing the k most similar ones to the current market situation. From there, it forecasts future prices based on weighted voting from those neighbors. But here’s the twist: our indicator focuses on just one nearest neighbor, making it a straightforward 1-NN algorithm.

This tool uses the Pearson correlation coefficient to measure the distance between the current pattern and historical ones, giving you a clear insight into future price movements.

Here’s a quick rundown of the indicator’s input parameters:

  • Npast - This is the number of past bars included in the pattern;
  • Nfut - This refers to the number of future bars in the pattern (and it needs to be less than Npast).

When you run this indicator, you’ll see two distinct curves: the blue curve reflects past prices of the nearest neighbor, while the red curve shows future prices based on the same pattern. The nearest neighbor is adjusted according to the linear regression slope between it and the current pattern, giving you a more accurate forecast.

Additionally, the indicator provides valuable information about the starting date of the nearest neighbor along with its correlation coefficient to the current pattern. For example:

Nearest_Neighbor (EURUSD, H1): Nearest neighbor is dated 2003.08.26 23:00:00 and has a correlation with the current pattern of 0.9432.

Image:

Price prediction by Nearest Neighbour

List
Comments 0