本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=2
// Combines Donchian Channels and Bollinger Bands. The Donchian Channels by
// default use the close value instead of the highest high and lowest low.
// Provides shading between the upper band and upper channel line that changes
// color depending on if the channel is above or below the upper bollinger band,
// and the source prices has crossed above the upper bollinger band.
// Works the same way for the lower bollinger band and lower channel line.
// The BB SMA is available as well as the mid line for the channels.
study("Bollinger/Donchian Channels", overlay = true)
srcU = input(close, title = "Source (Upper Donchian Channel)")
srcD = input(close, title = "Source (Lower Donchian Channel)")
srcB = input(close, title = "Source (Bollinger Bands)")
bbLen = input(20, title = "BB Length")
bbStd = input(2.0, title = "BB STDEV", type = float, step = 0.1)
dcLen = input(21, title = "Donchian Length")
h = highest(srcU, dcLen)
l = lowest(srcD, dcLen)
mid = (h + l) / 2
std = stdev(srcB, bbLen)
sma = sma(srcB, bbLen)
upperBB = sma + bbStd * std
lowerBB = sma - bbStd * std
hp = plot(h, title = "Highest", color = #999999AA)
lp = plot(l, title = "Lowest", color = #999999AA)
plot(mid, "Mid", color = #FFA500AA)
bbUp = plot(upperBB, title = "Upper BB", color = #800080AA)
bbDn = plot(lowerBB, title = "Lower BB", color = #800080AA)
plot(sma, title = "BB SMA", style = circles, color = #DDFF0077)
fill(hp, bbUp, color = h > upperBB and barssince(crossover(h, upperBB)) >= barssince(srcU > upperBB) ? #00FFFF22 : #EEEEEE22, title = "Upper Fill")
fill(lp, bbDn, color = l < lowerBB and barssince(crossunder(l, lowerBB)) >= barssince(srcD < lowerBB) ? #FF00FF22 : #EEEEEE22, title = "Lower Fill")