EXAMPLES:enhanced_ta
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed

//   __    __            __       __  __                  __       __                        __      __    __              __      _______             __    __                                          __ 
//  /  |  /  |          /  |  _  /  |/  |                /  \     /  |                      /  |    /  \  /  |            /  |    /       \           /  \  /  |                                        /  |
//  $$ |  $$ |  ______  $$ | / \ $$ |$$ |____    ______  $$  \   /$$ | __    __   _______  _$$ |_   $$  \ $$ |  ______   _$$ |_   $$$$$$$  |  ______  $$  \ $$ |  ______   _____  ____    ______    ____$$ |
//  $$ |__$$ | /      \ $$ |/$  \$$ |$$      \  /      \ $$$  \ /$$$ |/  |  /  | /       |/ $$   |  $$$  \$$ | /      \ / $$   |  $$ |__$$ | /      \ $$$  \$$ | /      \ /     \/    \  /      \  /    $$ |
//  $$    $$ |/$$$$$$  |$$ /$$$  $$ |$$$$$$$  |/$$$$$$  |$$$$  /$$$$ |$$ |  $$ |/$$$$$$$/ $$$$$$/   $$$$  $$ |/$$$$$$  |$$$$$$/   $$    $$< /$$$$$$  |$$$$  $$ | $$$$$$  |$$$$$$ $$$$  |/$$$$$$  |/$$$$$$$ |
//  $$$$$$$$ |$$    $$ |$$ $$/$$ $$ |$$ |  $$ |$$ |  $$ |$$ $$ $$/$$ |$$ |  $$ |$$      \   $$ | __ $$ $$ $$ |$$ |  $$ |  $$ | __ $$$$$$$  |$$    $$ |$$ $$ $$ | /    $$ |$$ | $$ | $$ |$$    $$ |$$ |  $$ |
//  $$ |  $$ |$$$$$$$$/ $$$$/  $$$$ |$$ |  $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$  |  $$ |/  |$$ |$$$$ |$$ \__$$ |  $$ |/  |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
//  $$ |  $$ |$$       |$$$/    $$$ |$$ |  $$ |$$    $$/ $$ | $/  $$ |$$    $$/ /     $$/   $$  $$/ $$ | $$$ |$$    $$/   $$  $$/ $$    $$/ $$       |$$ | $$$ |$$    $$ |$$ | $$ | $$ |$$       |$$    $$ |
//  $$/   $$/  $$$$$$$/ $$/      $$/ $$/   $$/  $$$$$$/  $$/      $$/  $$$$$$/  $$$$$$$/     $$$$/  $$/   $$/  $$$$$$/     $$$$/  $$$$$$$/   $$$$$$$/ $$/   $$/  $$$$$$$/ $$/  $$/  $$/  $$$$$$$/  $$$$$$$/ 
//                                                                                                                                                                                                          
//                                                                                                                                                                                             
//@version=5
import HeWhoMustNotBeNamed/enhanced_ta/4 as eta
indicator("enhanced_ta_examples", overlay=true)

display = input.string("ma", title="Display Indicator", options=["all", "ma", "atr",
                                                                     "band", "bandwidth", "bandpercent","oscillator"])
overlay = input.bool(true, title="Overlay", inline="o")
nonOverlay = input.bool(true, title="NonOverlay", inline="o")
//************************************ ma *************************************************** //
masource = input.source(close, title="Source", group="Moving Average")
matype = input.string("sma", title="Type", group="Moving Average", options=["sma", "ema", "hma", "rma", "wma", "vwma", "swma", "linreg", "median"])
malength = input.int(20, title="Length", group="Moving Average")

ma = eta.ma(masource, matype, malength)
displayMa = display == "ma" or (display == "all" and overlay)
plot(displayMa? ma : na, title="Moving Average", color=color.blue)
//************************************ ATR *************************************************** //
amatype = input.string("sma", title="Type", group="ATR", options=["sma", "ema", "hma", "rma", "wma", "vwma", "swma", "linreg", "median"])
amalength = input.int(20, title="Length", group="ATR")
displayPercent = input.bool(false, title="Display as Percent", group="ATR")
atr = eta.atr(amatype, amalength)
atrpercent = eta.atrpercent(amatype, amalength)
displayAtr = display == "atr" or (display == "all" and nonOverlay)
plot(displayAtr? displayPercent? atrpercent : atr : na, title="ATR (or Percent)", color = color.blue)
//************************************ bands *************************************************** //
bandType = input.string("BB", title="Type", group="Bands/Bandwidth/BandPercent", options=["BB", "KC", "DC"])
bmasource = input.source(close, title="Source", group="Bands/Bandwidth/BandPercent")
bmatype = input.string("sma", title="Type", group="Bands/Bandwidth/BandPercent", options=["sma", "ema", "hma", "rma", "wma", "vwma", "swma", "linreg", "median"])
bmalength = input.int(20, title="Length", group="Bands/Bandwidth/BandPercent")
multiplier = input.float(2.0, step=0.5, title="Multiplier", group="Bands/Bandwidth/BandPercent")
useTrueRange = input.bool(true, title="Use True Range (KC)", group="Bands/Bandwidth/BandPercent")
useAlternateSource = input.bool(false, title="Use Alternate Source (DC)", group="Bands/Bandwidth/BandPercent")
bsticky = input.bool(true, title="Sticky", group="Bands/Bandwidth/BandPercent")

displayBands = display == "band" or (display == "all" and overlay)
var cloudTransparency = 90
[bbmiddle, bbupper, bblower] = eta.bb(bmasource, bmatype, bmalength, multiplier, sticky=bsticky)
[kcmiddle, kcupper, kclower] = eta.kc(bmasource, bmatype, bmalength, multiplier, useTrueRange, sticky=bsticky)
[dcmiddle, dcupper, dclower] = eta.dc(bmalength, useAlternateSource, bmasource, sticky=bsticky)

upper = bandType == "BB"? bbupper : bandType == "KC"? kcupper : dcupper
lower = bandType == "BB"? bblower : bandType == "KC"? kclower : dclower
middle = bandType == "BB"? bbmiddle : bandType == "KC"? kcmiddle : dcmiddle

uPlot = plot(displayBands? upper: na, title="Upper", color=color.new(color.green, cloudTransparency))
lPlot = plot(displayBands? lower: na, title="Lower", color=color.new(color.red, cloudTransparency))
mPlot = plot(displayBands? middle: na, title="Middle", color=color.new(color.blue, cloudTransparency))

fill(uPlot, mPlot, title='UpperRange', color=color.new(color.green, cloudTransparency))
fill(lPlot, mPlot, title='LowerRange', color=color.new(color.red, cloudTransparency))
//************************************ bandwidth *************************************************** //
bbw = eta.bbw(bmasource, bmatype, bmalength, multiplier, sticky=bsticky)
kcw = eta.kcw(bmasource, bmatype, bmalength, multiplier, useTrueRange, sticky=bsticky)
dcw = eta.dcw(bmalength, useAlternateSource, bmasource, sticky=bsticky)

bandwidth = bandType == "BB"? bbw : bandType == "KC"? kcw : dcw
displayBandwidth = display == "bandwidth" or (display == "all" and nonOverlay)
plot(displayBandwidth? bandwidth: na, title="Bandwidth", color=color.maroon)

//************************************ bandpercent *************************************************** //
bpercentb = eta.bpercentb(bmasource, bmatype, bmalength, multiplier, sticky=bsticky)
kpercentk = eta.kpercentk(bmasource, bmatype, bmalength, multiplier, useTrueRange, sticky=bsticky)
dpercentd = eta.dpercentd(bmalength, useAlternateSource, bmasource, sticky=bsticky)

bandpercent = bandType == "BB"? bpercentb : bandType == "KC"? kpercentk : dpercentd
displayBandPercent = display == "bandpercent" or (display == "all" and nonOverlay)
plot(displayBandPercent? bandpercent: na, title="BandPercent", color=color.fuchsia)

//************************************ Oscillators *************************************************** //
oscType = input.string("cci", title="Oscillator Type", group="Oscillator", options=["cci", "cmo", "cog", "mfi", "roc", "rsi", "stoch", "tsi", "wpr"])
oLength = input.int(14, title="Length", group="Oscillator")
shortLength = input.int(9, title="Short Length (TSI)", group="Oscillator")
longLength = input.int(9, title="Long Length (TSI)", group="Oscillator")
method = input.string("highlow", title="Dynamic Overvought/Oversold Calculation method", group="Oscillator", options=["highlow", "sma", "ema", "hma", "rma", "wma", "vwma", "swma", "linreg", "median"])
highlowlength = input.int(50, title="Length", group="Oscillator")
osticky = input.bool(true, title="Sticky", group="Oscillator")
[oscillator, overbought, oversold] = eta.oscillator(oscType, oLength, shortLength, longLength, method = method, highlowLength=highlowlength, sticky=osticky)

// Just using oscillatorRange with only oscillator input
// [newUpper, newLower] = eta.oscillatorRange(oscillator, method, highlowlength, oLength, osticky)

displayOscillator = display == "oscillator" or (display == "all" and nonOverlay)
plot(displayOscillator? oscillator: na, title="Oscillator", color=color.blue)
plot(displayOscillator? overbought: na, title="Overbought", color=color.red)
plot(displayOscillator? oversold: na, title="Oversold", color=color.green)
