plotshape گن فن را دراین کد دستوری برایم فعال کن//@version=5
indicator("Candlestick Patterns with Bollinger Band Breakouts", overlay = true)

// { ==== Bollinger Bands ====
length_BB = input.int(20, minval=1, title="BB Length")
src_BB = input(close, title="Source")
mult_BB = input.float(2.0, minval=0.001, maxval=50, title="StdDev Multiplier")
basis = ta.sma(src_BB, length_BB)
dev = mult_BB * ta.stdev(src_BB, length_BB)
upper = basis + dev
lower = basis - dev
plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.red)
plot(lower, "Lower", color=color.green)

// Standardized Pin Bar Definitions
pinBarBodyMaxRatio = 0.33 // Maximum body size as a percentage of the candle range
pinBarTailMinRatio = 2.0 // Minimum tail size as a multiple of the body

bodyLength = math.abs(open - close)
candleRange = high - low
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low

// Pin Bar detection with Bollinger Bands
isBullishPinBar = (lowerShadow > bodyLength * pinBarTailMinRatio) and (bodyLength < candleRange * pinBarBodyMaxRatio) and (upperShadow < bodyLength)
isBearishPinBar = (upperShadow > bodyLength * pinBarTailMinRatio) and (bodyLength < candleRange * pinBarBodyMaxRatio) and (lowerShadow < bodyLength)

con_long_pinbar_bb = isBullishPinBar and (low < lower) and (close > lower)
con_short_pinbar_bb = isBearishPinBar and (high > upper) and (close < upper)

// Plot pin bar signals at Bollinger Bands
plotshape(series=con_long_pinbar_bb, location=location.belowbar, color=color.green, style=shape.triangleup, text="Bull Pin", size=size.small)
plotshape(series=con_short_pinbar_bb, location=location.abovebar, color=color.red, style=shape.triangledown, text="Bear Pin", size=size.small)

// Engulfing Pattern Identification with Bollinger Bands
isBullishEngulfing = (close[1] < open[1]) and (close > open) and (close >= open[1]) and (open <= close[1]) and (low <= lower)
isBearishEngulfing = (close[1] > open[1]) and (close < open) and (open >= close[1]) and (close <= open[1]) and (high >= upper)

plotshape(series=isBullishEngulfing, location=location.belowbar, color=color.lime, style=shape.triangleup, text="Bull Engulf", size=size.small)
plotshape(series=isBearishEngulfing, location=location.abovebar, color=color.orange, style=shape.triangledown, text="Bear Engulf", size=size.small)

// Bollinger Band Breakout Detection
breakoutAboveUpper = close > upper and close > open and open <= upper
breakoutBelowLower = close < lower and close < open and open >= lower

// Plot breakout signals at Bollinger Bands
plotshape(series=breakoutAboveUpper, location=location.abovebar, color=color.purple, style=shape.triangledown, text="Breakout ↑", size=size.small)
plotshape(series=breakoutBelowLower, location=location.belowbar, color=color.yellow, style=shape.triangleup, text="Breakout ↓", size=size.small)

// { ==== Gann Fan ====
pivotHigh = ta.pivothigh(high, 5, 5)
pivotLow = ta.pivotlow(low, 5, 5)

// Function to draw Gann Fan lines
drawGannFan(pivotTime, pivotValue, isHigh, color) =>
    fanAngles = isHigh ? array.from(1.0, 0.5, 0.333, 0.25, 0.125) : array.from(-1.0, -0.5, -0.333, -0.25, -0.125)
    trendDir = isHigh ? -1 : 1
    extent = 50
    for angle in fanAngles
        offset = trendDir * angle * (high - low)
        line.new(x1=pivotTime, y1=pivotValue, x2=pivotTime + extent, y2=pivotValue + offset, color=color, width=1, extend=extend.left)

if not na(pivotHigh)
    drawGannFan(bar_index[pivotHigh], high[pivotHigh], true, color=color.red)

if not na(pivotLow)
    drawGannFan(bar_index[pivotLow], low[pivotLow], false, color=color.green)
// }