EMA 9/20 + RSI

Bobo3003 · study · 165 行 · 点赞 372 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
//author Bobo3003
 
indicator(title="EMA 9/20 + RSI", shorttitle="EMA 9/20 + RSI", overlay=true, explicit_plot_zorder=true)
// 9/20 EMA crossover with additional RSI/RSI-SMA crossover
// Goal is to detect a Bullish/bearish Trend in EMAs and RSIs 
 
//Defining Timeframe inputs
timeframe1 = input(true , "Timeframe Number 1", group = "Timeframes")
timeframe1_val = input.int(3, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
timeframe2 = input(true , "Timeframe Number 2", group = "Timeframes")
timeframe2_val = input.int(5, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
timeframe3 = input(true , "Timeframe Number 3", group = "Timeframes")
timeframe3_val = input.int(15, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
timeframe4 = input(true , "Timeframe Number 4", group = "Timeframes")
timeframe4_val = input.int(30, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
timeframe5 = input(true , "Timeframe Number 5", group = "Timeframes")
timeframe5_val = input.int(45, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
timeframe6 = input(true , "Timeframe Number 6", group = "Timeframes")
timeframe6_val = input.int(60, "Timeframe ", group = "Timeframes", options=[1, 3, 5, 15, 30, 45, 60, 120, 180, 240])
 
 
//Activation Options for Alarms, RSI and combination of RSI and EMA
 
activate_alerts = input(false,"Activate Alarms", group="EMA 9/20 Signals")
activate_rsi = input(false, "Activate RSI", group="RSI")
combined_activated = input(false, "Activate combination of RSI and EMA 9/20", group="Combination of RSI and EMA9/20")
 
//Crossing signals for EMA and RSI
 
tf1_tf2_signal = input(true, "Show Crossing for Timeframe 1&2", group="EMA 9/20 Signals")
tf1_tf2_tf3_signal = input(true, "Show Crossing for Timeframe 1&2&3", group="EMA 9/20 Signals")
tf1_tf2_tf3_tf4_signal = input(false, "Show Crossing for Timeframe 1&2&3&4", group="EMA 9/20 Signals")
tf1_tf2_tf3_tf4_tf5_signal = input(false, "Show Crossing for Timeframe 1&2&3&4&5", group="EMA 9/20 Signals")
tf1_tf2_tf3_tf4_tf5_tf6_signal = input(false, "Show Crossing for Timeframe 1&2&3&4&5&6", group="EMA 9/20 Signals")
 
rsi_tf1_tf2 = input(true, "Show Crossing for Timeframe 1&2", group="RSI")
rsi_tf1_tf2_tf3 = input(true, "Show Crossing for Timeframe 1&2&3", group="RSI")
rsi_tf1_tf2_tf3_tf4 = input(false, "Show Crossing for Timeframe 1&2&3&4", group="RSI")
rsi_tf1_tf2_tf3_tf4_tf5 = input(false, "Show Crossing for Timeframe 1&2&3&4&5", group="RSI")
rsi_tf1_tf2_tf3_tf4_tf5_tf6 = input(false, "Show Crossing for Timeframe 1&2&3&4&5&6", group="RSI")
 
//function to calculate EMAs and give alerts
 
computeEMAs(timeframe1, timeframe1_val, activate_alerts) =>
    ema_9_timeframe1 = request.security(syminfo.tickerid, str.tostring(timeframe1_val, '#'), ta.ema(close,9))
    ema_20_timeframe1 = request.security(syminfo.tickerid, str.tostring(timeframe1_val, '#'), ta.ema(close,20))
    crossover_on_tf1 = ta.crossover(ema_9_timeframe1, ema_20_timeframe1)
    crossunder_on_tf1 = ta.crossunder(ema_9_timeframe1, ema_20_timeframe1)
    if (timeframe1 and crossover_on_tf1 and activate_alerts)
        alert("Bullish Crossover on " + str.tostring(timeframe1_val) + "min")
    if (timeframe1 and crossunder_on_tf1 and activate_alerts)
        alert("Bearish Crossunder on " + str.tostring(timeframe1_val) + "min")
    
    [crossover_on_tf1, crossunder_on_tf1]
 
//Print plot for EMA9 and 20 and color it by crossover
 
ema_9 = ta.ema(close, 9)
ema_20 = ta.ema(close, 20)
plot(ema_9, color = ema_9>ema_20 ? color.green : color.red)
 
//execute EMA function for all timeframes
 
[crossover_on_tf1, crossunder_on_tf1] = computeEMAs(timeframe1, timeframe1_val, activate_alerts)
[crossover_on_tf2, crossunder_on_tf2] = computeEMAs(timeframe2, timeframe2_val, activate_alerts)
[crossover_on_tf3, crossunder_on_tf3] = computeEMAs(timeframe3, timeframe3_val, activate_alerts)
[crossover_on_tf4, crossunder_on_tf4] = computeEMAs(timeframe4, timeframe4_val, activate_alerts)
[crossover_on_tf5, crossunder_on_tf5] = computeEMAs(timeframe5, timeframe5_val, activate_alerts)
[crossover_on_tf6, crossunder_on_tf6] = computeEMAs(timeframe6, timeframe6_val, activate_alerts)
 
//function to calculate RSI, code by TradingView
 
computeRSI(rsiLengthInput) =>
    //RSI
    up = ta.rma(math.max(ta.change(close), 0), rsiLengthInput)
    down = ta.rma(-math.min(ta.change(close), 0), rsiLengthInput)
    rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
    rsiMA = ta.sma(rsi, rsiLengthInput)
    rsi_crossing_bullish  = ta.crossover(rsi, rsiMA)
    rsi_crossing_bearish  = ta.crossunder(rsi, rsiMA)
    [rsi_crossing_bullish, rsi_crossing_bearish]
    
[crossover_on_tf1_rsi, crossunder_on_tf1_rsi] = computeRSI(timeframe1_val)
[crossover_on_tf2_rsi, crossunder_on_tf2_rsi] = computeRSI(timeframe2_val)
[crossover_on_tf3_rsi, crossunder_on_tf3_rsi] = computeRSI(timeframe3_val)
[crossover_on_tf4_rsi, crossunder_on_tf4_rsi] = computeRSI(timeframe4_val)
[crossover_on_tf5_rsi, crossunder_on_tf5_rsi] = computeRSI(timeframe5_val)
[crossover_on_tf6_rsi, crossunder_on_tf6_rsi] = computeRSI(timeframe6_val)
 
//signals for EMA crossovers on multiple timeframes
    
bullish_signal_12 = crossover_on_tf1 and crossover_on_tf2 and tf1_tf2_signal
bearish_signal_12 = crossunder_on_tf1 and crossunder_on_tf2 and tf1_tf2_signal
bullish_signal_123 = crossover_on_tf1 and crossover_on_tf2 and crossover_on_tf3 and tf1_tf2_tf3_signal
bearish_signal_123 = crossunder_on_tf1 and crossunder_on_tf2 and crossunder_on_tf3 and tf1_tf2_tf3_signal
bullish_signal_1234 = crossover_on_tf1 and crossover_on_tf2 and crossover_on_tf3 and crossover_on_tf4 and tf1_tf2_tf3_tf4_signal
bearish_signal_1234 = crossunder_on_tf1 and crossunder_on_tf2 and crossunder_on_tf3 and crossunder_on_tf4 and tf1_tf2_tf3_tf4_signal
bullish_signal_12345 = crossover_on_tf1 and crossover_on_tf2 and crossover_on_tf3 and crossover_on_tf4 and crossover_on_tf5 and tf1_tf2_tf3_tf4_tf5_signal
bearish_signal_12345 = crossunder_on_tf1 and crossunder_on_tf2 and crossunder_on_tf3 and crossunder_on_tf4 and crossunder_on_tf5 and tf1_tf2_tf3_tf4_tf5_signal
bullish_signal_123456 = crossover_on_tf1 and crossover_on_tf2 and crossover_on_tf3 and crossover_on_tf4 and crossover_on_tf5  and crossover_on_tf6 and tf1_tf2_tf3_tf4_tf5_tf6_signal
bearish_signal_123456 = crossunder_on_tf1 and crossunder_on_tf2 and crossunder_on_tf3 and crossunder_on_tf4 and crossunder_on_tf5 and crossunder_on_tf6_rsi and tf1_tf2_tf3_tf4_tf5_tf6_signal
 
//signals for RSI crossovers on multiple timeframes
 
rsi_bullish_signal_12 = crossover_on_tf1_rsi and crossover_on_tf2_rsi and activate_rsi and rsi_tf1_tf2
rsi_bearish_signal_12 = crossunder_on_tf1_rsi and crossunder_on_tf2_rsi and activate_rsi and rsi_tf1_tf2
rsi_bullish_signal_123 = crossover_on_tf1_rsi and crossover_on_tf2_rsi and crossover_on_tf3_rsi and activate_rsi and rsi_tf1_tf2_tf3
rsi_bearish_signal_123 = crossunder_on_tf1_rsi and crossunder_on_tf2_rsi and crossunder_on_tf3_rsi and activate_rsi and rsi_tf1_tf2_tf3
rsi_bullish_signal_1234 = crossover_on_tf1_rsi and crossover_on_tf2_rsi and crossover_on_tf3_rsi and crossover_on_tf4_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4
rsi_bearish_signal_1234 = crossunder_on_tf1_rsi and crossunder_on_tf2_rsi and crossunder_on_tf3_rsi and crossunder_on_tf4_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4
rsi_bullish_signal_12345 = crossover_on_tf1_rsi and crossover_on_tf2_rsi and crossover_on_tf3_rsi and crossover_on_tf4_rsi and crossover_on_tf5_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4_tf5
rsi_bearish_signal_12345 = crossunder_on_tf1_rsi and crossunder_on_tf2_rsi and crossunder_on_tf3_rsi and crossunder_on_tf4_rsi and crossunder_on_tf5_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4_tf5
rsi_bullish_signal_123456 = crossover_on_tf1_rsi and crossover_on_tf2_rsi and crossover_on_tf3_rsi and crossover_on_tf4_rsi and crossover_on_tf5_rsi and crossover_on_tf6_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4_tf5_tf6
rsi_bearish_signal_123456 = crossunder_on_tf1_rsi and crossunder_on_tf2_rsi and crossunder_on_tf3_rsi and crossunder_on_tf4_rsi and crossunder_on_tf5_rsi and crossunder_on_tf6_rsi and activate_rsi and rsi_tf1_tf2_tf3_tf4_tf5_tf6
 
//signals for the combination of RSI and EMA crossovers on multiple timeframes
 
combined_bullish_signal_12 = bullish_signal_12 and rsi_bullish_signal_12 and combined_activated
combined_bullish_signal_123 = bullish_signal_123 and rsi_bullish_signal_123 and combined_activated
combined_bullish_signal_1234 = bullish_signal_1234 and rsi_bullish_signal_1234 and combined_activated
combined_bullish_signal_12345 = bullish_signal_12345 and rsi_bullish_signal_12345 and combined_activated
combined_bullish_signal_123456 = bullish_signal_123456 and rsi_bullish_signal_123456 and combined_activated
combined_bearish_signal_12 = bearish_signal_12 and rsi_bearish_signal_12 and combined_activated
combined_bearish_signal_123 = bearish_signal_123 and rsi_bearish_signal_123 and combined_activated
combined_bearish_signal_1234 = bearish_signal_1234 and rsi_bearish_signal_1234 and combined_activated
combined_bearish_signal_12345 = bearish_signal_12345 and rsi_bearish_signal_12345 and combined_activated
combined_bearish_signal_123456 = bearish_signal_123456 and rsi_bearish_signal_123456 and combined_activated
    
//plot EMA cross-over/unders
 
plotchar(series = combined_activated ? 0 : bullish_signal_12, title = "Crossup Timeframe 1&2", char = "▲", location = location.belowbar, color = color.lime, size = size.tiny)
plotchar(series = combined_activated ? 0 : bearish_signal_12, title = "Crossdown Timeframe 1&2", char = "▼", location = location.abovebar,    color = color.red,  size = size.tiny)
plotchar(series = combined_activated ? 0 : bullish_signal_123, title = "Crossup Timeframe 1&2&3",  char = "▲", location = location.belowbar, color = color.lime, size = size.small)
plotchar(series = combined_activated ? 0 : bearish_signal_123, title = "Crossdown Timeframe 1&2&3", char = "▼", location = location.abovebar,    color = color.red,  size = size.small)
plotchar(series = combined_activated ? 0 : bullish_signal_1234, title = "Crossup Timeframe 1&2&3&4",  char = "▲", location = location.belowbar, color = color.lime, size = size.normal)
plotchar(series = combined_activated ? 0 : bearish_signal_1234, title = "Crossdown Timeframe 1&2&3&4", char = "▼", location = location.abovebar,    color = color.red,  size = size.normal)
plotchar(series = combined_activated ? 0 : bullish_signal_12345, title = "Crossup Timeframe 1&2&3&4&5",  char = "▲", location = location.belowbar, color = color.lime, size = size.large)
plotchar(series = combined_activated ? 0 : bearish_signal_12345, title = "Crossdown Timeframe 1&2&3&4&5", char = "▼", location = location.abovebar,    color = color.red,  size = size.large)
 
//plot RSI cross-over/under
 
plotchar(series = combined_activated ? 0 : rsi_bullish_signal_12, title = "RSI Crossup on Timeframe 1&2", char = "·", location = location.belowbar, color = color.blue, size = size.tiny)
plotchar(series = combined_activated ? 0 : rsi_bearish_signal_12, title = "RSI Crossdown on Timeframe 1&2", char = "·", location = location.abovebar, color = color.yellow,  size = size.tiny)
plotchar(series = combined_activated ? 0 : rsi_bullish_signal_123, title = "RSI Crossup on Timeframe 1&2&3", char = "·", location = location.belowbar, color = color.blue, size = size.small)
plotchar(series = combined_activated ? 0 : rsi_bearish_signal_123, title = "RSI Crossdown on Timeframe 1&2&3", char = "·", location = location.abovebar, color = color.yellow,  size = size.small)
plotchar(series = combined_activated ? 0 : rsi_bullish_signal_1234, title = "RSI Crossup on Timeframe 1&2&3&4", char = "·", location = location.belowbar, color = color.blue, size = size.normal)
plotchar(series = combined_activated ? 0 : rsi_bearish_signal_1234, title = "RSI Crossdown on Timeframe 1&2&3&4", char = "·", location = location.abovebar, color = color.yellow,  size = size.normal)
plotchar(series = combined_activated ? 0 : rsi_bullish_signal_12345, title = "RSI Crossup on Timeframe 1&2&3&4&5", char = "·", location = location.belowbar, color = color.blue, size = size.normal)
plotchar(series = combined_activated ? 0 : rsi_bearish_signal_12345, title = "RSI Crossdown on Timeframe 1&2&3&4&5", char = "·", location = location.abovebar, color = color.yellow,  size = size.normal)
plotchar(series = combined_activated ? 0 : rsi_bullish_signal_123456, title = "RSI Crossup on Timeframe 1&2&3&4&5&6", char = "·", location = location.belowbar, color = color.blue, size = size.normal)
plotchar(series = combined_activated ? 0 : rsi_bearish_signal_123456, title = "RSI Crossdown on Timeframe 1&2&3&4&5&6", char = "·", location = location.abovebar, color = color.yellow,  size = size.normal)
 
//when combined_activated is activated, signals for the combination of RSI and EMA crossovers on multiple timeframes are plottet
 
plotchar(combined_bullish_signal_12, "Combined Crossup on Timeframe 1&2", "▲", location.belowbar, color.lime, size = size.tiny)
plotchar(combined_bearish_signal_12, "Combined Crossdown on Timeframe 1&2", "▼", location.abovebar, color.red,  size = size.tiny)
plotchar(combined_bullish_signal_123, "Combined Crossup on Timeframe 1&2&3", "▲", location.belowbar, color.lime, size = size.small)
plotchar(combined_bearish_signal_123, "Combined Crossdown on Timeframe 1&2&3", "▼", location.abovebar, color.red,  size = size.small)
plotchar(combined_bullish_signal_1234, "Combined Crossup on Timeframe 1&2&3&4", "▲", location.belowbar, color.lime, size = size.normal)
plotchar(combined_bearish_signal_1234, "Combined Crossdown on Timeframe 1&2&3&4", "▼", location.abovebar, color.red,  size = size.normal)
plotchar(combined_bullish_signal_12345, "Combined Crossup on Timeframe 1&2&3&4&5", "▲", location.belowbar, color.lime, size = size.normal)
plotchar(combined_bearish_signal_12345, "Combined Crossdown on Timeframe 1&2&3&4&5", "▼", location.abovebar, color.red,  size = size.normal)
plotchar(combined_bullish_signal_123456, "Combined Crossup on Timeframe 1&2&3&4&5&6", "▲", location.belowbar, color.lime, size = size.normal)
plotchar(combined_bearish_signal_123456, "Combined Crossdown on Timeframe 1&2&3&4&5&6", "▼", location.abovebar, color.red,  size = size.normal)

← 返回列表