// @version=3 study(title="RERSI - ZLMA", overlay=true) // -------------------------- INPUTS --------------------------------// Level1 = input(defval=50, minval=1, title="Mid Level - Usually 50") Level2 = input(defval=60, minval=1, title="Uptrend Limit") Level3 = input(defval=40, minval=1, title="Downtrend Limit") Level4 = input(defval=70, minval=1, title="Overbought Level") Level5 = input(defval=30, minval=1, title="Oversold Level") RSILen = input(defval=14, minval=1, title="RSI Length") ZLen = input(defval=200, minval=1, title="Zero Lag MA Length") CurrentRes = input(false, title="Use Current Chart Resolution?") CustomRes = input("240", title="Custom Timeframe? Uncheck Box Above (E.g. 1M, 5D, 240 = 4Hours)") src = log(close) res = CurrentRes ? period : CustomRes // -------------------------- RSI Calc --------------------------------// reRSI(RSILen, Length) => ExpPer = 2 * RSILen - 1 K = 2 / (ExpPer + 1) AUC = 0.0 AUC := iff(src > src[1], K * (src - src[1]) + (1 - K) * nz(AUC[1], 1), (1-K) * nz(AUC[1], 1)) ADC = 0.0 ADC := iff(src > src[1], (1-K) * nz(ADC[1], 1), K * (src[1] - src) + (1 - K) * nz(ADC[1], 1)) nVal = (RSILen - 1) * (ADC * Length / (100 - Length) - AUC) nRes = iff(nVal >= 0, src + nVal, src + nVal * (100 - Length) / Length) nl1 = reRSI(RSILen, Level1) nl2 = reRSI(RSILen, Level2) nl3 = reRSI(RSILen, Level3) nl4 = reRSI(RSILen, Level4) nl5 = reRSI(RSILen, Level5) // -------------------------- Zero Lag EMA --------------------------------// zema(src, len) => ema1=ema(src, len) ema2=ema(ema1, len) d=ema1-ema2 zlema=ema1+d // -------------------------- MTF + MA's --------------------------------// zl1 = exp(security(tickerid, res, zema(nl1, ZLen))) zl2 = exp(security(tickerid, res, zema(nl2, ZLen))) zl3 = exp(security(tickerid, res, zema(nl3, ZLen))) zl4 = exp(security(tickerid, res, zema(nl4, ZLen))) zl5 = exp(security(tickerid, res, zema(nl5, ZLen))) // -------------------------- Plotting --------------------------------// plot(zl1, color=black, linewidth=2, title="Mid Line MA", transp=0) plot(zl2, color=blue, linewidth=1, title="Uptrend MA", transp=0) plot(zl3, color=blue, linewidth=1, title="Downtrend MA", transp=0) plot(zl4, color=red, linewidth=1, title="Overbought MA", transp=0) plot(zl5, color=green, linewidth=1, title="Oversold MA", transp=0)