//@version=3
study("Elder AutoEnvelope", overlay = true)
myema = input(26, title="Center EMA", minval = 0)
lookback = input(100, title="Lookback", minval = 0)
multiplier = input(2, title="Multiplier", minval = 0, step = 0.01)
shortema = input(13, title="Short EMA", minval=1)
mode = input(title="Use Close?", type=bool, defval=true)
centerline = ema(close, myema)
myvar = mode == true ? abs(close - centerline) : max(abs(high - centerline), abs(low - centerline))
myvars = myvar * myvar
mymov = sqrt(sma(myvars, lookback))
newmax = max(mymov, max(mymov[1], max(mymov[2], max(mymov[3], max(mymov[4], mymov[5] ) ) ) ) )
upper = centerline + (newmax * multiplier)
lower = centerline - (newmax * multiplier)
plot(centerline, title="Center EMA", color=#FFFF00, linewidth=3)
plot(ema(close,shortema), title="Short EMA", color=#c900ff, linewidth=3)
plot(upper, title="Upper Channel", linewidth=3)
plot(lower, title="Lower Channel", linewidth=3)