// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © loxx //@version=5 indicator("TDI w/ Variety RSI, Averages, & Source Types [Loxx]", shorttitle = "TDIVRSIAST [Loxx]", overlay = false, timeframe="", timeframe_gaps = true) import loxx/loxxvarietyrsi/1 import loxx/loxxexpandedsourcetypes/4 import loxx/loxxmas/1 greencolor = #2DD204 redcolor = #D2042D darkGreenColor = #1B7E02 darkRedColor = #93021F SM02 = 'Signal Crosses' SM03 = 'Floating Boundary Crosses' SM04 = 'Horizontal Boundary Crosses' SM05 = 'Floating Middle Crosses' SM06 = 'Horizontal Middle Crosses' smthtype = input.string("Kaufman", "Heikin-Ashi Better Caculation Type", options = ["AMA", "T3", "Kaufman"], group = "Source Settings") srcin = input.string("Close", "Source", group= "Source Settings", options = ["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)", "HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)", "HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"]) RsiPeriod = input.int(14, "RSI Period", group = "Basic Settings") RsiMethod = input.string("RSX", "RSI Type", options = ["RSX", "Regular", "Slow", "Rapid", "Harris", "Cuttler", "Ehlers Smoothed", "T3 RSI"], group = "Basic Settings") RsiPriceLinePeriod = input.int(2, "RSI Price Line Period", group = "Basic Settings") // Signal line moving average method RsiPriceLineMAMode = input.string("Simple Moving Average - SMA", "Signal Line MA Type", options = ["ADXvma - Average Directional Volatility Moving Average", "Ahrens Moving Average" , "Alexander Moving Average - ALXMA", "Double Exponential Moving Average - DEMA", "Double Smoothed Exponential Moving Average - DSEMA" , "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA", "Fractal Adaptive Moving Average - FRAMA" , "Hull Moving Average - HMA", "IE/2 - Early T3 by Tim Tilson", "Integral of Linear Regression Slope - ILRS" , "Instantaneous Trendline", "Laguerre Filter", "Leader Exponential Moving Average", "Linear Regression Value - LSMA (Least Squares Moving Average)" , "Linear Weighted Moving Average - LWMA", "McGinley Dynamic", "McNicholl EMA", "Non-Lag Moving Average", "Parabolic Weighted Moving Average" , "Recursive Moving Trendline", "Simple Moving Average - SMA", "Sine Weighted Moving Average", "Smoothed Moving Average - SMMA" , "Smoother", "Super Smoother", "Three-pole Ehlers Butterworth", "Three-pole Ehlers Smoother" , "Triangular Moving Average - TMA", "Triple Exponential Moving Average - TEMA", "Two-pole Ehlers Butterworth", "Two-pole Ehlers smoother" , "Volume Weighted EMA - VEMA", "Zero-Lag DEMA - Zero Lag Double Exponential Moving Average", "Zero-Lag Moving Average" , "Zero Lag TEMA - Zero Lag Triple Exponential Moving Average"], group = "Basic Settings") RsiSignalLinePeriod = input.int(14, "RSI Signal Line Period", group = "Basic Settings") // Signal line moving average method RsiSignalLineMAMode = input.string("Simple Moving Average - SMA", "RSI Signal Line MA Type", options = ["ADXvma - Average Directional Volatility Moving Average", "Ahrens Moving Average" , "Alexander Moving Average - ALXMA", "Double Exponential Moving Average - DEMA", "Double Smoothed Exponential Moving Average - DSEMA" , "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA", "Fractal Adaptive Moving Average - FRAMA" , "Hull Moving Average - HMA", "IE/2 - Early T3 by Tim Tilson", "Integral of Linear Regression Slope - ILRS" , "Instantaneous Trendline", "Laguerre Filter", "Leader Exponential Moving Average", "Linear Regression Value - LSMA (Least Squares Moving Average)" , "Linear Weighted Moving Average - LWMA", "McGinley Dynamic", "McNicholl EMA", "Non-Lag Moving Average", "Parabolic Weighted Moving Average" , "Recursive Moving Trendline", "Simple Moving Average - SMA", "Sine Weighted Moving Average", "Smoothed Moving Average - SMMA" , "Smoother", "Super Smoother", "Three-pole Ehlers Butterworth", "Three-pole Ehlers Smoother" , "Triangular Moving Average - TMA", "Triple Exponential Moving Average - TEMA", "Two-pole Ehlers Butterworth", "Two-pole Ehlers smoother" , "Volume Weighted EMA - VEMA", "Zero-Lag DEMA - Zero Lag Double Exponential Moving Average", "Zero-Lag Moving Average" , "Zero Lag TEMA - Zero Lag Triple Exponential Moving Average"], group = "Basic Settings") VolatilityBandPeriod = input.int(34, "Volatility Band Period", group = "Volatility Band Settings") VolatilityBandMultiplier = input.float(1.6185, "Volatility Band Multiplier", group = "Volatility Band Settings") sigtype = input.string(SM02, "Signal Type", options = [SM02, SM03, SM04, SM05, SM06], group = "Signal Settings") statup = input.int(68, "Upper Horizontal Boundary", group = "Horizontal Boundary Settings") statmid = input.int(50, "Middle Horizontal Boundary", group = "Horizontal Boundary Settings") statdn = input.int(32, "Down Horizontal Boundary", group = "Horizontal Boundary Settings") colorbars = input.bool(true, "Color Bars?", group = "UI Options") showSigs = input.bool(true, "Show Signals?", group = "UI Options") frama_FC = input.int(defval=1, title="* Fractal Adjusted (FRAMA) Only - FC", group = "Moving Average Inputs") frama_SC = input.int(defval=200, title="* Fractal Adjusted (FRAMA) Only - SC", group = "Moving Average Inputs") instantaneous_alpha = input.float(defval=0.07, minval = 0, title="* Instantaneous Trendline (INSTANT) Only - Alpha", group = "Moving Average Inputs") _laguerre_alpha = input.float(title="* Laguerre Filter (LF) Only - Alpha", minval=0, maxval=1, step=0.1, defval=0.7, group = "Moving Average Inputs") lsma_offset = input.int(defval=0, title="* Least Squares Moving Average (LSMA) Only - Offset", group = "Moving Average Inputs") _pwma_pwr = input.int(2, "* Parabolic Weighted Moving Average (PWMA) Only - Power", minval=0, group = "Moving Average Inputs") kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs") ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs") amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs") amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs") haclose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) haopen = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open) hahigh = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high) halow = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low) hamedian = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hl2) hatypical = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlc3) haweighted = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlcc4) haaverage = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ohlc4) src = switch srcin "Close" => loxxexpandedsourcetypes.rclose() "Open" => loxxexpandedsourcetypes.ropen() "High" => loxxexpandedsourcetypes.rhigh() "Low" => loxxexpandedsourcetypes.rlow() "Median" => loxxexpandedsourcetypes.rmedian() "Typical" => loxxexpandedsourcetypes.rtypical() "Weighted" => loxxexpandedsourcetypes.rweighted() "Average" => loxxexpandedsourcetypes.raverage() "Average Median Body" => loxxexpandedsourcetypes.ravemedbody() "Trend Biased" => loxxexpandedsourcetypes.rtrendb() "Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext() "HA Close" => loxxexpandedsourcetypes.haclose(haclose) "HA Open" => loxxexpandedsourcetypes.haopen(haopen) "HA High" => loxxexpandedsourcetypes.hahigh(hahigh) "HA Low" => loxxexpandedsourcetypes.halow(halow) "HA Median" => loxxexpandedsourcetypes.hamedian(hamedian) "HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical) "HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted) "HA Average" => loxxexpandedsourcetypes.haaverage(haaverage) "HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen) "HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow) "HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow) "HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl) "HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl) "HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl) "HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl) "HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl) "HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl) "HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl) "HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl) "HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl) "HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl) "HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl) => haclose variant(type, src, len) => sig = 0.0 trig = 0.0 special = false if type == "ADXvma - Average Directional Volatility Moving Average" [t, s, b] = loxxmas.adxvma(src, len) sig := s trig := t special := b else if type == "Ahrens Moving Average" [t, s, b] = loxxmas.ahrma(src, len) sig := s trig := t special := b else if type == "Alexander Moving Average - ALXMA" [t, s, b] = loxxmas.alxma(src, len) sig := s trig := t special := b else if type == "Double Exponential Moving Average - DEMA" [t, s, b] = loxxmas.dema(src, len) sig := s trig := t special := b else if type == "Double Smoothed Exponential Moving Average - DSEMA" [t, s, b] = loxxmas.dsema(src, len) sig := s trig := t special := b else if type == "Exponential Moving Average - EMA" [t, s, b] = loxxmas.ema(src, len) sig := s trig := t special := b else if type == "Fast Exponential Moving Average - FEMA" [t, s, b] = loxxmas.fema(src, len) sig := s trig := t special := b else if type == "Fractal Adaptive Moving Average - FRAMA" [t, s, b] = loxxmas.frama(src, len, frama_FC, frama_SC) sig := s trig := t special := b else if type == "Hull Moving Average - HMA" [t, s, b] = loxxmas.hma(src, len) sig := s trig := t special := b else if type == "IE/2 - Early T3 by Tim Tilson" [t, s, b] = loxxmas.ie2(src, len) sig := s trig := t special := b else if type == "Integral of Linear Regression Slope - ILRS" [t, s, b] = loxxmas.ilrs(src, len) sig := s trig := t special := b else if type == "Instantaneous Trendline" [t, s, b] = loxxmas.instant(src, instantaneous_alpha) sig := s trig := t special := b else if type == "Laguerre Filter" [t, s, b] = loxxmas.laguerre(src, _laguerre_alpha) sig := s trig := t special := b else if type == "Leader Exponential Moving Average" [t, s, b] = loxxmas.leader(src, len) sig := s trig := t special := b else if type == "Linear Regression Value - LSMA (Least Squares Moving Average)" [t, s, b] = loxxmas.lsma(src, len, lsma_offset) sig := s trig := t special := b else if type == "Linear Weighted Moving Average - LWMA" [t, s, b] = loxxmas.lwma(src, len) sig := s trig := t special := b else if type == "McGinley Dynamic" [t, s, b] = loxxmas.mcginley(src, len) sig := s trig := t special := b else if type == "McNicholl EMA" [t, s, b] = loxxmas.mcNicholl(src, len) sig := s trig := t special := b else if type == "Non-Lag Moving Average" [t, s, b] = loxxmas.nonlagma(src, len) sig := s trig := t special := b else if type == "Parabolic Weighted Moving Average" [t, s, b] = loxxmas.pwma(src, len, _pwma_pwr) sig := s trig := t special := b else if type == "Recursive Moving Trendline" [t, s, b] = loxxmas.rmta(src, len) sig := s trig := t special := b else if type == "Simple Moving Average - SMA" [t, s, b] = loxxmas.sma(src, len) sig := s trig := t special := b else if type == "Sine Weighted Moving Average" [t, s, b] = loxxmas.swma(src, len) sig := s trig := t special := b else if type == "Smoothed Moving Average - SMMA" [t, s, b] = loxxmas.smma(src, len) sig := s trig := t special := b else if type == "Smoother" [t, s, b] = loxxmas.smoother(src, len) sig := s trig := t special := b else if type == "Super Smoother" [t, s, b] = loxxmas.super(src, len) sig := s trig := t special := b else if type == "Three-pole Ehlers Butterworth" [t, s, b] = loxxmas.threepolebuttfilt(src, len) sig := s trig := t special := b else if type == "Three-pole Ehlers Smoother" [t, s, b] = loxxmas.threepolesss(src, len) sig := s trig := t special := b else if type == "Triangular Moving Average - TMA" [t, s, b] = loxxmas.tma(src, len) sig := s trig := t special := b else if type == "Triple Exponential Moving Average - TEMA" [t, s, b] = loxxmas.tema(src, len) sig := s trig := t special := b else if type == "Two-pole Ehlers Butterworth" [t, s, b] = loxxmas.twopolebutter(src, len) sig := s trig := t special := b else if type == "Two-pole Ehlers smoother" [t, s, b] = loxxmas.twopoless(src, len) sig := s trig := t special := b else if type == "Volume Weighted EMA - VEMA" [t, s, b] = loxxmas.vwema(src, len) sig := s trig := t special := b else if type == "Zero-Lag DEMA - Zero Lag Double Exponential Moving Average" [t, s, b] = loxxmas.zlagdema(src, len) sig := s trig := t special := b else if type == "Zero-Lag Moving Average" [t, s, b] = loxxmas.zlagma(src, len) sig := s trig := t special := b else if type == "Zero Lag TEMA - Zero Lag Triple Exponential Moving Average" [t, s, b] = loxxmas.zlagtema(src, len) sig := s trig := t special := b trig rsimode = switch RsiMethod "RSX" => "rsi_rsx" "Regular" => "rsi_rsi" "Slow" => "rsi_slo" "Rapid" => "rsi_rap" "Harris" => "rsi_har" "Cuttler" => "rsi_cut" "Ehlers Smoothed" => "rsi_ehl" => "rsi_rsi" prices = src rsi = loxxvarietyrsi.rsiVariety(rsimode, prices, RsiPeriod) rsiPL = variant(RsiPriceLineMAMode, rsi, RsiPriceLinePeriod) rsiSL = variant(RsiSignalLineMAMode, rsi, RsiSignalLinePeriod) bandMi = 0. for k = 0 to VolatilityBandPeriod - 1 bandMi += nz(rsi[k]) bandMi /= VolatilityBandPeriod deviation = ta.stdev(rsi, VolatilityBandPeriod) bandUp = bandMi + VolatilityBandMultiplier * deviation bandDn = bandMi - VolatilityBandMultiplier * deviation trend = 0 trend := (rsiPL > rsiSL) ? 1 : (rsiPL < rsiSL) ? -1 : nz(trend[1]) state = 0. if sigtype == SM02 if (rsiPL < rsiSL) state :=-1 if (rsiPL > rsiSL) state := 1 else if sigtype == SM03 if (rsiPL < bandDn) state :=-1 if (rsiPL > bandUp) state := 1 else if sigtype == SM04 if (rsiPL < statdn) state :=-1 if (rsiPL > statup) state := 1 else if sigtype == SM05 if (rsiPL < bandMi) state :=-1 if (rsiPL > bandMi) state := 1 else if sigtype == SM06 if (rsiPL < statmid) state :=-1 if (rsiPL > statmid) state := 1 colorout = state == 1 ? greencolor : state == -1 ? redcolor : color.gray plot(rsiPL, "RSI Price Line", color = colorout, linewidth = 2) plot(rsiSL, "RSI Signal Line", color = color.white, linewidth = 1) uppl = plot(bandUp, "Upper Band", color = darkGreenColor, linewidth = 1) dnpl = plot(bandDn, "Lower Band", color = darkRedColor, linewidth = 1) midpl = plot(bandMi, "Mid Level", color = color.yellow, linewidth = 1) fill(uppl, midpl, color.new(greencolor, 85)) fill(dnpl, midpl, color.new(redcolor, 85)) plot(statup, "Upper Horizontal Boundary", color = bar_index % 2 ? color.gray : na, linewidth = 1) plot(statmid, "Middle Horizontal Boundary", color = bar_index % 2 ? color.gray : na, linewidth = 1) plot(statdn, "Down Horizontal Boundary", color = bar_index % 2 ? color.gray : na, linewidth = 1) barcolor(colorbars ? colorout : na) goLong = sigtype == SM02 ? ta.crossover(rsiPL, rsiSL) : sigtype == SM03 ? ta.crossover(rsiPL, bandUp) : sigtype == SM04 ? ta.crossover(rsiPL, statup) : sigtype == SM05 ? ta.crossover(rsiPL, bandMi) : ta.crossover(rsiPL, statmid) goShort = sigtype == SM02 ? ta.crossunder(rsiPL, rsiSL) : sigtype == SM03 ? ta.crossunder(rsiPL, bandDn) : sigtype == SM04 ? ta.crossunder(rsiPL, statdn) : sigtype == SM05 ? ta.crossunder(rsiPL, bandMi) : ta.crossunder(rsiPL, statmid) plotshape(showSigs and goLong, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.bottom, size = size.auto) plotshape(showSigs and goShort, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.top, size = size.auto) alertcondition(goLong, title="Long", message="TDI w/ Variety RSI, Averages, & Source Types [Loxx: Long\nSymbol: {{ticker}}\nPrice: {{close}}") alertcondition(goShort, title="Short", message="TDI w/ Variety RSI, Averages, & Source Types [Loxx: Short\nSymbol: {{ticker}}\nPrice: {{close}}")