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

Skrip sumber terbuka

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai sumber terbuka supaya pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara percuma, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?

Penafian