# 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.
Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuyla, bu betiğin yazarı, yatırımcının anlayabilmesi ve doğrulayabilmesi için onu açık kaynak olarak yayınladı. Yazarın eline sağlık! Bunu ücretsiz olarak kullanabilirsiniz, ancak bu kodun bir yayında yeniden kullanımı Kullanım Koşulları ile yönetilir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?