Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="RSI Moving Average Crossovers", shorttitle="RSIMAC", overlay=true,timeframe ="",timeframe_gaps =true )
- ma(source, length, type) =>
- type == "SMA" ? ta.sma(source, length) :
- type == "EMA" ? ta.ema(source, length) :
- type == "SMMA (RMA)" ? ta.rma(source, length) :
- type == "WMA" ? ta.wma(source, length) :
- type == "VWMA" ? ta.vwma(source, length) :
- na
- // Options
- fastMA_len = input.int(20, "Fast Moving average Length", group="Moving averages")
- slowMA_len = input.int(50, "Slow Moving average Length", group="Moving averages")
- ma_type = input.string("EMA", title="MA Type", inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving averages")
- ma_source = input.source(close, "MA Source", group="Moving averages")
- rsi_src = input.source(close, "RSI source", group="RSI")
- rsi_len = input.int(14, "RSI Length", group="RSI")
- rsi_ma_len = input.int(20, "Moving Average Length", group="RSI")
- rsi_ma_type = input.string("SMMA (RMA)", title="RSI MA Type", inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI")
- ob_level = input.int(60, "Overbought level", group="RSI")
- os_level = input.int(40, "Oversold level", group="RSI")
- show_rsi_crossovers = input.bool(false, "Plot RSI/MA crossovers", group="Options")
- show_ma_crossovers = input.bool(false, "Plot Trend MA crossovers", group="Options")
- show_screener = input.bool(false, "Show screener", group="Options")
- // RSI
- rsi = ta.rsi(rsi_src, rsi_len)
- rsi_ma = ma(rsi, rsi_ma_len, rsi_ma_type)
- // Moving Averages
- s = ma(ma_source, fastMA_len, ma_type)
- s2 = ma(ma_source, slowMA_len, ma_type)
- // Colors
- uncertain_color=#bababa50
- bull_color=#48C9B0
- bear_color=#EC7063
- bg_bear_trend = #f50a0ae8
- bg_bear_correct = color.rgb(240, 81, 81 )
- bg_bull_trend = #00bc13c3
- bg_bull_correct = #2ca834
- up_shape_col=#069ecc
- down_shape_col=#aa0000
- // Conditions
- bull = s > s2 and close > s2
- bear = s < s2 and close < s2
- col = (bull or bear) ? (rsi > rsi_ma ? bull_color : bear_color) : uncertain_color
- // Plots
- rsilinecol = (bull or bear) ? (rsi > rsi_ma ? #0676cc : color.red): color.black
- malinecol = (bull or bear) ? (rsi < rsi_ma ? #0676cc : color.red): uncertain_color
- rsi_line = plot(rsi, color=rsilinecol, title="RSI")
- ma_line = plot(rsi_ma, color=malinecol, title="RSI MA")
- // Table Data
- trend = bull ? "Bullish" : bear ? "Bearish": "Uncertain"
- rsi_cell_col = rsi > rsi_ma ? bull_color : bear_color
- rsi_ma_cell_color = rsi < rsi_ma ? bull_color : bear_color
- trend_cell_col = bull ? bull_color : bear ? bear_color : uncertain_color
- status = trend != "Uncertain" ? (bull and rsi < rsi_ma and rsi[1] < rsi_ma[1]) or (bear and rsi > rsi_ma and rsi[1] > rsi_ma[1]) ? "Correction" : "Impulse" : trend
- status_col = trend == "Uncertain" ? uncertain_color : (bull and rsi < rsi_ma) or (bear and rsi > rsi_ma) ? bear_color : bull_color
- // Background Color
- bgcol = (trend == "Bullish" ? (status == "Impulse" ? bg_bull_trend : bg_bull_correct) : trend == "Bearish" ? (status == "Impulse" ? bg_bear_trend : bg_bear_correct) : na)
- // Overbought & Oversold levels
- h = hline(ob_level, title="Overbought level", color=color.red)
- l = hline(os_level, title="Oversold level", color=#0676cc)
- m = hline(50, title="middle level", color=color.gray)
- // Fill normal zone with trend color
- fill(h, l, color=bgcol, title="Trend background color")
Advertisement
Add Comment
Please, Sign In to add comment