MME MTF CCI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mme_trades

//@version=5

//This indicator will draw the following
//CCI- 8 of 5  minutes or Current Timeframe
//CCI-34 of 5  minutes or Current Timeframe
//CCI-34 of 30 minutes or appropriate HTF 

indicator('MME MTF CCI v1.1', shorttitle='MTF CCI v1.1', overlay=false)

group_cci = "CCI Settings"
len             = 8         //input(8, title='Length',  group=group_cci)
len2            = 34        //input(34, title='Length', group=group_cci)
src             = input(hlc3, title='CCI Source',       group=group_cci)
show_CCI8_5m    = input(true, title='Show CCI  8 CTF',  group=group_cci)
show_CCI34_5m   = input(true, title='Show CCI 34 CTF',  group=group_cci)
show_CCI34_30m  = input(true, title='Show CCI 34 HTF',  group=group_cci)
show_labels     = input(true, title='Show labels',      group=group_cci)

htf_auto        = timeframe.period == '1'   ? '5'  : 
                  timeframe.period == '3'   ? '5'  : 
                  timeframe.period == '5'   ? '30' : 
                  timeframe.period == '10'  ? '30' : 
                  timeframe.period == '15'  ? '30' : 
                  timeframe.period == '25'  ? 'D'  : 
                  timeframe.period == '30'  ? 'D'  : 
                  timeframe.period == '45'  ? 'D'  : 
                  timeframe.period == '60'  ? 'D'  : 
                  timeframe.period == '75'  ? 'D'  : 
                  timeframe.period == '120' ? 'D'  : 
                  timeframe.period == '180' ? 'D'  : 
                  timeframe.period == '240' ? 'D'  : 
                  timeframe.period == 'D'   ? 'W'  : 
                  timeframe.period == 'W'   ? 'M'  : 
                  timeframe.period == 'M'   ? '3M' :  '30'


cci8_5m     = ta.cci(src, len)
cci34_5m    = ta.cci(src, len2)
cci34_30m   = request.security(syminfo.tickerid, htf_auto, ta.cci(src, len2))

CCI8_5m_str     = str.format("{0,number,integer}", cci8_5m)
CCI34_5m_str    = str.format("{0,number,integer}", cci34_5m)
CCI34_30m_str   = str.format("{0,number,integer}", cci34_30m)

plot(show_CCI8_5m   ?   cci8_5m     : na, color=color.new(color.orange,0),  linewidth=1, title=' 8 CTF')
plot(show_CCI34_5m  ?   cci34_5m    : na, color=color.new(color.blue,0),    linewidth=2, title='34 CTF')
plot(show_CCI34_30m ?   cci34_30m   : na, color=color.new(color.red,0),     linewidth=3, title='34 HTF')

if show_CCI8_5m and show_labels
    cci8_5m_l = label.new(bar_index + 3,    cci8_5m,   text="CCI  8 "+timeframe.period,    color=color.white, textcolor=color.orange, size=size.small, style=label.style_none)
    label.delete(cci8_5m_l[1])
    
if show_CCI34_5m and show_labels
    cci34_5m_l = label.new(bar_index + 3,   cci34_5m,  text="CCI 34 "+timeframe.period,    color=color.white,   textcolor=color.blue,   size=size.small, style=label.style_none)
    label.delete(cci34_5m_l[1])

if show_CCI34_30m and show_labels
    cci34_30m_l = label.new(bar_index + 3,  cci34_30m, text="CCI 34 "+ htf_auto,           color=color.white,    textcolor=color.red,    size=size.small, style=label.style_none)
    label.delete(cci34_30m_l[1]) 

band1 = plot(135, title='135',      style=plot.style_circles,   linewidth=1, color=color.new(color.red, 50),    display=display.none,editable=false)
band2 = plot(100, title='100',      style=plot.style_circles,   linewidth=1, color=color.new(color.lime, 50),   display=display.none,editable=false)
band3 = plot(60, title='60',        style=plot.style_circles,   linewidth=1, color=color.new(color.green, 50),  display=display.none,editable=false)
band4 = plot(0, title='0',          style=plot.style_line,      linewidth=0, color=color.new(color.gray, 50),   display=display.none,editable=false)
band5 = plot(-60, title='-60',      style=plot.style_circles,   linewidth=1, color=color.new(color.green, 50),  display=display.none,editable=false)
band6 = plot(-100, title='-100',    style=plot.style_circles,   linewidth=1, color=color.new(color.lime, 50),   display=display.none,editable=false)
band7 = plot(-135, title='-135',    style=plot.style_circles,   linewidth=1, color=color.new(color.red, 50),    display=display.none,editable=false)


fill(band1, band2, color=color.new(color.fuchsia, 90),  editable=false)
fill(band3, band4, color=color.new(color.gray, 95),     editable=false)
fill(band4, band5, color=color.new(color.gray, 85),     editable=false)
fill(band6, band7, color=color.new(color.fuchsia, 90),  editable=false)
