add buy and sells criteria:
Buy - if price close above the slowma and above the -0.77 fib level. they must have same direction of trend.

Sell - if price close below the slowma and below the 0.77 fib level., they must have same direction if trend.

take profit is at 1:3
stoploss is at 1:05 fib level
dont take trade if the theyre not on thesame direction
 //@version=5
strategy("Demo GPT - Magic MA with Daily Fibs Levels", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1.5, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)

// Custom weighted moving average function
wma(src, len) =>
    float sum = 0.0
    float norm = 0.0
    for i = 0 to len - 1
        weight = len - i
        sum := sum + src[i] * weight
        norm := norm + weight
    sum / norm

// SuperSmoother filter
superSmoother(src, len) =>
    a1 = math.exp(-1.414 * math.pi / len)
    b1 = 2 * a1 * math.cos(1.414 * math.pi / len)
    c2 = b1
    c3 = -a1 * a1
    c1 = 1 - c2 - c3
    var float data = na
    data := c1 * (src + nz(src[1])) / 2 + c2 * nz(data[1]) + c3 * nz(data[2])

// Function to select Moving Average type
ma(type, src, len) =>
    switch type
        "SMA" => ta.sma(src, len)
        "EMA" => ta.ema(src, len)
        "WMA" => wma(src, len)
        "VWMA" => ta.vwma(src, len)
        "SMMA" => ta.rma(src, len)

        "HullMA" => wma(2 * wma(src, len / 2) - wma(src, len), math.round(math.sqrt(len)))
        "ZEMA" => ta.ema(ta.sma(src, len) + (ta.sma(src, len) - ta.ema(src, len)), len)
        "TMA" => ta.sma(ta.sma(src, len), len)
        "SSMA" => superSmoother(src, len)
        => src  // Default to source if type is unknown

// Inputs
type3 = input.string(defval="HullMA", title="Slow MA Type", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
len3 = input.int(defval=37, title="Slow Length", minval=1)
RSIsrc = close
RSILen = input.int(6, title="RSI Length")
SF = input.int(3, title="RSI Smoothing Factor")
QQE = input.float(2.618, title="Fast QQE Factor")
threshhold = input.int(10, title="RSI Threshold")
filter = input.bool(false, title="Use Moving Average Filter")

// QQE Variables
Wilders_Period = RSILen * 2 - 1
Rsi = ta.rsi(RSIsrc, RSILen)
RSIndex = ta.ema(Rsi, SF)  // Ensure length is passed as SF
AtrRsi = math.abs(RSIndex[1] - RSIndex)
MaAtrRsi = ta.ema(AtrRsi, Wilders_Period)  // Ensure length is passed as Wilders_Period
DeltaFastAtrRsi = MaAtrRsi * QQE

newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi
float longband = 0.0
float shortband = 0.0
var int trend = 0
longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? math.max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? math.min(shortband[1], newshortband) : newshortband
isCrossUp = ta.cross(RSIndex, shortband[1])
isCrossDown = ta.cross(longband[1], RSIndex)
trend := isCrossUp ? 1 : isCrossDown ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband

// Series variables
ma_slow = ma(type3, RSIsrc, len3)

// Daily Fibs Levels Section
firstLength = input.int(50, title='ADR Calculation Period (Days)')
fibScale = input.float(1, step=0.1, title='Fibonacci Scale')

dayOpen = request.security(syminfo.tickerid, "D", open)
dayHigh = request.security(syminfo.tickerid, "D", high)
dayLow = request.security(syminfo.tickerid, "D", low)

dayRange = dayHigh - dayLow
avgRange = request.security(syminfo.tickerid, "D", ta.sma(dayRange, firstLength))

fibLevels = array.new_float(6)
array.set(fibLevels, 0, avgRange * 0.25 * fibScale)
array.set(fibLevels, 1, avgRange * 0.77 * fibScale)  // Changed from 0.382 to 0.77
array.set(fibLevels, 2, avgRange * 1.0 * fibScale)  // Changed from 0.5 to 1.0
array.set(fibLevels, 3, avgRange * 0.618 * fibScale)
array.set(fibLevels, 4, avgRange * 0.786 * fibScale)
array.set(fibLevels, 5, avgRange * 1.0 * fibScale)

// Plot Slow MA
plot(ma_slow, title="MA Slow", color=color.blue, linewidth=2)

// Plot Fib Levels
plot(dayOpen + array.get(fibLevels, 0), color=color.red, linewidth=1, title="Fib Level 0.25")
plot(dayOpen - array.get(fibLevels, 0), color=color.green, linewidth=1, title="Fib Level -0.25")
plot(dayOpen + array.get(fibLevels, 1), color=color.red, linewidth=1, title="Fib Level 0.77")
plot(dayOpen - array.get(fibLevels, 1), color=color.green, linewidth=1, title="Fib Level -0.77")
plot(dayOpen + array.get(fibLevels, 2), color=color.red, linewidth=1, title="Fib Level 1.0")
plot(dayOpen - array.get(fibLevels, 2), color=color.green, linewidth=1, title="Fib Level -1.0")

// Strategy logic for buy signal
longCondition = close > ma_slow and close > (dayOpen - array.get(fibLevels, 1)) and trend == 1

// Date Range Input
startDate = input.time(timestamp("2020-01-01 00:00 +0000"), title="Start Date")
endDate = input.time(timestamp("2050-12-31 23:59 +0000"), title="End Date")

isInDateRange() =>
    (time >= startDate) and (time <= endDate)

// Execution of trades within date range
if (isInDateRange())
    if (longCondition)
        strategy.entry("Long", strategy.long)
        // Here, consider defining stop loss and take profit based on Fib levels if needed
        stopLossLevel = dayOpen + array.get(fibLevels, 5)
        takeProfitLevel = close + 3 * math.abs(stopLossLevel - close)  // Example TP calculation
        strategy.exit("Take Profit", "Long", stop=stopLossLevel, limit=takeProfitLevel)