OPEN-SOURCE SCRIPT

Donchian Channels + Fibs

42
//version=6
indicator(title="Donchian Channels + Fibs", shorttitle="DC Fibs", overlay=true, timeframe="", timeframe_gaps=true)

// --- 1. 输入设置 ---
length = input.int(20, minval = 1, title="Length")
offset = input.int(0, "Offset")
show_fibs = input.bool(true, "Show Fib Levels")

// --- 2. 核心计算 ---
lower = ta.lowest(length) // 0.0 (下轨)
upper = ta.highest(length) // 1.0 (上轨)
basis = math.avg(upper, lower) // 0.5 (中轨)
range_val = upper - lower // 高度

// --- 3. 斐波那契计算 ---
f_786 = lower + range_val * 0.786
f_618 = lower + range_val * 0.618
f_382 = lower + range_val * 0.382
f_236 = lower + range_val * 0.236

// --- 4. 绘图 (已修复样式错误) ---

// 上下轨 (最粗实线)
u = plot(upper, "Upper 1.0", color = #2962FF, linewidth=2, offset = offset)
l = plot(lower, "Lower 0.0", color = #2962FF, linewidth=2, offset = offset)

// 中轴 (中等实线)
plot(basis, "Basis 0.5", color = #FF6D00, linewidth=1, offset = offset)

// 斐波那契内部线
// 修复点:删除了不支持的 style_dashed/dotted,改为默认实线,但保留了透明度

// 0.786 (偏红)
plot(show_fibs ? f_786 : na, "Fib 0.786", color = color.new(#f23645, 30), linewidth=1, offset = offset)

// 0.618 (橙色)
p_618 = plot(show_fibs ? f_618 : na, "Fib 0.618", color = color.new(color.orange, 30), linewidth=1, offset = offset)

// 0.382 (橙色)
p_382 = plot(show_fibs ? f_382 : na, "Fib 0.382", color = color.new(color.orange, 30), linewidth=1, offset = offset)

// 0.236 (偏绿)
plot(show_fibs ? f_236 : na, "Fib 0.236", color = color.new(#089981, 30), linewidth=1, offset = offset)

// --- 5. 背景填充 ---
fill(p_618, p_382, color = color.new(color.orange, 85), title="Golden Zone Fill")
fill(u, l, color = color.rgb(33, 150, 243, 95), title = "Background")

免責聲明

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.