Zanyar kaGoldOANDA:XAUUSDzanyarafm9//@version=5 strategy("Radical Saghf-Kaf Strategy with SL/TP", overlay=true, margin_long=100, margin_short=100, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // ===== Input ها ===== length = input.int(20, "Lookback (برای سقف/کف)") use_close = input.bool(true, "استفاده از Close به جای قیمت لحظهای") risk_percent = input.float(1.0, "درصد ریسک برای هر معامله (%)") take_profit_ratio = input.float(2.0, "نسبت حد سود به حد ضرر") // ===== قیمت اصلی ===== price = use_close ? close : hl2 // ===== سقف و کف ===== highest_prev = ta.highest(high, length) lowest_prev = ta.lowest(low, length) // ===== فاصلهها ===== dist_high = highest_prev - price dist_low = price - lowest_prev // ===== فرمول خرید و فروش ===== buy_formula = math.sqrt(price + math.pow(dist_high/2, 2)) sell_formula = math.sqrt(price - math.pow(dist_low/2, 2)) // ===== شرطها ===== long_cond = buy_formula > price short_cond = sell_formula < price // ===== حد ضرر و حد سود ===== stop_loss_long = price - dist_low take_profit_long = price + (dist_low * take_profit_ratio) stop_loss_short = price + dist_high take_profit_short = price - (dist_high * take_profit_ratio) // ===== ورود به معامله ===== if (long_cond) strategy.entry("Long", strategy.long, comment="Buy") strategy.exit("Exit Long", from_entry="Long", stop=stop_loss_long, limit=take_profit_long) plotshape(long_cond, title="Buy", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small) if (short_cond) strategy.entry("Short", strategy.short, comment="Sell") strategy.exit("Exit Short", from_entry="Short", stop=stop_loss_short, limit=take_profit_short) plotshape(short_cond, title="Sell", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small) // ===== نمایش خطوط ===== plot(buy_formula, "Buy Formula", color=color.new(color.green, 40)) plot(sell_formula, "Sell Formula", color=color.new(color.red, 40)) plot(price, "Price", color=color.white)