0% found this document useful (0 votes)
1K views2 pages

Relative Strength Levy

This document defines a Relative Strength Levy (RSL) study in Pine Script. It allows the user to input parameters like the color scheme, moving average type and length. It then calculates the RSL as the closing price divided by a moving average of the closing price. The RSL value is plotted as a line or columns in either bullish or bearish colors depending on if it is above or below 1. A centerline at 1 is also plotted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views2 pages

Relative Strength Levy

This document defines a Relative Strength Levy (RSL) study in Pine Script. It allows the user to input parameters like the color scheme, moving average type and length. It then calculates the RSL as the closing price divided by a moving average of the closing price. The RSL value is plotted as a line or columns in either bullish or bearish colors depending on if it is above or below 1. A centerline at 1 is also plotted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Calculations: Contains mathematical and calculation logic applied to the input data to produce the desired outcomes.
  • Inputs: Defines input parameters and variables required for the script using a financial study.
  • Outputs: Specifies how the calculated data is visually represented in the form of plots.

//@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)

You might also like