defparam calculateonlastbars=1000
lookback=20
CCIper=14
RSIper=14
MaPeriod=2
koef=8
//arrows=1 //1 = true , 0 = false
if(koef>8 or koef<0) then
koef=8
endif
llimit = lookback
typical = (high[0] + low[0] + close[0])/3
for i = llimit-3 downto 0 do
//typical = (high[i] + low[i] + close[i])/3
a = cci[CCIper](typical)[i]-rsi[RSIper](typical)[i]
b = rsi[RSIper](typical)[i]-cci[CCIper](typical)[i]
if(i-1>=0) then
a1 = cci[CCIper](typical)[i-1]-rsi[RSIper](typical)[i+1]
b1 = rsi[CCIper](typical)[i-1]-cci[RSIper](typical)[i+1]
endif
if(i-2>=0) then
a2 = cci[CCIper](typical)[i-2]-rsi[RSIper](typical)[i+2]
b2 = rsi[CCIper](typical)[i-2]-cci[RSIper](typical)[i+2]
endif
if(i-3>=0) then
a3 = cci[CCIper](typical)[i-3]-rsi[RSIper](typical)[i+3]
b3 = rsi[CCIper](typical)[i-3]-cci[RSIper](typical)[i+3]
endif
if(i-4>=0) then
a4 = cci[CCIper](typical)[i-4]-rsi[RSIper](typical)[i+4]
b4 = rsi[CCIper](typical)[i-4]-cci[RSIper](typical)[i+4]
endif
if(i-5>=0) then
a5 = cci[CCIper](typical)[i-5]-rsi[RSIper](typical)[i+5]
b5 = rsi[CCIper](typical)[i-5]-cci[RSIper](typical)[i+5]
endif
if(i-6>=0) then
a6 = cci[CCIper](typical)[i-6]-rsi[RSIper](typical)[i+6]
b6 = rsi[CCIper](typical)[i-6]-cci[RSIper](typical)[i+6]
endif
if(i-7>=0) then
a7 = cci[CCIper](typical)[i-7]-rsi[RSIper](typical)[i+7]
b7 = rsi[CCIper](typical)[i-7]-cci[RSIper](typical)[i+7]
endif
if(i-8>=0) then
a8 = cci[CCIper](typical)[i-8]-rsi[RSIper](typical)[i+8]
b8 = rsi[CCIper](typical)[i-8]-cci[RSIper](typical)[i+8]
endif
next
if koef=8 then
tt1max=a+a1+a2+a3+a4+a5+a6+a7+a8
tt2min=b+b1+b2+b3+b4+b5+b6+b7+b8
endif
bull = average[MaPeriod](tt1max)
bear = average[MaPeriod](tt2min)
return bull coloured(0,191,255) style(line,2), bear coloured(255,0,0) style(line,2)