[RS]Donchian HL Width - Cycle Information

RicardoSantos · study · 62 行 · 点赞 819 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos
 
//@version=4
study(title='[RS]Donchian HL Width - Cycle Information')
 
f_ph(_length) =>
	float _max = highest(_length)
	float _min = lowest(_length)
	100 * (high - _max) / (_max - _min)
f_pl(_length) =>
	float _max = highest(_length)
	float _min = lowest(_length)
	100 * (low - _max) / (_max - _min)
 
int length = input(28)
bool show_barcolor = input(true)
 
float ph = f_ph(length)
float pl = f_pl(length)
float avg = avg(ph, pl)
float mean = cum(avg) / (bar_index + 1)
 
var int cycle_counter = 0
cycle_counter := nz(cycle_counter) + 1
var int cycle_trend = 1
 
var float cycle_avg = 0.0
var int cycle_count = 0
var color cycle_col = color.silver
 
if cycle_trend < 0 and ph >= 0.0
    label.new(bar_index, 0.0, '', color=color.green, style=label.style_arrowdown)
    cycle_counter := 0
    cycle_trend := +1
    cycle_col := color.lime
    cycle_count := nz(cycle_count) + 1
    cycle_avg := nz(cycle_avg) * (1-(2/cycle_count)) + cycle_counter[1] * (2/cycle_count)
if cycle_trend > 0 and pl <= -100.0
    label.new(bar_index, -100.0, '', color=color.maroon, style=label.style_arrowup)
    cycle_counter := 0
    cycle_trend := -1
    cycle_col := color.red
    cycle_count := nz(cycle_count) + 1
    cycle_avg := nz(cycle_avg) * (1-(2/cycle_count)) + cycle_counter[1] * (2/cycle_count)
 
plot(series=cycle_avg, title='Cycle AVG', color=color.orange)
plot(series=cycle_counter, title='Cycle Counter', color=cycle_col)
plot(series=ph, title='%Wd high')
plot(series=pl, title='%Wd low')
plot(series=avg, title='HL AVG', color=color.black)
plot(series=mean, title='Mean', color=color.navy)
 
color col = na
if show_barcolor
    if avg > -40
        col := color.green
    else if avg < -60
        col := color.maroon
    else
        col := color.silver
barcolor(col)

← 返回列表