本页源码来自 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/
// © mattishenner
//@version=5
indicator("Relative Strength (Volatility Adjusted)")
string instrument_comparison = input.symbol("SPY", "Comparison Instrument")
lookback_length = input.int(100, "Look-back Length", minval=1)
// Request security data
inst = request.security(instrument_comparison, "", close)
// Normalize data
inst_atr = request.security(instrument_comparison, "", ta.atr(50))
normalized_change = (inst - inst[1]) / inst_atr
// Calculations for each ticker's change
change_1 = (inst - inst[1]) / inst[1] * 100
// Index change
index_change = (close - close[1]) / request.security(syminfo.tickerid, "", ta.atr(50))
// Cumulative change calculations with look-back period
var float cumulative_change = na
var float cumulative_change_index = na
// Use look-back length
if na(cumulative_change)
cumulative_change := math.sum(normalized_change, lookback_length)
else
cumulative_change := math.sum(normalized_change, lookback_length)
if na(cumulative_change_index)
cumulative_change_index := math.sum(index_change, lookback_length)
else
cumulative_change_index := math.sum(index_change, lookback_length)
rs = cumulative_change_index - cumulative_change
// ZERO LINE
zero_plot = plot(0, "ZERO LINE", color.new(color.black, 70))
//plot(cumulative_change, color=color.new(color.orange, 80), title="INDEX Color")
//plot(cumulative_change_index, color=color.new(color.black, 80), title="Instrument Color")
//plot(normalized_change, "INDEX Change", color=color.new(color.orange, 50), style=plot.style_columns)
//plot(index_change, "Instrument Change", color=color.new(color.gray, 50), style=plot.style_columns)
rs_plot = plot(rs, "RS", rs > 0 ? color.blue : color.fuchsia, linewidth = 2)
ma = ta.hma(rs, 100)
ma_plot = plot(ma, color = ma > 0 ? color.blue : color.fuchsia, linewidth = 2)
fill(zero_plot, rs_plot, rs > 0 ? #0084ff52 : #ff52c852)
fill(ma_plot, rs_plot, rs > ma ? #0084ff52 : #ff52c852)