本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
study(title="Donchian Channel Trend Intensity [DW]", shorttitle="DCTI [DW]", overlay=false)
//by Donovan Wall
//This is an experimental study designed to analyze trend intensity using two Donchian Channels.
//The DCTI curve is calculated by comparing the differences between Donchian highs and lows over a major an minor period, and expressing them as a positive and negative percentage.
//The curve is then smoothed with an exponential moving average to provide a signal line.
//Custom bar colors included with two coloring methods to choose from.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Periods
perM = input(defval=21, minval=1, title="Major Period")
perm = input(defval=3, minval=1, title="Minor Period")
pers = input(defval=5, minval=1, title="Signal Period")
//Bar Color Method
bcm = input(defval=1, minval=0, maxval=2, title="Bar Color Method (0 = None, 1 = DCTI, 2 = Signal)")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Major Levels
H = highest(high, perM)
L = lowest(low, perM)
//Minor Levels
h = highest(high, perm)
l = lowest(low, perm)
//DTI
pdiv = l - L
ndiv = H - h
dcti = 100*((pdiv - ndiv)/(pdiv + ndiv))
//Signal
sig = ema(dcti, pers)
//Center
cent = 0
//Color
dcolor = ((dcti > sig) and (dcti == 100)) ? #00FF7F : ((dcti > 0) and (dcti > sig) and (dcti < 100)) ? lime : ((dcti > 0) and (dcti <= sig)) ? green : ((dcti < sig) and (dcti == -100)) ? #F08080 : ((dcti < 0) and (dcti < sig) and (dcti > -100)) ? red : ((dcti < 0) and (dcti >= sig)) ? maroon : orange
scolor = sig > 0 ? aqua : sig < 0 ? fuchsia : na
barcolor = bcm==1 ? dcolor : bcm==2 ? scolor : na
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Center
cplot = plot(cent, color=orange, title="Center")
//DCTI
dctiplot = plot(dcti, color=dcolor, style=histogram, linewidth=4, transp=50, title="DCTI")
//Signal
sigplot = plot(sig, color=scolor, linewidth=1, transp=0, title="Signal Line")
//Barcolor
barcolor(barcolor)