OPEN-SOURCE SCRIPT

Buy/Sell Signals Boinger band

//version=5
indicator("Buy/Sell Signals", overlay=true)

// Define the Bollinger Band parameters
length = input(20, title="Bollinger Band Length")
stdDev = input(2.0, title="Bollinger Band Standard Deviation")

// Calculate the Bollinger Band
basis = ta.sma(close, length)
upper = basis + stdDev * ta.stdev(close, length)
lower = basis - stdDev * ta.stdev(close, length)

// Plot the Bollinger Band
plot(basis, color=color.new(color.blue, 0), linewidth=2)
plot(upper, color=color.red, linewidth=2)
plot(lower, color=color.green, linewidth=2)

// Define the buy signal conditions
lowerBandTouch = close <= lower
threeGreenCandles = close > open and close[1] > open[1] and close[2] > open[2]

// Define the sell signal conditions
upperBandTouch = close >= upper
threeRedCandles = close < open and close[1] < open[1] and close[2] < open[2]

// Generate the buy and sell signals
buySignal = lowerBandTouch and threeGreenCandles
sellSignal = upperBandTouch and threeRedCandles

// Plot the buy and sell signals
plotshape(buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(sellSignal, location=location.belowbar, color=color.red, style=shape.labeldown, text="Sell")

// Alert conditions
alertcondition(buySignal, title="Buy Signal", message="Buy signal generated!")
alertcondition(sellSignal, title="Sell Signal", message="Sell signal generated!")

Wyłączenie odpowiedzialności