S2BU2 True Range Bands
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sucks2bu2

//@version=5
indicator(title = 'S2BU2 True Range Bands', shorttitle = 'S2BU2 TRB', timeframe = '', timeframe_gaps = true, overlay = true)

//==================================define Inputs==================================//
periodInput = input.int(title = 'ATR Length', defval = 14, minval = 1)
atrFactor = input.float(title = 'ATR Multiplier', defval = 1.0, minval = 0.1)



//==================================calculate data==================================//
float atr = ta.rma(ta.tr(true),periodInput)*atrFactor
//bands
float maOpen = ta.ema(open, periodInput)
float upperBand = maOpen + nz(atr[1])
float lowerBand = maOpen - nz(atr[1])



//====================================plot graphs====================================//
plotBase = plot(maOpen, color= color.white)
plotUpper = plot(upperBand, title = 'Upper Band', color = color.green)
plotLower = plot(lowerBand, title = 'Lower Band', color = color.red)

//fill space between bands
fill(plotBase, plotUpper, title = 'Background Positive', color = color.rgb(66, 245, 120, 95))
fill(plotBase, plotLower, title = 'Background Negative', color = color.rgb(245, 66, 66, 95))