Price prediction by Nearest Neighbor found by a weighted correlation coefficient:
Author: Vladimir
I know some of your codes in MQL4 as well and you seem to have a firm grasp of some advanced subjects , very good work Vladimir.
What a blessing... I was going to write such "trouble" myself... now it will be possible to just redo it....
Question to the author... what is a pattern? It's not clear to me... because in my version candlestick sequences will be encoded... it is the code from several candles that will be considered a pattern...
What's yours?
because I look in the "book" and see a pattern )))
What a blessing... was going to write such a "trouble" myself... now you can just redo it....
Question for the author... what is the pattern? it's not clear to me... because in my version candlestick sequences will be encoded... it is the code from several candles that will be considered as a pattern.....
and what's yours?
Because when I look in the "book" I see a pattern.)
The pattern consists of two parts
- Past prices, i.e. prices to the left of some current price (Open in my case) including the current price itself - they are Npast.
- Future prices, i.e. prices to the right of the current price - they are Nfut.
For the most recent bar on the chart there are no future prices, only the current price and past prices. That is, the pattern for the current price has only present and past prices (Npast in total) and the indicator predicts Nfut future prices. This incomplete pattern I call current or present (current pattern). The rest of the patterns I call past patterns or simply neighbours. These neighbours have both past and "future" prices. The nearest neighbour is the one that is most correlated with the current pattern in terms of past prices. We can change the distance measure and use Euclidean distance instead of correlation coefficient, which is generally accepted. But here we need to remove the average and normalise prices by high-low.
Quite interesting this topic with the search for closest matches. But using it as an indicator makes it difficult to explore. Here, for example, is one of the ways of such a search using a script that is simply thrown on the chart (for dark background). But it is still on mql4. But the idea itself may be useful to you. It also uses the HP filter and the ability to search for continuous data and hourly from time of day.
Thank You
I wonder what kind of history array is needed for more or less successful prediction? Why 300 bars by default?
and what are the statistics of showing at least directions?
Is it positive, negative or, like everything else, 50/50?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Price prediction by Nearest Neighbor found by a weighted correlation coefficient:
The main disadvantage of the classical Nearest Neighbor algorithm (see an examplary implementation in https://www.mql5.com/en/code/133) is that all prices within a pattern are treated equally. In other words, it assumes that older prices have the same effect on future as newer ones.
To overcome this drawback, this version of the nearest neighbor indicator gives larger weights to most recent prices while searching for the closest pattern in the past. It uses a weighted correlation coefficient, whose weight decays linearly from newer to older prices within a price pattern.
The indicator plots two curves: the blue curve indicates the past prices of the nearest neighbor and the red curve indicates the future prices of the same pattern. The nearest neighbor is scaled according to the linear regression slope between this pattern and the current pattern. The indicator also prints the information about the starting date of the nearest neighbor and its correlation coefficient to the present pattern.
Author: Vladimir