OPEN-SOURCE SCRIPT

Euclidean Distance Predictive Candles [SS]

Aggiornato
Finally releasing this, its been in the works for the past 2 weeks and has undergone many iterations.

I am not sure if I am 100% happy with it yet, but I guess its best to release and get feedback to make improvements.

So this is the Euclidean distance predictive candle indicator and what it does is exactly what it sounds like, it uses Euclidean distance to identify similar candles and then plot the candles and range that immediately proceeded like candles.

While this is using a general machine learning/data science approach (Euclidean distance), I do not employ the KNN (Nearest Neighbors) algo into this. The reason being is it simply offered no predictive advantage than isolating for the last case. I tried it, I didn't like it, the results were not improve and, at times, acutally hindered so I ditched it. Perhaps it was my approach but using some other KNN indicators, I just don't really find them all that more advantageous to simply relying on the Law of Large Numbers and collecting more data rather than less data (which we will get into later in this explanation).

So using this indicator:

There is a lot of customizability here. And the reason is, not all settings are going to work the same for all tickers. To help you narrow down your parameters, I have included various backtest results that show you how the model is performing. You see in the AMZN chart above, with the current settings, it is performing optimally, with a cumulative range pass of 99% (meaning that, of all the cases, the indicator accurately predicted the next day high OR low range 99% of the time), and the ability to predict the candle slightly over 52%.

The recommended settings, from me, are as follows:

istantanea

So these are generally my recommended settings.

Euclidian Tolerance: This will determine the parameters to look for similar candles. In general, the lower the tolerance, the greater the precision. I recommend keeping it between 0.5, for tickers with larger prices (like ES1! futures or NQ1!) or 0.05 for tickers with lower TPs, like SPY or QQQ.
If the ED Tolerance is too extreme that the indicator cannot find identical setups, it will alert you:

istantanea

But in general, the more precise you can get it, the better.

Anchor Type: You will see the option to anchor by "Predicted Open" or by "Previous Close". I suggest sticking with anchoring by predicted open. All this means is, it is going to anchor your range, candle, high and low targets by the predicted open price. Anchoring by previous close will anchor by the close of yesterday. Both work okay, but in general the results from anchoring to predicted open have higher pass rates and more accurately depict the candle.

Euclidean Distance Measurement Type: You can choose to measure by candle body or from high to low wicks. I haven't played around with measuring from high to low wicks all that much, because candle body tends to do the job. But remember, ED is a neutral measurement. Which means, its not going to distinguish between a red or green candle, just the formation of the candle. Thus, I tend to recommend, pragmatically, not to necessarily rely on the candle being red or green, but one the formation of the candle (where are the wicks going, are there more bearish wicks or bullish wicks) etc. Examples will follow.

Range Prediction Type: You can filter the range prediction type by last instance (in which, it will pull the previous identical candle and plot the next candle that followed it, adjusted for the current ranges) or "Average of All Cases". So this is where we need to talk a little bit about the law of large numbers.

In general, in statistics, when you have a huge amount of random data, the law of large numbers stipulates that, within this randomness should be repeated events. This is why sometimes chart patterns work, sometimes they don't. When we filter by the average of all cases, we are relying on the law of large numbers. In general, if you are getting good Backtest readings from Last Instance, then you don't need to use this function. But it provides an alternative insight into potential candle formations next day. Its not a bad idea to compare between the two and look for similarities and differences.

So now that we have covered the boring details, let's get into how to use the indicator and some examples.

So the indicator is plotting the range and candle for the next day. As such, we are not looking at the current candle being plotted, but we are looking at the previous candle (see image below for example):

istantanea

The green arrow shows the prediction for Friday, along with the corresponding result. The purple arrow shows the prediction for Monday which we have yet to realize.

So remember when you are using this, you need to look at the previous candle, and not the candle that it is currently plotting with realtime data, because it is plotting for the next candle.

If you are plotting by last instance, the indicator will tell you which day it is pulling its data from if you have opted to toggle on the demographic data:

istantanea

You can see the green arrow pointing to the date where it is pulling from. This data serves as the example candle with the candle proceeding this date being the anchored candle (or the predicted candle).

Price Targets and Probability:

istantanea

In the chart, you can see the green arrow pointing to the green portion of the table. In this table, it will give you the current TPs. These represent the current time target price, which means, the TPs shown here are for Friday. On Monday, the table will update with the TPs for Monday, etc. If you want to view the TPs in advance, you can view them from the actual candle itself.

Below the TPs, you see a bullish 7:6. It means, in a total of 13 cases, the next candle was bullish 7 times and bearish 6 times. Where do we see the number of cases? In the demographic table as well:

istantanea

Auxiliary functions

Because you are using the previous candle, if you want to avoid confusion, you can have the indicator plot the price targets over the predicted candle, to anchor your attention so to speak. Simply select "Label" in the "Show Price Targets" section, which will look like this:

istantanea

You can also ask the indicator to plot the demographic data of Higher High, Low, etc. information. What this does is simply looks at all the cases and plots how many times higher highs, lows, lower lows, highs etc. were made:

istantanea

This will just count all of the cases identified and plot the number of times higher highs, lows, etc. were made.

Concluding Remarks

This is a kind of complex indicator and I can appreciate it may take some getting used to.
I will try to post a tutorial video at some point next week for it, so stay tuned for that.
But this isn't designed to make your life more complicated, just to help give you insights into potential outcomes for the next day or hour or 5 minute (it can be used on all timeframes).

If you find it helpful, great! If not, that's okay, too :-).

Please be aware, this is not my forte of indicators. I am not a data scientist or programmer. My background is in Epi and we don't use these types of data science approaches, so if you have any suggestions or critiques, feel free to share them below.

Otherwise, I hope you enjoy!
Take care everyone and safe trades!





Note di rilascio
Quick cleanup of the code.
Note di rilascio
Error that was fixed.
Note di rilascio
Fix
forecasting

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?


For real-time updates and premium indicators, consider joining my group at: patreon.com/steversteves
Anche su:

Declinazione di responsabilità