//@version=3
study(title="Woodies CCI + CZ + SW indicators")
//declaration of variables
source = input (title="Source for CCI", defval=close)
barsbt = input(title="Bars before trend", defval = 4)
swhigh = input(title="Sidewinder higher th", defval = 1.7453)
swlow = input(title="Sidewinder lower th", defval = 0.5235)
swmid = input(title="Sidewinder middle th", defval = 1.0471)
colorTurquoise = #34dddd
colorDarkGreen = #006400
colorPaleGreen = #98fb98
colorLime = lime
colorDarkRed = #8B0000
colorRed = red
colorOrange = orange
colorLightOrange = #ffc04c
colorYellow = yellow
avg = hlc3
pi = atan(1) * 4
periods = 30
highestHigh = highest(periods)
lowestLow = lowest(periods)
range = 25 / (highestHigh - lowestLow) * lowestLow
//Chopzone indicator
emal = input(title="ema34 Length", type=integer, defval=34)
ema34 = ema(source, emal)
x1_ema34 = 0
x2_ema34 = 1
y1_ema34 = 0
y2_ema34 = (ema34[1] - ema34) / avg * range
c_ema34 = sqrt((x2_ema34 - x1_ema34)*(x2_ema34 - x1_ema34) + (y2_ema34 - y1_ema34)*(y2_ema34 - y1_ema34))
emaAngle_1 = round(180 * acos((x2_ema34 - x1_ema34)/c_ema34) / pi)
emaAngle = iff(y2_ema34 > 0, - emaAngle_1, emaAngle_1)
chopZoneColor = emaAngle >= 5 ? colorTurquoise : emaAngle < 5 and emaAngle >= 3.57 ? colorDarkGreen : emaAngle < 3.57 and emaAngle >= 2.14 ? colorPaleGreen : emaAngle < 2.14 and emaAngle >= .71 ? colorLime : emaAngle <= -1 * 5 ? colorDarkRed : emaAngle > -1 * 5 and emaAngle <= -1 * 3.57 ? colorRed : emaAngle > -1 * 3.57 and emaAngle <= -1 * 2.14 ? colorOrange : emaAngle > -1 * 2.14 and emaAngle <= -1 * .71 ? colorLightOrange : colorYellow
// Woodies CCI indicator
cciTurboLength = input(title="CCI Turbo Length", type=integer, defval=6, minval=3, maxval=14)
cci14Length = input(title="CCI 14 Length", type=integer, defval=14, minval=7, maxval=20)
cciTurbo = cci(source, cciTurboLength)
cci14 = cci(source, cci14Length)
ccilz = barssince(crossunder(cci14,0))
ccigz = barssince(crossover(cci14,0))
ccibrs = (ccilz > ccigz) ? ccigz : ccilz
histogramColor = (ccibrs < barsbt) ? silver : (ccibrs == barsbt) ? yellow : (cci14 < 0) ? red: green
cci14color = cci14 < 0 ? red : green
//LSMA indicator
length = input(title="Length", type=integer, defval=25)
offset = input(title="Offset", type=integer, defval=0)
src = input(defval=open, title="Source for LSMA")
lsma = linreg(src, length, offset)
lsmastd = stdev(abs(lsma[1] - lsma), length)
colorLine= abs(lsma - lsma[1]) < lsmastd ? white : lsma < lsma[1] ? red : green
//Sidewinder indicator
sum=change(lsma)+change(ema34)
//** radian angles
colorLineSW= abs(sum)> swhigh ? green : (abs(sum)>swlow and abs(sum)<swmid) ? red : yellow
colorLineSW2= close > ema34 ? green : red
//plots of CCIS
plot(cci14, title="CCI 14 area", color=histogramColor, style=area, transp=50)
plot(cciTurbo, title="CCI Turbo", color=aqua, style=line, linewidth=2)
plot(cci14, title="CCI 14", color=fuchsia, style=line, linewidth=2)
//plots of Chopzones
plot(100, title="plusle chop zone",color=chopZoneColor , style=line, linewidth=3, editable= false)
plot(-100, title="minus chop zone",color=chopZoneColor , style=line, linewidth=3, editable= false)
//plot of LSMA
plot(0, title="LSMA line",color=colorLine , style=line, linewidth=3, editable= false)
//plot of Sidewinder
plot(-200, title="-Sidewinder",color=colorLineSW , style=line, linewidth=3, editable= false)
plot(200, title="-Sidewinder",color=colorLineSW2 , style=line, linewidth=3, editable= false)
//hlines
hline(0, title="Zero Line", color=black, linestyle=solid)
hline(200, title="+Sidewinder line", color=black, linestyle=dotted)
hline(-200, title="-Sidewinder line", color=black, linestyle=dotted)
hline(100, title="+chop zone line", color=black, linestyle=dotted)
hline(-100, title="-chop zone line", color=black, linestyle=dotted)