//@version=5 strategy("Bollinger Retracement Strategy", overlay=

//version=5
strategy("Bollinger Retracement Strategy", overlay=true)

// Bollinger Band Settings
length = input(20, minval=1, title="Bollinger Length")
mult = input(2.0, minval=0.1, title="Bollinger Multiplier")
src = input(close, title="Source")
basis = sma(src, length)
dev = mult * stdev(src, length)

// Bollinger Bands
upperBB = basis + dev
lowerBB = basis - dev

// Buy Signal: Price crosses below the lower Bollinger Band
buySignal = crossover(close, lowerBB)

// Sell Signal: Price crosses above the upper Bollinger Band
sellSignal = crossunder(close, upperBB)

// Exit Signal: Price touches the middle Bollinger Band
exitSignal = close == basis

// Strategy logic
if (buySignal)
strategy.entry("Buy", strategy.long)

if (sellSignal)
strategy.close("Buy")

if (exitSignal)
strategy.close("Buy")

// Plotting Bollinger Bands for visual reference
plot(basis, color=color.blue, title="Middle Bollinger Band")
plot(upperBB, color=color.red, title="Upper Bollinger Band")
plot(lowerBB, color=color.green, title="Lower Bollinger Band")
Trend Analysis

Wyłączenie odpowiedzialności