Know Sure Thing + Ribbon
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © akikostas

//@version=5
indicator(title="Know Sure Thing [Log] + Ribbon", shorttitle="KST-L + Ribbon", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
roclen1 = input.int(10, minval=1, title = "ROC Length #1", group = "KST Settings")
roclen2 = input.int(15, minval=1, title = "ROC Length #2", group = "KST Settings")
roclen3 = input.int(20, minval=1, title = "ROC Length #3", group = "KST Settings")
roclen4 = input.int(30, minval=1, title = "ROC Length #4", group = "KST Settings")
smalen1 = input.int(10, minval=1, title = "SMA Length #1", group = "KST Settings")
smalen2 = input.int(10, minval=1, title = "SMA Length #2", group = "KST Settings")
smalen3 = input.int(10, minval=1, title = "SMA Length #3", group = "KST Settings")
smalen4 = input.int(15, minval=1, title = "SMA Length #4", group = "KST Settings")
siglen = input.int(9, minval=1, title = "Signal Line Length", group = "KST Settings")
source = input(close, title = "Source", group = "KST Settings")
exotic = input.bool(false, title = "Exotic Calculations", group = "KST Settings")
length1 = input.int(9, title="EMA-1 period", minval=1, group = "Ribbon Settings")
length2 = input.int(18, title="EMA-2 period", minval=1, group = "Ribbon Settings")
length3 = input.int(27, title="EMA-3 period", minval=1, group = "Ribbon Settings")
length4 = input.int(36, title="EMA-4 period", minval=1, group = "Ribbon Settings")
length5 = input.int(45, title="EMA-5 period", minval=1, group = "Ribbon Settings")
length6 = input.int(54, title="EMA-6 period", minval=1, group = "Ribbon Settings")
length7 = input.int(63, title="EMA-7 period", minval=1, group = "Ribbon Settings")
length8 = input.int(72, title="EMA-8 period", minval=1, group = "Ribbon Settings")

logarithmic(src)=> math.sign(src) * math.log(math.abs(src) + 1)

price = source

roc(p, l)=> 100 * (p - p[l]) / p[l]
rocl(p, l)=> 100 * (logarithmic(p) - logarithmic(p[l]))

smaroc(roclen, smalen) => ta.sma(roc(price, roclen), smalen)
smarocl(roclen, smalen) => ta.sma(rocl(price, roclen), smalen)

kst = smaroc(roclen1, smalen1) + 2 * smaroc(roclen2, smalen2) + 3 * smaroc(roclen3, smalen3) + 4 * smaroc(roclen4, smalen4)
if (exotic)
    kst := smarocl(roclen1, smalen1) + 2 * smarocl(roclen2, smalen2) + 3 * smarocl(roclen3, smalen3) + 4 * smarocl(roclen4, smalen4)
sig = ta.sma(kst, siglen)

hline(0, title="Zero", color = #787B86DE, display = display.none)
plot(ta.ema(kst, length8), title="EMA-8", color=#aa270740, linewidth=2)
plot(ta.ema(kst, length7), title="EMA-7", color=#f5515140, linewidth=2)
plot(ta.ema(kst, length6), title="EMA-6", color=#f57d5140, linewidth=2)
plot(ta.ema(kst, length5), title="EMA-5", color=#f56d5840, linewidth=2)
plot(ta.ema(kst, length4), title="EMA-4", color=#f57b4e40, linewidth=2)
plot(ta.ema(kst, length3), title="EMA-3", color=#f5b05640, linewidth=2)
plot(ta.ema(kst, length2), title="EMA-2", color=#f5b77140, linewidth=2)
plot(ta.ema(kst, length1), title="EMA-1", color=#f5eb5d40, linewidth=2)
plot(sig, color=#f44336DE, title="Signal", linewidth = 3, display = display.none)
plot(kst, color=#5b9cf6DE, title="KST", linewidth = 3)