OPEN-SOURCE SCRIPT
Nearest Neighbor Extrapolation of Price [Loxx]

I wasn't going to post this because I don't like how this calculates by puling in the Open price, but I'm posting it anyway. This does work in it's current form but there is a. better way to do this. I'll revisit this in the future.
Anyway...
The k-Nearest Neighbor algorithm (k-NN) searches for k past patterns (neighbors) that are most similar to the current pattern and computes the future prices based on weighted voting of those neighbors. This indicator finds only one nearest neighbor. So, in essence, it is a 1-NN algorithm. It uses the Pearson correlation coefficient between the current pattern and all past patterns as the measure of distance between them. Also, 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.
This indicator also includes an error window that shows whether the calculation is valid. If it's green and says "Passed", then the calculation is valid, otherwise it'll show a red background and and error message.
Inputs
Related indicators
Hodrick-Prescott Extrapolation of Price
![Hodrick-Prescott Extrapolation of Price [Loxx]](https://s3.tradingview.com/h/HCfWOt6F_mid.png)
Itakura-Saito Autoregressive Extrapolation of Price
![Itakura-Saito Autoregressive Extrapolation of Price [Loxx]](https://s3.tradingview.com/b/BKC6dFUY_mid.png)
Helme-Nikias Weighted Burg AR-SE Extra. of Price
![Helme-Nikias Weighted Burg AR-SE Extra. of Price [Loxx]](https://s3.tradingview.com/8/8YbmmPCn_mid.png)
Weighted Burg AR Spectral Estimate Extrapolation of Price
![Weighted Burg AR Spectral Estimate Extrapolation of Price [Loxx]](https://s3.tradingview.com/g/G3VyvCoH_mid.png)
Levinson-Durbin Autocorrelation Extrapolation of Price
![Levinson-Durbin Autocorrelation Extrapolation of Price [Loxx]](https://s3.tradingview.com/m/mvUdLxSg_mid.png)
Fourier Extrapolator of Price w/ Projection Forecast
![Fourier Extrapolator of Price w/ Projection Forecast [Loxx]](https://s3.tradingview.com/u/u0r2gpti_mid.png)
Anyway...
The k-Nearest Neighbor algorithm (k-NN) searches for k past patterns (neighbors) that are most similar to the current pattern and computes the future prices based on weighted voting of those neighbors. This indicator finds only one nearest neighbor. So, in essence, it is a 1-NN algorithm. It uses the Pearson correlation coefficient between the current pattern and all past patterns as the measure of distance between them. Also, 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.
This indicator also includes an error window that shows whether the calculation is valid. If it's green and says "Passed", then the calculation is valid, otherwise it'll show a red background and and error message.
Inputs
- Npast - number of past bars in a pattern;
- Nfut -number of future bars in a pattern (must be < Npast).
- lastbar - How many bars back to start forecast? Useful to show past prediction accuracy
- barsbark - This prevents Pine from trying to calculate on all past bars
Related indicators
Hodrick-Prescott Extrapolation of Price
![Hodrick-Prescott Extrapolation of Price [Loxx]](https://s3.tradingview.com/h/HCfWOt6F_mid.png)
Itakura-Saito Autoregressive Extrapolation of Price
![Itakura-Saito Autoregressive Extrapolation of Price [Loxx]](https://s3.tradingview.com/b/BKC6dFUY_mid.png)
Helme-Nikias Weighted Burg AR-SE Extra. of Price
![Helme-Nikias Weighted Burg AR-SE Extra. of Price [Loxx]](https://s3.tradingview.com/8/8YbmmPCn_mid.png)
Weighted Burg AR Spectral Estimate Extrapolation of Price
![Weighted Burg AR Spectral Estimate Extrapolation of Price [Loxx]](https://s3.tradingview.com/g/G3VyvCoH_mid.png)
Levinson-Durbin Autocorrelation Extrapolation of Price
![Levinson-Durbin Autocorrelation Extrapolation of Price [Loxx]](https://s3.tradingview.com/m/mvUdLxSg_mid.png)
Fourier Extrapolator of Price w/ Projection Forecast
![Fourier Extrapolator of Price w/ Projection Forecast [Loxx]](https://s3.tradingview.com/u/u0r2gpti_mid.png)
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
للوصول السريع إلى الرسم البياني، أضف هذا النص البرمجي إلى مفضلاتك - تعرف على المزيد هنا.
Public Telegram Group, t.me/algxtrading_public
VIP Membership Info: patreon.com/algxtrading/membership
VIP Membership Info: patreon.com/algxtrading/membership
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
للوصول السريع إلى الرسم البياني، أضف هذا النص البرمجي إلى مفضلاتك - تعرف على المزيد هنا.
Public Telegram Group, t.me/algxtrading_public
VIP Membership Info: patreon.com/algxtrading/membership
VIP Membership Info: patreon.com/algxtrading/membership
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.