// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alperzengin22
//@version=5
indicator("KDJ Indicator")
period = input.int(9, title="Period(dK)", minval=1)
signal = input.int(3, title="Period(dD)", minval=1)
smoothing = input.int(1, title="Smoothing", minval=1)
var float pK = na
var float pD = na
RSV = ta.stoch(close, high, low, period)
pK := nz(pK[1],50)*(signal-1)/signal + RSV/signal
pD := nz(pD[1],50)*(signal-1)/signal + pK/signal
pJ = 3 * pK-2 * pD
pK := ta.sma(pK,smoothing)
pD := ta.sma(pD,smoothing)
pJ := ta.sma(pJ,smoothing)
plot(pJ, color=color.blue, linewidth = 1, title = "pJ")
plot(pK, color=color.orange, linewidth = 1, title = "pK")
plot(pD, color=color.purple, linewidth = 1, title = "pD")
OverBought = hline(80, color=color.red, linewidth = 2, title = "OverBought", display=display.none)
OverSell = hline(20, color=color.green, linewidth = 2, title = "OverSell", display=display.none)
Max = hline(150, color=color.red, linewidth = 2, title = "Max", display=display.none)
Min = hline(-50, color=color.green, linewidth = 2, title = "Min", display=display.none)
fill(OverBought,Max,color=color.new(color.red,transp = 80))
fill(OverSell,Min,color=color.new(color.green,transp = 80))
up = ta.rma(math.max(ta.change(close), 0), 14)
down = ta.rma(-math.min(ta.change(close), 0), 14)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))