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 אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יוכלו להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אבל השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

רוצה להשתמש בסקריפ זה בגרף?

כתב ויתור