本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoTrader_Yiwamoto
//@version=6
indicator("Spread RSI Indicator", overlay=false)
// Input Settings
symbol_2 = input.symbol("AMEX:SPY", "Comparison Symbol")
rsi_length = input.int(2, title="RSI Length", minval=2, maxval=100)
rsi_upper = input.int(90, title="RSI Upper Threshold", minval=50, maxval=100)
rsi_lower = input.int(10, title="RSI Lower Threshold", minval=0, maxval=50)
// Retrieve Symbol Prices
symbol_1_price = close
symbol_2_price = request.security(symbol_2, timeframe.period, close, lookahead=barmerge.lookahead_off)
// Calculate Price Ratio (Chart Symbol / Comparison Symbol)
spread = symbol_2_price != 0 ? symbol_1_price / symbol_2_price : na
// Calculate RSI of the Price Ratio
rsi_spread = ta.rsi(spread, rsi_length)
// Plot RSI and Threshold Levels
plot(rsi_spread, color=color.rgb(71, 36, 201), title="Spread RSI", offset=0, linewidth=3)
hline(rsi_lower, "RSI Lower Threshold", color=color.green, linewidth=2)
hline(rsi_upper, "RSI Upper Threshold", color=color.red, linewidth=2)