OPEN-SOURCE SCRIPT
Donchian Channels + Fibs

//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")
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")
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
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.