I am trying to plot stochastic (14,1,1) in trading view using pine script. But I if I plot the stochastics indicator using the indicators tool of trading view, the output is different.I am using the code as below:
//@version=4
study("My Script")
Length = input (14, minval=1, title = "Stochastic Length")
k = input (1, minval=1, title = "Stochastic %K")
d = input (1, minval=1, title = "Stochastic %D")
Sto = stoch (close, highest(Length), lowest(Length), Length)
K= sma (Sto, k)
D= sma (Sto, d)
plot (D, title ="%D", color = color.red, linewidth=1)
plot (K, title ="%K", color = color.aqua, linewidth=1)
hline(80, title = "Upper Limit", color = color.red, linestyle = hline.style_dotted)
hline(20, title = "Lower Limit", color = color.lime, linestyle = hline.style_dotted)
Screenshot of stochastics in tradingview
The difference can be seen in the above screenshot.
Pls help in correcting the code if I am doing something wrong.
Need to use:
Sto = stoch (close, high, low, Length)
instead of:
Sto = stoch (close, highest(Length), lowest(Length), Length)