本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG
//@version=5
indicator('Cyclic RSI High Low With Noise Filter', 'cRSI')
// 0. Inputs
// 1. Variables and calculations
// 2. Custom functions
// 3. Construct
// 4. Plot, fill and hline
// 0. Inputs
i_src = input.source(close, 'RSI', inline = '0')
i_i_len = input.int(13, '', inline = '0', minval=1)
i_b_line = input.bool(false, 'Show line')
i_b_plot = input.bool(true, 'Show axis label')
i_b_fill = input.bool(true, 'Show fill')
i_s_noise = input.string('none', 'Remove Noise', options = ['none', '35 < cRSI < 65', '50 < cRSI < 65', '35 < cRSI < 50'])
// 1. Variables and calculations
crsi = 0.0
vibration = 10
torque = 0.618 / (vibration + 1)
phasingLag = (vibration - 1) / 0.618
rsi = ta.rsi(i_src, i_i_len)
crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1])
float ph = ta.highestbars(high, i_i_len) == 0 ? crsi : na
float pl = ta.lowestbars(low, i_i_len) == 0 ? crsi : na
var int dir = 0
dir := ph and na(pl) ? 1 : pl and na(ph) ? -1 : dir
var max_array_size = 10
var arr_zz = array.new_float(0)
older_zz = array.copy(arr_zz)
dirchanged = ta.change(dir)
// 2. Custom functions
// 2.1 Zigzag functions
// Credits to LonesomeTheBlue
add_to_zigzag(_id, float value, int bindex) =>
array.unshift(_id, bindex)
array.unshift(_id, value)
if array.size(_id) > max_array_size
array.pop(_id)
array.pop(_id)
update_zigzag(_id, float value, int bindex, int dir) =>
if array.size(_id) == 0
add_to_zigzag(_id, value, bindex)
else
if dir == 1 and value > array.get(_id, 0) or dir == -1 and value < array.get(_id, 0)
array.set(_id, 0, value)
array.set(_id, 1, bindex)
0.
if ph or pl
if dirchanged
add_to_zigzag(arr_zz, dir == 1 ? ph : pl, bar_index)
else
update_zigzag(arr_zz, dir == 1 ? ph : pl, bar_index, dir)
// 2.2 Remove noise
f_noise() =>
filter_noise = switch i_s_noise
'35 < cRSI < 65' => array.get(arr_zz, 2) <= 65 and array.get(arr_zz, 2) >= 35
'50 < cRSI < 65' => array.get(arr_zz, 2) >= 35
'30 < cRSI < 50' => array.get(arr_zz, 2) <= 65
// 3. Construct
if array.size(arr_zz) >= 6
// Variables
var line line_zz = na
var label label_zz = na
// Bools for or
bool bool_or_1 = array.get(arr_zz, 0) != array.get(older_zz, 0)
bool bool_or_2 = array.get(arr_zz, 1) != array.get(older_zz, 1)
// Bools for and
bool bool_n_1 = array.get(arr_zz, 2) == array.get(older_zz, 2)
bool bool_n_2 = array.get(arr_zz, 3) == array.get(older_zz, 3)
// Bools for more than and less than
bool bool_0_mt_4 = array.get(arr_zz, 0) > array.get(arr_zz, 4)
bool bool_0_lt_4 = array.get(arr_zz, 0) < array.get(arr_zz, 4)
if bool_or_1 or bool_or_2
if bool_n_1 and bool_n_2
line.delete(line_zz)
label.delete(label_zz)
if f_noise()
label.delete(label_zz)
if i_b_line
line_zz := line.new( x1 = math.round(array.get(arr_zz, 1)), y1 = array.get(arr_zz, 0),
x2 = math.round(array.get(arr_zz, 3)), y2 = array.get(arr_zz, 2),
color = color.gray,
width = 2)
str_label = dir == 1 ? bool_0_mt_4 ? 'OB\n▼' : '◍' :
bool_0_lt_4 ? '▲\nOS' : '◍'
col_label = dir == 1 ? bool_0_mt_4 ? color.red : color.teal :
bool_0_lt_4 ? color.teal : color.red
label_zz := label.new(x = math.round(array.get(arr_zz, 1)), y = array.get(arr_zz, 0), text = str_label,
color = color.new(color.blue, 100), textcolor = col_label,
style=dir == 1 ? label.style_label_down : label.style_label_up)
label_zz
// 4. Plot, fill and hline
p_crsi = plot(crsi, 'CRSI', color.new(color.yellow, i_b_plot ? 0 : 100), linewidth = 2)
p_os = plot(30, 'OS', color.new(color.teal, i_b_plot ? 0 : 50))
p_ob = plot(70, 'OB', color.new(color.red, i_b_plot ? 0 : 50))
fill(p_os, p_crsi, color.new(color.teal, i_b_fill ? 65 : 100))
fill(p_ob, p_crsi, color.new(color.red, i_b_fill ? 65 : 100))
hline(50)
hline(0, 'OS', color.new(color.blue, 100))
hline(100, 'OB', color.new(color.blue, 100))