[TTI] ATR channels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TintinTrading
//@version=5

indicator(title='[TTI] ATR channels', overlay=true, shorttitle='ATRch')

//USER INPUTS
length = input.int(20, minval=0, title='Average length', tooltip = 'Moving average length')
inst_length = input.int(200, minval = 0, maxval=500, title = 'Institutional Length', tooltip = 'Define the length for the Institutional averages')

//TURN ON/OFF CONDITIONS FOR ATRS
ATR1_on = input.bool (defval = true, tooltip = 'Show First ATR', inline = '1x', group='Short Term ATRs')
ATR2_on = input.bool (defval = true, tooltip = 'Show Second ATR', inline = '2x', group='Short Term ATRs')
ATR3_on = input.bool (defval = true, tooltip = 'Show Third ATR', inline = '3x', group='Short Term ATRs')
ATR5_on = input.bool (defval = false, tooltip = 'Show Mid Term Institutional ATR', inline = '5x', group='Institutional ATRs')
ATR10_on = input.bool (defval = false, tooltip = 'Show Long Term Institutional ATR', inline = '10x', group='Institutional ATRs')
ATR_LAST = input.bool (defval = true, inline = 'll', group='Show Last ATRs')
ATR_LASTD = input.int (defval = 10, title = 'Show Last X bars', inline = 'll', group='Show Last ATRs')

//KELTNER CHANNEL MULTIPLIERS
multiplier1 = input.int(1, minval=0, title='ATR Multiplier 1', tooltip = 'Customise how long you want the first multiplier', inline = '1x', group='Short Term ATRs')
multiplier2 = input.int(2, minval=0, title='ATR Multiplier 2', tooltip = 'Customise how long you want the second multiplier', inline = '2x', group='Short Term ATRs')
multiplier3 = input.int(3, minval=0, title='ATR Multiplier 3', tooltip = 'Customise how long you want the third multiplier', inline = '3x', group='Short Term ATRs')
multiplier5 = input.int(5, minval=0, title='Mid Term ATR Multiplier 1', tooltip = 'Customise how long you want the third multiplier', inline = '5x', group='Institutional ATRs')
multiplier10 = input.int(10, minval=0, title='Long Term ATR Multiplier 2', tooltip = 'Customise how long you want the third multiplier', inline = '10x', group='Institutional ATRs')



//CALCULATIONS
//{
exponential1 = input(true, title='Exponential MA?')
ema_1 = ta.ema(close, length)
sma_1 = ta.sma(close, length)
mean = exponential1 ? ema_1 : sma_1

exponential2 = input(true, title='Exponential ATR?')
ema_2 = ta.ema(ta.tr, length)
sma_2 = ta.sma(ta.tr, length)
ATR = exponential2 ? ema_2 : sma_2
//}

//SHORT TERM ATRS
//{{
ATR3 = mean + multiplier3 * ATR
ATR2 = mean + multiplier2 * ATR
ATR1 = mean + multiplier1 * ATR
ATR_1 = mean - multiplier1 * ATR
ATR_2 = mean - multiplier2 * ATR
ATR_3 = mean - multiplier3 * ATR
//}}


//LONG TERM ATRS
//{{
ATR5 = ta.ema(close,inst_length) + multiplier5 * ta.ema(ta.tr, inst_length)
ATR10 = ta.ema(close,inst_length) + multiplier10 * ta.ema(ta.tr, inst_length)
ATR_5 = ta.ema(close,inst_length) - multiplier5 * ta.ema(ta.tr, inst_length)
ATR_10 = ta.ema(close,inst_length) - multiplier10 * ta.ema(ta.tr, inst_length)
//}}

//PLOTTING
//{{
ATRR10 = plot(ATR10_on and not ATR_LAST ? ATR10 : na, title = "LT Institutional ATR", color = color.new(color.blue,0), style = plot.style_circles)
ATRR5 = plot(ATR5_on  and not ATR_LAST ? ATR5 : na, title = "MT Institutional ATR", color = color.new(color.purple,0), style = plot.style_circles)
ATRR3 = plot(ATR3_on  and not ATR_LAST ? ATR3 : na, title="3x Plus", color=color.new(color.white, 0))
ATRR2 = plot(ATR2_on  and not ATR_LAST ? ATR2 : na, title="2x Plus", color=color.new(color.green, 0))
ATRR1 = plot(ATR1_on  and not ATR_LAST ? ATR1 : na, title="1x Plus", color=color.new(color.white, 50))

ATRRm = plot(mean,  title="Mid line", color=color.new(color.aqua, 0), linewidth=3)

ATRR1_ = plot(ATR1_on  and not ATR_LAST ? ATR_1 : na, title="1x Minus", color=color.new(color.white, 50))
ATRR2_ = plot(ATR2_on and not ATR_LAST ? ATR_2 : na, title="2x Minus", color=color.new(color.red, 0))
ATRR3_ = plot(ATR3_on and not ATR_LAST ? ATR_3 : na, title="3x Minus", color=color.new(color.white, 0))
ATRR5_ =plot(ATR5_on and not ATR_LAST ? ATR_5 : na, title = "MT Institutional ATR", color = color.new(color.purple ,0), style = plot.style_circles)
ATRR10_ =plot(ATR10_on and not ATR_LAST ? ATR_10 : na, title = "LT Institutional ATR", color = color.new(color.blue,0), style = plot.style_circles)


//Show LAST 10
ATRR10L = plot(ATR10_on and ATR_LAST ? ATR10 : na, title = "LT Institutional ATR", color = color.new(color.blue,0), style = plot.style_circles, show_last = ATR_LASTD)
ATRR5L = plot(ATR5_on and ATR_LAST ? ATR5 : na, title = "MT Institutional ATR", color = color.new(color.purple,0), style = plot.style_circles, show_last = ATR_LASTD)
ATRR3L = plot(ATR3_on and ATR_LAST ? ATR3 : na, title="3x Plus", color=color.new(color.white, 0), show_last = ATR_LASTD)
ATRR2L = plot(ATR2_on and ATR_LAST ? ATR2 : na, title="2x Plus", color=color.new(color.green, 0), show_last = ATR_LASTD)
ATRR1L = plot(ATR1_on and ATR_LAST ? ATR1 : na, title="1x Plus", color=color.new(color.white, 50), show_last = ATR_LASTD)

//ATRRm = plot(mean,  title="Mid line", color=color.new(color.aqua, 0), linewidth=3)

ATRR1_L = plot(ATR1_on and ATR_LAST ? ATR_1 : na, title="1x Minus", color=color.new(color.white, 50), show_last = ATR_LASTD)
ATRR2_L = plot(ATR2_on and ATR_LAST ? ATR_2 : na, title="2x Minus", color=color.new(color.red, 0), show_last = ATR_LASTD)
ATRR3_L = plot(ATR3_on and ATR_LAST ? ATR_3 : na, title="3x Minus", color=color.new(color.white, 0), show_last = ATR_LASTD)
ATRR5_L =plot(ATR5_on and ATR_LAST ? ATR_5 : na, title = "MT Institutional ATR", color = color.new(color.purple ,0), style = plot.style_circles, show_last = ATR_LASTD)
ATRR10_L =plot(ATR10_on and ATR_LAST ? ATR_10 : na, title = "LT Institutional ATR", color = color.new(color.blue,0), style = plot.style_circles, show_last = ATR_LASTD)

//FILL between insitutional ATRS
fill(ATRR5,ATRR5_ , color = color.new(color.purple,80), title = 'MT Insitutional ATR fill')
fill(ATRR10,ATRR5, color = color.new(color.blue,80), title = 'LT Insitutional ATR+ fill')
fill(ATRR10_,ATRR5_, color = color.new(color.blue,80), title = 'LT Insitutional ATR– fill')


//}}