این کد دستوری رو برام تشریح کن//@version=5
indicator("Group with Gann Fan", 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)

// Long Condition BB
long_con1_bb = (low <= lower) and (open > lower) and (close > lower) and (high < basis)
number_candle_long_con1_bb = ta.barssince(long_con1_bb)
long_con2_bb = number_candle_long_con1_bb > 0 and number_candle_long_con1_bb <= 6 and (close > lower) and (number_candle_long_con1_bb != -1) and close > high[number_candle_long_con1_bb]

// Short Condition BB
short_con1_bb = (high >= upper) and (open < upper) and (close < upper) and (low > basis)
number_candle_short_con1_bb = ta.barssince(short_con1_bb)
short_con2_bb = number_candle_short_con1_bb > 0 and number_candle_short_con1_bb <= 6 and (close < upper) and (number_candle_short_con1_bb != -1) and close < low[number_candle_short_con1_bb]

// { === Candle Pattern Identification ===
pinBarBodyRatio = 0.5
pinBarTailRatio = 1.3
bodyLength = math.abs(open - close)
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low
isBullishPinBar = (lowerShadow > bodyLength * pinBarTailRatio) and (bodyLength < (high - low) * pinBarBodyRatio) and (upperShadow < bodyLength)
con_long_pinbar_bb = isBullishPinBar and long_con1_bb
isBearishPinBar = (upperShadow > bodyLength * pinBarTailRatio) and (bodyLength < (high - low) * pinBarBodyRatio) and (lowerShadow < bodyLength)
con_short_pinbar_bb = isBearishPinBar and short_con1_bb

isBullishEngulfing = (close[1] < open[1]) and (close > open) and (close >= open[1]) and (open <= close[1])
plotshape(series=isBullishEngulfing, location=location.belowbar, color=color.green, style=shape.triangleup, text="Bull Engulf", size=size.small)

isBearishEngulfing = (close[1] > open[1]) and (close < open) and (open >= close[1]) and (close <= open[1])
plotshape(series=isBearishEngulfing, location=location.abovebar, color=color.red, style=shape.triangledown, text="Bear Engulf", 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, color) => 
    fan_lines = array.new_line(0)
    angles = array.new_float(7, 0.0)
    array.set(angles, 0, 1.0) // 1:1
    array.set(angles, 1, 0.5) // 1:2
    array.set(angles, 2, 0.333) // 1:3
    array.set(angles, 3, 0.25) // 1:4
    array.set(angles, 4, 0.125) // 1:8
    array.set(angles, 5, 2.0) // 2:1
    array.set(angles, 6, 3.0) // 3:1

    for i = 0 to array.size(angles) - 1
        offset = array.get(angles, i)
        line.new(x1=pivotTime, y1=pivotValue, x2=pivotTime + 50, y2=pivotValue + (offset * (high - low)), color=color, width=1)

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

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