Log Distance From MA + 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="Log Distance From MA", shorttitle="MA Log-Dist", timeframe="", timeframe_gaps=true)
source = input(close, title = "Source", group = "Distance Settings")
maLength = input(title="MA Length", defval=50, group = "Distance Settings")
exotic = input.bool(false, title = "Exotic Calculations", group = "Distance Settings")
length1 = input.int(7, title="EMA-1 period", minval=1, group = "Ribbon Settings")
length2 = input.int(14, title="EMA-2 period", minval=1, group = "Ribbon Settings")
length3 = input.int(21, title="EMA-3 period", minval=1, group = "Ribbon Settings")
length4 = input.int(28, title="EMA-4 period", minval=1, group = "Ribbon Settings")
length5 = input.int(35, title="EMA-5 period", minval=1, group = "Ribbon Settings")
length6 = input.int(42, title="EMA-6 period", minval=1, group = "Ribbon Settings")
length7 = input.int(49, title="EMA-7 period", minval=1, group = "Ribbon Settings")
length8 = input.int(56, title="EMA-8 period", minval=1, group = "Ribbon Settings")
price = source
logarithmic(src)=> math.sign(src) * math.log(math.abs(src) + 1)

ma = ta.sma(price, maLength)

dif = price / ma * 100 - 100
if (exotic)
    dif := 100 * (logarithmic(price) -logarithmic(ma))
hline(0, "Zero Line", color=color.new(#787B86, 50), display=display.none)
plot(ta.ema(dif, length8), title="EMA-8", color=#4a148c80, linewidth=2)
plot(ta.ema(dif, length7), title="EMA-7", color=#6a1b9a80, linewidth=2)
plot(ta.ema(dif, length6), title="EMA-6", color=#7b1fa280, linewidth=2)
plot(ta.ema(dif, length5), title="EMA-5", color=#8e24aa80, linewidth=2)
plot(ta.ema(dif, length4), title="EMA-4", color=#9c27b080, linewidth=2)
plot(ta.ema(dif, length3), title="EMA-3", color=#ab47bc80, linewidth=2)
plot(ta.ema(dif, length2), title="EMA-2", color=#ba68c880, linewidth=2)
plot(ta.ema(dif, length1), title="EMA-1", color=#ce93d880, linewidth=2)
plot(dif, title="Difference", color=#00bcd4, linewidth=2)