UK Sectors Comparison SMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Berengrave

//@version=5
indicator("UK Sectors", shorttitle="UKS", overlay=false)

smalength = input.int(50, title="SMA Length", tooltip="Default = 50\n  Another good option is 100 or 200", group="Settings")
absolute = input.bool(false, title="Show absolute value", tooltip="Selected = show the absolute index value.\nNot Selected = show as a percentage increase / decrease baselined from baseline index (see tooltip below for more)", group="Settings")

base = input.symbol("CBOEEU:BUKAC",   title="Baseline Index", tooltip="Default = UK All Companies Index\nWhen Show absolute value is checked, this shows as a filled area (to easily see which is below it).\nWhen show absolute is not checked, it this index is represented by the 0% line", group="Baseline")

conc = input.symbol("CBOEEU:BUKCONC",   title="UK Consumer Cyclicals",              group="Sectors")
minp = input.symbol("CBOEEU:BUKMINP",   title="UK Mining and Minerals Products",    group="Sectors")
fin = input.symbol("CBOEEU:BUKFIN",     title="UK Financials",                      group="Sectors")
tec = input.symbol("CBOEEU:BUKTEC",     title="UK Technology",                      group="Sectors")
tel = input.symbol("CBOEEU:BUKTEL",     title="UK Telecoms",                        group="Sectors")
cons = input.symbol("CBOEEU:BUKCONS",   title="UK Consumer Services",               group="Sectors")
hlth = input.symbol("CBOEEU:BUKHLTH",   title="UK Healthcare",                      group="Sectors")
engy = input.symbol("CBOEEU:BUKENGY",   title="UK Energy",                          group="Sectors")
utl = input.symbol("CBOEEU:BUKUTL",     title="UK Utilities",                       group="Sectors")
bus = input.symbol("CBOEEU:BUKBUS",     title="UK Business Services",               group="Sectors")
cnc = input.symbol("CBOEEU:BUKCNC",     title="UK Consumer Non-Cyclicals",          group="Sectors")
ind = input.symbol("CBOEEU:BUKIND",     title="UK Industrials",                     group="Sectors")
nem = input.symbol("CBOEEU:BUKNEM",     title="UK Non-Energy Materials",            group="Sectors")

baseline = request.security(base, "D", close)
baselinesma = ta.sma(baseline, smalength)


getSma(sec, length) =>
    ss = request.security(sec, "D", close)
    sma = ta.sma(ss, length)
    pc = ((sma / baselinesma)*100)-100
    output = absolute ? sma : pc // return either the percentage value (vs baseline) or the raw sma data



plot(getSma(conc, length=smalength), color=#d98880, linewidth=1, editable=true, title="Cons Cyclicals")
plot(getSma(minp, length=smalength), color=#f1948a, linewidth=1, editable=true, title="Mining Minerals")
plot(getSma(fin, length=smalength), color=#ff0021, linewidth=1, editable=true, title="Finance")
plot(getSma(tec, length=smalength), color=#c39bd3, linewidth=1, editable=true, title="Tech")
plot(getSma(tel, length=smalength), color=#ff0041, linewidth=1, editable=true, title="Tel")
plot(getSma(cons, length=smalength), color=#bb8fce, linewidth=1, editable=true, title="Cons Servs")
plot(getSma(hlth, length=smalength), color=#7fb3d5, linewidth=1, editable=true, title="Health")
plot(getSma(engy, length=smalength), color=#85c1e9, linewidth=1, editable=true, title="Energy")
plot(getSma(utl, length=smalength), color=#76d7c4, linewidth=1, editable=true, title="Utilities")
plot(getSma(bus, length=smalength), color=#f5b041, linewidth=1, editable=true, title="Bus Svcs")
plot(getSma(cnc, length=smalength), color=#7dcea0, linewidth=1, editable=true, title="Cons NonCyc")
plot(getSma(ind, length=smalength), color=#82e0aa, linewidth=1, editable=true, title="Industrial")
plot(getSma(nem, length=smalength), color=#f7dc6f, linewidth=1, editable=true, title="NonEngergy Mats")

plot(getSma(base, length=smalength)[1], color=#00000009, linewidth=2, editable=true, style=plot.style_area, title="Baseline")
