Colored Bollinger BandWidth [AMLQ]

mmdcharts · study · 39 行 · 点赞 8 · TradingView 原页

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

Pine Script

//@version=6
indicator(title="Colored Bollinger BandWidth [AMLQ]",format=format.price, precision=2, timeframe="", timeframe_gaps=true)
 
// Input parameters
length = input.int(60,    minval = 1, title="BBW Length")
src    = input(close,     title = "Source")
mult   = input.float(2.0, minval = 0.001, maxval =50, title ="StdDev")
 
expansionLengthInput   = input.int(125, "Highest Expansion Length",  display = display.data_window)
contractionLengthInput = input.int(125, "Lowest Contraction Length", display = display.data_window)
 
// Input for the moving average length of BBW
maLength = input.int(60, minval = 1, title="BBW SMA Length")
 
// Calculate the 20-period moving average
ma60 = ta.sma(src, 30)
 
// Calculate Bollinger Bands
basis = ta.sma(src, length)
dev   = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
bbw   = ((upper - lower) / basis) * 100
 
// Determine the color of the Bollinger BandWidth plot
bbwColor = close > ma60 ? color.blue : color.red
 
// Plot Bollinger BandWidth with conditional color
plot(bbw, "Bollinger BandWidth", color = bbwColor)
 
// Calculate the 60-period SMA of the BBW
bbwSMA = ta.sma(bbw, maLength)
 
// Plot the 60-period SMA of the BBW
plot(bbwSMA, "BBW 60-period SMA", color = color.gray, linewidth = 1)
 
// Plot Highest Expansion and Lowest Contraction
plot(ta.highest(bbw, expansionLengthInput),  "Highest Expansion",  color = color.new(#F23645, 50))
plot(ta.lowest(bbw, contractionLengthInput), "Lowest Contraction", color = color.new(#089981, 50))

← 返回列表