Bollinger Bands Filter

TradeChartist · study · 83 行 · 点赞 2,695 · TradingView 原页

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

Pine Script

//@version=4
 
//┌───── •••• ─────┐//
//   TradeChartist  //
//└───── •••• ─────┘//
 
//Bollinger Bands is a classic indicator that uses a simple moving average of 20 periods along with upper and lower bands that are 2 standard deviations away from the basis line. 
//These bands help visualize price volatility and trend based on where the price is in relation to the bands.
 
//This Bollinger Bands filter plots a long signal when price closes above the upper band and plots a short signal when price closes below the lower band. 
//It doesn't take into account any other parameters such as Volume/RSI/fundamentals etc, so user must use discretion based on confirmations from another indicator or based on fundamentals.
 
//This filter's default is 55 SMA and 1 standard deviation, but can be changed based on asset type
 
//It is definitely worth reading the 22 rules of Bollinger Bands written by John Bollinger. 
 
 
study(shorttitle="BB Filter", title="Bollinger Bands Filter", overlay=true, resolution="")
 
src         = input(close, title = "Source")
length      = input(55, minval=1, title = "SMA length")// 20 for classis Bollinger Bands SMA line (basis)
CC          = input(true, "Color Bars")
 
 
mult        = input(1., minval=0.236, maxval=2, title="Standard Deviation")//2 for Classic Bollinger Bands //Maxval = 2 as higher the deviation, higher the risk
basis       = sma(src, length)
dev         = mult * stdev(src,length)
 
upper       = basis + dev
lower       = basis - dev
 
//Conditions for Long and Short - Extra filter condition can be used such as RSI or CCI etc.
 
short       = src<lower// and rsi(close,14)<40
long        = src>upper// and rsi(close,14)>60
 
L1          = barssince(long)
S1          = barssince(short)
 
longSignal  = L1<S1 and not (L1<S1)[1]
shortSignal = S1<L1 and not (S1<L1)[1]
 
//Plots and Fills
 
 
 
////Long/Short shapes with text
// plotshape(S1<L1 and not (S1<L1)[1]?close:na, text = "sᴇʟʟ", textcolor=#ff0100, color=#ff0100, style=shape.triangledown, size=size.small, location=location.abovebar, transp=0, title = "SELL", editable = true)
// plotshape(L1<S1 and not (L1<S1)[1]?close:na, text = "ʙᴜʏ", textcolor = #008000, color=#008000, style=shape.triangleup, size=size.small, location=location.belowbar, transp=0, title = "BUY", editable = true)  
 
 
plotshape(shortSignal?close:na, color=#ff0100, style=shape.triangledown, size=size.small, location=location.abovebar, transp=0, title = "Short Signal", editable = true)
plotshape(longSignal?close:na, color=#008000, style=shape.triangleup, size=size.small, location=location.belowbar, transp=0, title = "Long Signal", editable = true)  
 
 
 
p1          = plot(upper, color=#ff0000, display=display.all, transp=75, title = "Upper Band")
p2          = plot(lower, color=#008000, display=display.all, transp=75, title = "Lower Band")
 
 
p           = plot(basis, color=L1<S1?#008000:S1<L1?#ff0000:na, linewidth=2, editable=false, title="Basis")
 
 
fill(p,p1, color=color.teal, transp=85, title = "Top Fill") //fill for basis-upper
fill(p,p2, color=color.orange, transp=85, title = "Bottom Fill")//fill for basis-lower
 
 
//Barcolor
 
bcol        = src>upper?color.new(#8ceb07,0): 
             src<lower?color.new(#ff0000,0):
             src>basis?color.green:
             src<basis?color.red:na
 
 
barcolor(CC?bcol:na, editable=false, title = "Color Bars")
 
 
 
//Alerts ----  // Use 'Once per bar close'
 
alertcondition(condition=longSignal, title="Long - Transformer", message='Transformer Long @ {{close}}') // Use 'Once per bar close'
alertcondition(condition=longSignal, title="Short - Transformer", message='Transformer Short @ {{close}}')  // Use 'Once per bar close'

← 返回列表