Fitting the CCI into my stochastic indicator
Posted: Sat Sep 12, 2020 8:53 am
Hey Guys,
I just started to learn and practice with pinescript this week because so i'm very much in the beginner phase. I want to have an Stochastic + CCI indicator. The problem is; how do i get the CCI to fit properly within the boundaries of the stochastic? I can't seem to figure it out and hope you guys can help me.
Link of how it now looks:
https://www.tradingview.com/x/TxEea89q/
Code:
I just started to learn and practice with pinescript this week because so i'm very much in the beginner phase. I want to have an Stochastic + CCI indicator. The problem is; how do i get the CCI to fit properly within the boundaries of the stochastic? I can't seem to figure it out and hope you guys can help me.
Link of how it now looks:
https://www.tradingview.com/x/TxEea89q/
Code:
Code: Select all
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TraderBillyJ
//@version=4
study(title="Stoch + CCI", shorttitle="Stoch CCI")
// Stochastic
periodK = input(14, title="K value", minval=1)
periodD = input(3, title="D value", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
// Plot Stochastic
plot(k, title="K Line", color=#14ff0a, linewidth=2)
plot(d, title="D Line", color=#ff0000, linewidth=2)
// Background Stochastic
h0 = hline(100, "Range High", color=#14ff0a)
h1 = hline(0, "Range Low", color=#ff0000)
band0 = hline(80, "Distribution Zone", color=#C0C0C0, linestyle=hline.style_solid)
band1 = hline(20, "Accumulation Zone", color=#C0C0C0, linestyle=hline.style_solid)
band2 = hline(50, "EQ", color=#C0C0C0, linestyle=hline.style_dashed)
fill(h0, h1, color=#5d606b, transp=80, title="Background")
// CCI
length = input(20, minval=1)
src = input(close, title="Source")
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))
// Plot CCI
plot(cci, "CCI", color=#ffffff)