OPEN-SOURCE SCRIPT

Bollinger Band Cross Strategy

//version=5
indicator("Bollinger Band Cross Strategy", overlay=true)

// Input settings for Bollinger Bands
length = input.int(20, title="Bollinger Band Length")
src = input.source(close, title="Source")
mult = input.float(2.0, title="Standard Deviation")

// Bollinger Bands calculations
basis = ta.sma(src, length)
upper = basis + mult * ta.stdev(src, length)
lower = basis - mult * ta.stdev(src, length)
// Plot the Bollinger Bands
plot(basis, color=color.blue, title="Middle Band")
plot(upper, color=color.green, title="Upper Band")
plot(lower, color=color.red, title="Lower Band")

// Buy and Sell conditions
buySignal = ta.crossover(close[1], upper[1]) and ta.crossover(close, upper)
sellSignal = ta.crossunder(close[1], lower[1]) and ta.crossunder(close, lower)

// Exit conditions
exitBuy = ta.crossunder(close, basis)
exitSell = ta.crossover(close, basis)

// Plot Buy and Sell signals
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")

// Plot Exit signals
plotshape(series=exitBuy, location=location.abovebar, color=color.blue, style=shape.circle, title="Exit Buy", text="EXIT")
plotshape(series=exitSell, location=location.belowbar, color=color.orange, style=shape.circle, title="Exit Sell", text="EXIT")

// Alerts
alertcondition(buySignal, title="Buy Alert", message="Two consecutive candles closed above Upper Bollinger Band - BUY")
alertcondition(sellSignal, title="Sell Alert", message="Two consecutive candles closed below Lower Bollinger Band - SELL")
alertcondition(exitBuy, title="Exit Buy Alert", message="Candle closed below Middle Bollinger Band - EXIT BUY")
alertcondition(exitSell, title="Exit Sell Alert", message="Candle closed above Middle Bollinger Band - EXIT SELL")
Bands and Channels

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明