//@version=4
study("Relative Strength Levy", "RSL", precision = 5)
// Inputs
CS0 = "Lime/Red", CS1 = "Aqua/Pink", CS2 = "Coral/Violet", CS3 = "Blue/Yellow"
colorScheme= input(CS0, "Color Scheme", options = [CS0, CS1, CS2, CS3])
display = input("Line", "Display", input.string, options = ["Line", "Columns"])
maLen = input(26, "Length", input.integer)
maType = input("SMA", "MA Type", input.string, options = ["ALMA", "EMA",
"DEMA", "TEMA", "WMA", "VWMA", "SMA", "SMMA", "HMA", "LSMA", "Kijun", "McGinley"])
lsmaOffset = input(0, "* Least Squares (LSMA) Only - Offset Value", minval=0)
almaOffset = input(0.85, "* Arnaud Legoux (ALMA) Only - Offset Value", minval=0,
step=0.01)
almaSigma = input(6, "* Arnaud Legoux (ALMA) Only - Sigma Value", minval=0)
ma(type, src, len) =>
float result = 0
if type=="SMA" // Simple
result := sma(src, len)
if type=="EMA" // Exponential
result := ema(src, len)
if type=="DEMA" // Double Exponential
e = ema(src, len)
result := 2 * e - ema(e, len)
if type=="TEMA" // Triple Exponential
e = ema(src, len)
result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
if type=="WMA" // Weighted
result := wma(src, len)
if type=="VWMA" // Volume Weighted
result := vwma(src, len)
if type=="SMMA" // Smoothed
w = wma(src, len)
result := na(w[1]) ? sma(src, len) : (w[1] * (len - 1) + src) / len
if type == "RMA"
result := rma(src, len)
if type=="HMA" // Hull
result := wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))
if type=="LSMA" // Least Squares
result := linreg(src, len, lsmaOffset)
if type=="ALMA" // Arnaud Legoux
result := alma(src, len, almaOffset, almaSigma)
if type=="Kijun" //Kijun-sen
kijun = avg(lowest(len), highest(len))
result :=kijun
if type=="McGinley"
mg = 0.0
mg := na(mg[1]) ? ema(src, len) : mg[1] + (src - mg[1]) / (len *
pow(src/mg[1], 4))
result :=mg
result
rsl = close / ma(maType, close, maLen)
// Colors
bullsColor = colorScheme == CS0 ? #00FF00ff : colorScheme == CS1 ? #00C0FFff :
colorScheme == CS2 ? #FF8080ff : color.blue
bearsColor = colorScheme == CS0 ? #FF0000ff : colorScheme == CS1 ? #FF0080ff :
colorScheme == CS2 ? #AA00FFff : color.yellow
rslColor = rsl > 1 ? bullsColor : bearsColor
// Plots
column = rsl >= 1.0 ? rsl - 1.0 : rsl < 1.0 ? -(1.0 - rsl) : 0.0
_line = display == "Line"
style = _line ? plot.style_line : plot.style_columns
plot(_line ? rsl : column, "RSL", rslColor, 2, style, histbase = 0)
plot(_line ? 1 : 0, "Centerline", color.gray)