// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © 7FX Traders // // 7FX · London Breakout Gold (Diuji 7FX) // Aturan diadaptasi dari "London Breakout on Gold: 3.7 Years of Backtests" (MQL5 blog), // ditulis ulang dari nol oleh 7FX Traders untuk diuji ulang di TradingView. // // Aturan: // 1. Range = high–low sesi Asia, 03:00–08:00 jam server (default: broker GMT+2/+3). // 2. Setelah range selesai: buy stop di atas high, sell stop di bawah low (+ buffer). Satu kena, satunya batal. // 3. SL = sisi seberang range, maksimal 0,6% harga. // 4. TP = 2,5R. SL digeser ke break-even setelah harga jalan 1,5R. // 5. Skip hari dengan range < 0,30% atau > 1,60% harga. // 6. Maksimal 1 trade per hari. Semua posisi ditutup jam 21:00 server. // // Edukasi, bukan sinyal. Hasil masa lalu tidak menjamin hasil masa depan. // Biaya: atur "Commission" di tab Properties = setengah spread per ounce (contoh spread $0,30 → isi 0,15). //@version=6 strategy("7FX · London Breakout Gold", shorttitle = "7FX LB Gold", overlay = true, initial_capital = 10000, currency = currency.USD, commission_type = strategy.commission.cash_per_contract, commission_value = 0.15, slippage = 2, margin_long = 1, margin_short = 1, max_bars_back = 500) // ───────────── Input ───────────── grpS = "Sesi" tz = input.string("America/New_York", "Zona waktu sesi", group = grpS, tooltip = "Pakai New York supaya otomatis ikut pergantian DST, sama seperti jam server broker GMT+2/+3.") rangeSess = input.session("2000-0100", "Range Asia", group = grpS, tooltip = "20:00–01:00 New York = 03:00–08:00 jam server GMT+2/+3.") tradeSess = input.session("0100-1400", "Window trading", group = grpS, tooltip = "01:00–14:00 New York = 08:00–21:00 jam server. Posisi ditutup saat window berakhir.") grpR = "Risiko" riskPct = input.float(1.0, "Risiko per trade (%)", minval = 0.1, step = 0.1, group = grpR) rr = input.float(2.5, "Take profit (R)", minval = 0.5, step = 0.1, group = grpR) beR = input.float(1.5, "Geser SL ke BE di (R)", minval = 0.0, step = 0.1, group = grpR, tooltip = "0 = tanpa break-even.") slCapPct = input.float(0.6, "SL maksimal (% harga)", minval = 0.1, step = 0.05, group = grpR) grpF = "Filter" minRange = input.float(0.30, "Range minimum (% harga)", minval = 0.0, step = 0.05, group = grpF) maxRange = input.float(1.60, "Range maksimum (% harga)", minval = 0.1, step = 0.05, group = grpF) buffer = input.float(0.20, "Buffer entry (USD)", minval = 0.0, step = 0.05, group = grpF) // ───────────── Range Asia ───────────── inRange = not na(time(timeframe.period, rangeSess, tz)) inTrade = not na(time(timeframe.period, tradeSess, tz)) var float rh = na var float rl = na var bool ready = false var bool traded = false if inRange and not inRange[1] rh := high rl := low ready := false traded := false else if inRange rh := na(rh) ? high : math.max(rh, high) rl := na(rl) ? low : math.min(rl, low) if not inRange and inRange[1] ready := true rangePct = ready and not na(rh) ? (rh - rl) / close * 100 : na rangeOk = ready and not na(rangePct) and rangePct >= minRange and rangePct <= maxRange // ───────────── State posisi ───────────── var float lStop = na var float sStop = na var float lSL = na var float sSL = na var float lTP = na var float sTP = na var float slNow = na var float tpNow = na var float entryRef = na var float riskRef = na opened = strategy.position_size != 0 and strategy.position_size[1] == 0 if opened traded := true entryRef := strategy.position_avg_price slNow := strategy.position_size > 0 ? lSL : sSL tpNow := strategy.position_size > 0 ? lTP : sTP riskRef := math.abs(entryRef - slNow) // Trade yang buka dan tutup di bar yang sama tetap dihitung 1 trade hari itu if strategy.closedtrades > strategy.closedtrades[1] traded := true // ───────────── Order pending ───────────── canTrade = inTrade and rangeOk and not traded and strategy.position_size == 0 if canTrade lStop := rh + buffer sStop := rl - buffer lSL := math.max(rl, lStop * (1 - slCapPct / 100)) sSL := math.min(rh, sStop * (1 + slCapPct / 100)) lTP := lStop + rr * (lStop - lSL) sTP := sStop - rr * (sSL - sStop) riskCash = strategy.equity * riskPct / 100 qL = riskCash / (lStop - lSL) qS = riskCash / (sSL - sStop) strategy.entry("Long", strategy.long, qty = qL, stop = lStop, oca_name = "7FX-LB", oca_type = strategy.oca.cancel) strategy.entry("Short", strategy.short, qty = qS, stop = sStop, oca_name = "7FX-LB", oca_type = strategy.oca.cancel) strategy.exit("XL", from_entry = "Long", stop = lSL, limit = lTP) strategy.exit("XS", from_entry = "Short", stop = sSL, limit = sTP) else if strategy.position_size == 0 strategy.cancel("Long") strategy.cancel("Short") // ───────────── Manajemen posisi ───────────── if strategy.position_size > 0 if beR > 0 and high >= entryRef + beR * riskRef slNow := math.max(slNow, entryRef) strategy.exit("XL", from_entry = "Long", stop = slNow, limit = tpNow) if strategy.position_size < 0 if beR > 0 and low <= entryRef - beR * riskRef slNow := math.min(slNow, entryRef) strategy.exit("XS", from_entry = "Short", stop = slNow, limit = tpNow) if not inTrade and strategy.position_size != 0 strategy.close_all(comment = "Tutup akhir sesi") // ───────────── Visual (warna 7FX) ───────────── showRange = ready and inTrade pHi = plot(showRange ? rh : na, "Range high", color = color.new(#C8C7C8, 0), style = plot.style_linebr, linewidth = 1) pLo = plot(showRange ? rl : na, "Range low", color = color.new(#C8C7C8, 0), style = plot.style_linebr, linewidth = 1) fill(pHi, pLo, color = rangeOk ? color.new(#C8C7C8, 88) : color.new(#FF5A5F, 90), title = "Range Asia") bgcolor(inRange ? color.new(#E3AE3A, 93) : na, title = "Sesi Asia") plot(strategy.position_size != 0 ? slNow : na, "Stop loss", color = #FF5A5F, style = plot.style_linebr, linewidth = 2) plot(strategy.position_size != 0 ? tpNow : na, "Take profit", color = #2BD48F, style = plot.style_linebr, linewidth = 2)