Commodity Channel Relative Strength
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EsIstTurnt

//@version=5
indicator("Commodity Channel Relative Strength",shorttitle='CCRSI+FIB')
tf             =             input.timeframe(''     ,'TimeFrame                     ',group='Resolution')
Fib            =             input.bool     (false  ,'Plot Fib Levels               ',group='Fibonacci ')
SmoothFib      =             input.bool     (true   ,'Smooth Fib Levels             ',group='Fibonacci ')
Bound          =             input.bool     (true   ,'Plot Boundarys                ',group='Fibonacci ')
AltLength      =             input.bool     (true   ,'Use Alternate Length Calc?    ',group='Calc      ')
Background     =             input.bool     (false  ,'Plot Background               ',group='Plot      ')
FibOffset      =             input.int      (0      ,'Fib Offset                    ',group='Fibonacci ')
SmoothLen      =             input.int      (16     ,'Fib Smoothing Length          ',group='Fibonacci ')
momLen         =             input.int      (16     ,'Loppock Length                ',group='Length    ')
A1Length       =             input.int      (16     ,'Length 1                      ',group='Length    ')
A2Length       = AltLength ? input.int      (32     ,'Length 2                      ',group='Length    ') : A1Length*2
A3Length       = AltLength ? input.int      (64     ,'Length 3                      ',group='Length    ') : A1Length*3
A4Length       = AltLength ? input.int      (80     ,'Length 4                      ',group='Length    ') : A1Length*4
A5Length       = AltLength ? input.int      (128    ,'Length 5                      ',group='Length    ') : A1Length*5
A6Length       = AltLength ? input.int      (160    ,'Length 6                      ',group='Length    ') : A1Length*6
A7Length       = AltLength ? input.int      (200    ,'Length 7                      ',group='Length    ') : A1Length*7
A8Length       = AltLength ? input.int      (256    ,'Length 8                      ',group='Length    ') : A1Length*8
A9Length       = AltLength ? input.int      (300    ,'Length 9                      ',group='Length    ') : A1Length*9
A10Length      = AltLength ? input.int      (360    ,'Length 10                     ',group='Length    ') : A1Length*10
A11Length      = AltLength ? input.int      (420    ,'Length 11                     ',group='Length    ') : A1Length*10
lookback1      =             input.int      (16     ,'Lookback 1                    ',group='Fibonacci ')
lookback2      =             input.int      (32     ,'Lookback 2                    ',group='Fibonacci ')
Sigma          =             input.int      (3      ,'ALMA Sigma                    ',group='Calc      ') 
Offset         =             input.float    (.77    ,'ALMA Offset                   ',group='Calc      ')
fib0236        =             input.float    (0.236  ,'Fibonacci Level 1             ',group='Fibonacci ')
fib0382        =             input.float    (0.382  ,'Fibonacci Level 2             ',group='Fibonacci ')
fib05          =             input.float    (0.5    ,'Fibonacci Level 3             ',group='Fibonacci ')
fib0786        =             input.float    (0.786  ,'Fibonacci Level 4             ',group='Fibonacci ')
fib0618        =             input.float    (0.618  ,'Fibonacci Level 5             ',group='Fibonacci ')
fib1236        =             input.float    (1.236  ,'Fibonacci Level 6             ',group='Fibonacci ')
fib1382        =             input.float    (1.382  ,'Fibonacci Level 7             ',group='Fibonacci ')
fib1618        =             input.float    (1.618  ,'Fibonacci Level 8             ',group='Fibonacci ')


rsio=request.security(syminfo.ticker,tf,ta.rsi(ta.linreg(open ,(ta.rsi(hl2,8)>50?(12):A1Length),0),16))-50
rsih=request.security(syminfo.ticker,tf,ta.rsi(ta.linreg(high ,(ta.rsi(hl2,8)>50?(12):A1Length),0),16))-50
rsil=request.security(syminfo.ticker,tf,ta.rsi(ta.linreg(low  ,(ta.rsi(hl2,8)>50?(12):A1Length),0),16))-50
rsic=request.security(syminfo.ticker,tf,ta.rsi(ta.linreg(close,(ta.rsi(hl2,8)>50?(12):A1Length),0),16))-50
ccio=request.security(syminfo.ticker,tf,ta.cci(ta.linreg(open ,(ta.cci(hl2,8)>50?(48):A3Length ),0),A1Length))/4
ccih=request.security(syminfo.ticker,tf,ta.cci(ta.linreg(high ,(ta.cci(hl2,8)>50?(48):A3Length ),0),A1Length))/4
ccil=request.security(syminfo.ticker,tf,ta.cci(ta.linreg(low  ,(ta.cci(hl2,8)>50?(48):A3Length ),0),A1Length))/4
ccic=request.security(syminfo.ticker,tf,ta.cci(ta.linreg(close,(ta.cci(hl2,8)>50?(48):A3Length ),0),A1Length))/4
ccrsiav=math.avg(rsio,rsih,rsil,rsic,ccio,ccih,ccil,ccic)
o = ccrsiav>ccrsiav[1]?math.min(rsio,ccio):math.max(rsio,ccio)
h = math.max(rsih,ccih)
l = math.min(rsil,ccil)
c = ccrsiav>ccrsiav[1]?math.max(rsic,ccic):math.min(rsic,ccic)
ohlc=math.avg(o,h,l,c)
hl=ta.sma(ta.highest(h,A5Length)-ta.lowest(l,A5Length),A8Length)
hlx=ta.sma(ta.highest(h,A1Length)-ta.lowest(l,A1Length),A1Length)

ma1      =  ta.sma(ohlc,A1Length)
ma2      =  ta.ema(ohlc,A3Length)
ma3      =  ta.wma(ohlc,A7Length)
ma3a     =  ta.sma(ma3+(hl/2.68),A3Length)
ma3b     =  ta.sma(ma3-(hl/2.68),A3Length)
ma3c     =  math.avg(ma3a,ma3b)
ma4a     =  ta.sma(ma3+(hl/1.68),A3Length)
ma4b     =  ta.sma(ma3-(hl/1.68),A3Length)
ma5      =  ta.linreg(ohlc,A5Length,0)
coppock1 =ta.wma(ta.roc(hl2,11)+ta.roc(hl2,14),10)
coppock2 =coppock1>100 ?coppock1-(coppock1-100): coppock1<-100?coppock1-(coppock1+100):coppock1
loppock1 =ta.swma(ta.linreg(ta.roc(ta.cci(ta.highest(high,4)-ta.lowest(low,4),momLen),11)+ta.roc(ta.cci(ta.highest(high,4)-ta.lowest(low,4),momLen),14),10,0))/2
loppock2 =loppock1>100 ?loppock1-(loppock1-100): loppock1<-100?loppock1-(loppock1+100):loppock1
curve1   = ta.alma(ta.ema(c,(A1Length/2)),A1Length                                 ,Offset,Sigma)
curve1a  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5  ,Offset,Sigma)   
curve1b  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5*2,Offset,Sigma)
curve1c  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5*3,Offset,Sigma)
curve1d  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5*4,Offset,Sigma)
curve1e  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5*5,Offset,Sigma)
curve1f  = ta.alma(ta.ema(c,(A1Length/2)),A1Length + (A2Length  - A1Length)   / 5*6,Offset,Sigma)
curve3   = ta.alma(ta.ema(c,(A1Length/2)),A3Length                                 ,Offset,Sigma)
curve3a  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5  ,Offset,Sigma)
curve3b  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5*2,Offset,Sigma)
curve3c  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5*3,Offset,Sigma)
curve3d  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5*4,Offset,Sigma)
curve3e  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5*5,Offset,Sigma)
curve3f  = ta.alma(ta.ema(c,(A1Length/2)),A3Length + (A4Length  - A3Length)   / 5*6,Offset,Sigma)
curve5   = ta.alma(ta.ema(c,(A1Length/2)),A5Length                                 ,Offset,Sigma)
curve5a  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5  ,Offset,Sigma)  
curve5b  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5*2,Offset,Sigma)
curve5c  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5*3,Offset,Sigma)
curve5d  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5*4,Offset,Sigma)
curve5e  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5*5,Offset,Sigma)
curve5f  = ta.alma(ta.ema(c,(A1Length/2)),A5Length + (A6Length  - A5Length)   / 5*6,Offset,Sigma)
curve7   = ta.alma(ta.ema(c,(A1Length/2)),A7Length                                 ,Offset,Sigma)
curve7a  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5  ,Offset,Sigma)
curve7b  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5*2,Offset,Sigma)
curve7c  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5*3,Offset,Sigma)
curve7d  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5*4,Offset,Sigma)
curve7e  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5*5,Offset,Sigma)
curve7f  = ta.alma(ta.ema(c,(A1Length/2)),A7Length + (A8Length  - A7Length)   / 5*6,Offset,Sigma)
curve9   = ta.alma(ta.ema(c,(A1Length/2)),A9Length                                 ,Offset,Sigma)
curve9a  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5  ,Offset,Sigma)
curve9b  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5*2,Offset,Sigma)
curve9c  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5*3,Offset,Sigma)
curve9d  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5*4,Offset,Sigma)
curve9e  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5*5,Offset,Sigma)
curve9f  = ta.alma(ta.ema(c,(A1Length/2)),A9Length + (A10Length - A9Length)   / 5*6,Offset,Sigma)
xcurve1  = ta.alma(coppock1               ,A1Length                                 ,Offset,Sigma)
xcurve1a = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5  ,Offset,Sigma)   
xcurve1b = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5*2,Offset,Sigma)
xcurve1c = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5*3,Offset,Sigma)
xcurve1d = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5*4,Offset,Sigma)
xcurve1e = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5*5,Offset,Sigma)
xcurve1f = ta.alma(coppock1               ,A1Length + (A2Length  - A1Length)   / 5*6,Offset,Sigma)
xcurve3  = ta.alma(coppock1               ,A3Length                                 ,Offset,Sigma)
xcurve3a = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5  ,Offset,Sigma)
xcurve3b = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5*2,Offset,Sigma)
xcurve3c = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5*3,Offset,Sigma)
xcurve3d = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5*4,Offset,Sigma)
xcurve3e = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5*5,Offset,Sigma)
xcurve3f = ta.alma(coppock1               ,A3Length + (A4Length  - A3Length)   / 5*6,Offset,Sigma)
xcurve5  = ta.alma(coppock1               ,A5Length                                 ,Offset,Sigma)
xcurve5a = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5  ,Offset,Sigma)  
xcurve5b = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5*2,Offset,Sigma)
xcurve5c = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5*3,Offset,Sigma)
xcurve5d = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5*4,Offset,Sigma)
xcurve5e = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5*5,Offset,Sigma)
xcurve5f = ta.alma(coppock1               ,A5Length + (A6Length  - A5Length)   / 5*6,Offset,Sigma)
xcurve7  = ta.alma(coppock1               ,A7Length                                 ,Offset,Sigma)
xcurve7a = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5  ,Offset,Sigma)
xcurve7b = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5*2,Offset,Sigma)
xcurve7c = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5*3,Offset,Sigma)
xcurve7d = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5*4,Offset,Sigma)
xcurve7e = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5*5,Offset,Sigma)
xcurve7f = ta.alma(coppock1               ,A7Length + (A8Length  - A7Length)   / 5*6,Offset,Sigma)
xcurve9  = ta.alma(coppock1               ,A9Length                                 ,Offset,Sigma)
xcurve9a = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5  ,Offset,Sigma)
xcurve9b = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5*2,Offset,Sigma)
xcurve9c = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5*3,Offset,Sigma)
xcurve9d = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5*4,Offset,Sigma)
xcurve9e = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5*5,Offset,Sigma)
xcurve9f = ta.alma(coppock1               ,A9Length + (A10Length - A9Length)   / 5*6,Offset,Sigma)
av1      = ta.rsi(math.avg(curve1 , curve1a , curve1b , curve1c , curve1d , curve1e),A1Length)-50
av3      = ta.rsi(math.avg(curve3 , curve3a , curve3b , curve3c , curve3d , curve3e),A1Length)-50
av5      = ta.rsi(math.avg(curve5 , curve5a , curve5b , curve5c , curve5d , curve5e),A1Length)-50
av7      = ta.rsi(math.avg(curve7 , curve7a , curve7b , curve7c , curve7d , curve7e),A1Length)-50
av9      = ta.rsi(math.avg(curve9 , curve9a , curve9b , curve9c , curve9d , curve9e),A1Length)-50
xav1     = ta.cci(math.avg(xcurve1 , xcurve1a , xcurve1b , xcurve1c , xcurve1d , xcurve1e),A1Length) /5
xav3     = ta.cci(math.avg(xcurve3 , xcurve3a , xcurve3b , xcurve3c , xcurve3d , xcurve3e),A1Length) /5
xav5     = ta.cci(math.avg(xcurve5 , xcurve5a , xcurve5b , xcurve5c , xcurve5d , xcurve5e),A1Length) /5
xav7     = ta.cci(math.avg(xcurve7 , xcurve7a , xcurve7b , xcurve7c , xcurve7d , xcurve7e),A1Length) /5
xav9     = ta.cci(math.avg(xcurve9 , xcurve9a , xcurve9b , xcurve9c , xcurve9d , xcurve9e),A1Length) /5

max1= ta.linreg(math.max(xav1 ,av1 ),c>hl?A1Length:(12),0)
max3= ta.linreg(math.max(xav3 ,av3 ),c>hl?A1Length:(12),0)
max5= ta.linreg(math.max(xav5 ,av5 ),c>hl?A1Length:(12),0)
max7= ta.linreg(math.max(xav7 ,av7 ),c>hl?A1Length:(12),0)
max9= ta.linreg(math.max(xav9 ,av9 ),c>hl?A1Length:(12),0)
min1= ta.linreg(math.min(xav1 ,av1 ),c>hl?A1Length:(12),0)
min3= ta.linreg(math.min(xav3 ,av3 ),c>hl?A1Length:(12),0)
min5= ta.linreg(math.min(xav5 ,av5 ),c>hl?A1Length:(12),0)
min7= ta.linreg(math.min(xav7 ,av7 ),c>hl?A1Length:(12),0)
min9= ta.linreg(math.min(xav9 ,av9 ),c>hl?A1Length:(12),0)



BullOverbought  = ta.highest(c[FibOffset] ,h>hl?lookback1:lookback2)
BearOversold    = ta.lowest (c[FibOffset] ,l<hl?lookback1:lookback2)
minav=ta.ema(math.avg(min1,min9,c,BearOversold  )-(.382*hl),A1Length)
maxav=ta.ema(math.avg(max1,max9,c,BullOverbought)+(.382*hl),A1Length)
max=ta.sma(math.max(xav1,av1,xav3,av3,xav5,av5,xav7,av7,xav9,av9)+ta.wma((maxav-h)/1.618,32),64)
min=ta.sma(math.min(xav1,av1,xav3,av3,xav5,av5,xav7,av7,xav9,av9)-ta.wma((l-minav)/1.618,32),64)
mid=math.avg(max,min)
maxx=max>maxav
minn=min<minav

BullOverbought0 = SmoothFib?ta.ema(BullOverbought*fib0236,SmoothLen) :(BullOverbought*fib0236)
BearOversold0   = SmoothFib?ta.ema(BearOversold  *fib0236,SmoothLen) :(BearOversold  *fib0236)
FibOverbought1  = SmoothFib?ta.ema(BullOverbought*fib0382,SmoothLen) :(BullOverbought*fib0382)
FibOversold1    = SmoothFib?ta.ema(BearOversold  *fib0382,SmoothLen) :(BearOversold  *fib0382)
FibOverbought2  = SmoothFib?ta.ema(BullOverbought*fib05  ,SmoothLen) :(BullOverbought*fib05  )
FibOversold2    = SmoothFib?ta.ema(BearOversold  *fib05  ,SmoothLen) :(BearOversold  *fib05  )
FibOverbought3  = SmoothFib?ta.ema(BullOverbought*fib0618,SmoothLen) :(BullOverbought*fib0786)
FibOversold3    = SmoothFib?ta.ema(BearOversold  *fib0618,SmoothLen) :(BearOversold  *fib0786)
FibOverbought4  = SmoothFib?ta.ema(BullOverbought*fib0786,SmoothLen) :(BullOverbought*fib0618)
FibOversold4    = SmoothFib?ta.ema(BearOversold  *fib0786,SmoothLen) :(BearOversold  *fib0618)
FibOverbought5  = SmoothFib?ta.ema(BullOverbought*fib1236,SmoothLen) :(BullOverbought*fib1236)
FibOversold5    = SmoothFib?ta.ema(BearOversold  *fib1236,SmoothLen) :(BearOversold  *fib1236)
//FibOverbought6  = SmoothFib?ta.ema(BullOverbought*fib1382,SmoothLen) :(BullOverbought*fib1382)
//FibOversold6    = SmoothFib?ta.ema(BearOversold  *fib1382,SmoothLen) :(BearOversold  *fib1382)
//FibOverbought7  = SmoothFib?ta.ema(BullOverbought*fib1618,SmoothLen) :(BullOverbought*fib1618)
//FibOversold7    = SmoothFib?ta.ema(BearOversold  *fib1618,SmoothLen) :(BearOversold  *fib1618)
//colors
rsi_colors      = color.new(rsio<rsic?input.color(#acfb00    ,'Up'    ,group='RSI' ):input.color(#ff0000     ,'Down'    ,group='RSI' ),0)
cci_colors      = color.new(ccio<ccic?input.color(#acfb00    ,'Up'    ,group='CCI' ):input.color(#ff0000     ,'Down'    ,group='CCI' ),0)
span_colors     = color.new(o<c      ?input.color(color.olive,'SpanUp',group='Span'):input.color(#7d0909     ,'SpanDown',group='Span'),0)
fib_color       = color.new(input.color(#ffffff,'Fib Color       '  ),80),                                  
Overbought_color= color.new(input.color(#ff0000,'Overbought Color'  ),40),                                  
Oversold_color  = color.new(input.color(#acfb00,'Oversold Color  '  ),40),                                  
//FIB               '

Oversoldplot    = plot(Bound ? BearOversold    : na,'Lower Boundary'              ,color=color.new(Oversold_color  ,40)  ,linewidth=2,style=plot.style_linebr) 
Oversold0plot   = plot(Fib   ? BearOversold0   : na,'Inner Fib Oversold(0.236)'   ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Oversold1plot   = plot(Fib   ? FibOversold1    : na,'Inner Fib Oversold(0.382)'   ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Oversold2plot   = plot(Fib   ? FibOversold2    : na,'Inner Fib Oversold(0.5  )'   ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Oversold3plot   = plot(Fib   ? FibOversold3    : na,'Inner Fib Oversold(0.618)'   ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Oversold4plot   = plot(Fib   ? FibOversold4    : na,'Inner Fib Oversold(0.786)'   ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Overboughtplot  = plot(Bound ? BullOverbought  : na,'Upper Boundary'              ,color=color.new(Overbought_color,40)  ,linewidth=2,style=plot.style_linebr) 
Overbought0plot = plot(Fib   ? BullOverbought0 : na,'Inner Fib Overbought(0.236)' ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Overbought1plot = plot(Fib   ? FibOverbought1  : na,'Inner Fib Overbought(0.382)' ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Overbought2plot = plot(Fib   ? FibOverbought2  : na,'Inner Fib Overbought(0.5  )' ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Overbought3plot = plot(Fib   ? FibOverbought3  : na,'Inner Fib Overbought(0.618)' ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
Overbought4plot = plot(Fib   ? FibOverbought4  : na,'Inner Fib Overbought(0.786)' ,color=fib_color                       ,linewidth=1,style=plot.style_linebr) 
ma3cplot        = plot(ma3c,color=color.white,style=plot.style_linebr,linewidth=2)
ma5plot         = plot(ma5,color=color.orange)
midplot         = plot(mid  ,'Mid'        , color=color.new(color.gray,60 ))
minplot         = plot(min  ,'Min'        , color=color.new(c<hl?             Oversold_color  :Overbought_color,60 ))
maxplot         = plot(max  ,'Max'        , color=color.new(c<hl?             Overbought_color:Oversold_color,60   ))
minavplot       = plot(minav,'Min Average', color=color.new(Background?o<c?Oversold_color:Overbought_color:na,95),style=plot.style_areabr,histbase=-100)
maxavplot       = plot(maxav,'Max Average', color=color.new(Background?o>c?Overbought_color:Oversold_color:na,95),style=plot.style_areabr,histbase=+100)
coppockplot     = plot(coppock2*3                ,'Coppock Curve    ',linewidth=3,color=color.blue)
loppockplot     = plot(loppock2/5                ,'Loppock Momentum Curve',linewidth=2,color=color.new(loppock1/3>maxav or loppock1/3 < minav?color.fuchsia:color.purple,40))
fill(minavplot,maxavplot,color=color.new(color.gray,97))
fill(minplot,minavplot,color=minn and not maxx ?color.new(Background?#acfb00:na,80):color.new(color.gray,95))
fill(maxplot,maxavplot,color=maxx and not minn ?color.new(Background?#ff0000:na,80):color.new(color.gray,95))
plotcandle(o,h,l,c            ,'Span Candles',color=color.new(span_colors,90),wickcolor=color.new(span_colors,10),bordercolor=color.new(span_colors,20))
plotcandle(rsio,rsih,rsil,rsic,'RSI Candles ',color=color.new(rsi_colors ,40),wickcolor=color.new(rsi_colors ,10),bordercolor=color.new(rsi_colors ,20))
plotcandle(ccio,ccih,ccil,ccic,'CCI Candles ',color=color.new(cci_colors ,40),wickcolor=color.new(cci_colors ,10),bordercolor=color.new(cci_colors ,20))
h0=hline(0  ,'Zero',linewidth=2,color=color.white)
h1=hline(30 ,'30  ',linewidth=2,color=Overbought_color)
h2=hline(-30,'-30 ',linewidth=2,color=Oversold_color)


//plot(ma1,color=color.purple)
//plot(ma2,color=color.navy)
//plot(ma3,color =color.gray)
//plot(ma3a,color=color.black)
//plot(ma3b,color=color.black)
//plot(ma4a,color=color.black)
//plot(ma4b,color=color.black)