farzinsabbagh

KDJ stochastic indicator

This is a special calculation of KDJ indicator. As you may know this is based on stochastic indicator. Stochastic indicator is a method to normalize a trending time serie (here price). the calculation of stochastic itself is a built in function in pine but it is straight forward:
In sudo code:
RSV for n days=(Cn-Ln)/(Hn-Ln)×100
In which, Cn is the closing price on the nth day; Ln is the lowest price in n days; Hn is the highest price in n days.
To calculate other indices K, D and J we use this formulas:
K = (2/3) * K + (1/3) * RSV
D = (2/3) * D + (1/3) * K
J = 3 * K - 2 * D
As you can see it is a recursive calculation. It means any value of the indices are affected by it's own previous value (and I'm passionate about recursive functions!) It may concern you that in the initial calculation there is no previous value and you are right. For the initial values we use value of 50 because it is an oscillator and the mean value is always 50 so we replace the first NAs with 50 using nz() function in pine.
After doing this calculations we reach to the smoothing section. I used simple moving averages, you may replace it with other more advanced smoothing techniqes like EMA or ALMA.
After I wrote this indicator I saw that it is a good indicator for reading divergences. As you can see I showed couple of these divergences to you on the chart. Notice that I analyzed divergence between price and J (very light green) line and not to K or D. I really appreciate any suggestion on this indicator and hope to improve it. The other ones present in the public library wasn't good and they differ a lot in the calculation and also the graphics doesn't look good.
Be free to change the parameter i saw these parameter are good to daily Bitcoin chart.
Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?