帮助

作者: zachariahgakere-cell创建于 2025年11月4日更新于 2025年11月4日

// 修改此策略,以提高其效果, //@version=6 indicator("GGbest Backtest Lite v1.2 (Fixed Trade vars) — EMA+FVG + In-chart Backtester", overlay=true, max_boxes_count=250, max_lines_count=250)

// ========== USER INPUTS ========== ema_fast_len = input.int(50, "EMA Fast") ema_slow_len = input.int(200, "EMA Slow") use_fvg = input.bool(true, "Use FVG") use_atr_filter = input.bool(false, "Use ATR acceptance") atr_len = input.int(14, "ATR length") atr_min = input.float(0.0, "Min ATR (0=off)") atr_max = input.float(0.0, "Max ATR (0=off)")

rsi_len = input.int(14, "RSI length")

// Session (your trading hours) — default 21:00-23:00 EAT use_session = input.bool(true, "Restrict to session") sess = input.session("2100-2300", "Session (24h)")

need_confs = input.int(3, "Min confluence (1..4)", minval=1, maxval=4)

// Backtest settings sl_pips = input.int(7, "Stop Loss (pips)", minval=1, maxval=100) // 你表示 5-10 pips — 根据需要更改 lookback_for_tp = input.int(50, "Lookback bars to find nearest swing (TP)", minval=5, maxval=500) max_bars_holding = input.int(200, "Max bars to hold trade", minval=1, maxval=2000)

// Money / sizing start_balance = input.float(100.0, "Start Balance (USD)") pip_size = input.float(0.0001, "Pip size (price units). e.g. EURUSD=0.0001, XAUUSD=0.01, CL=0.01") pip_value_usd = input.float(0.1, "USD per pip (per trade) — change to reflect lot size")

// Display show_stats = input.bool(true, "Show backtest stats on chart") show_trade_markers = input.bool(true, "Show entry/exit markers")

// ========== INDICATORS & BASIC SCANNER ========== ema_fast = ta.ema(close, ema_fast_len) ema_slow = ta.ema(close, ema_slow_len) atr_val = ta.atr(atr_len) rsi = ta.rsi(close, rsi_len)

in_session = not use_session or (time(timeframe.period, sess) != 0) atr_ok = not use_atr_filter or ((atr_min == 0 or atr_val >= atr_min) and (atr_max == 0 or atr_val <= atr_max))

// FVG 检测 (3 条规则) var box[] fvg_bull_boxes = array.new_box() var box[] fvg_bear_boxes = array.new_box() max_boxes = 200 bool bull_fvg = false bool bear_fvg = false if use_fvg and bar_index >= 2 if (high[2] < low[1]) and (low > high[2]) bull_fvg := true array.push(fvg_bull_boxes, box.new(bar_index-2, high[2], bar_index, low[1], bgcolor=color.new(color.green,85))) else bull_fvg := false if (low[2] > high[1]) and (high < low[2]) bear_fvg := true array.push(fvg_bear_boxes, box.new(bar_index-2, high[1], bar_index, low[2], bgcolor=color.new(color.red,85))) else bear_fvg := false while array.size(fvg_bull_boxes) > max_boxes box.delete(array.shift(fvg_bull_boxes)) while array.size(fvg_bear_boxes) > max_boxes box.delete(array.shift(fvg_bear_boxes))

// 趋势 / RSI 共振 bull_trend = ema_fast > ema_slow bear_trend = ema_fast < ema_slow rsi_bull_ok = rsi > 50 rsi_bear_ok = rsi < 50 long_confs = (bull_trend ? 1 : 0) + ((bull_fvg) ? 1 : 0) + (atr_ok ? 1 : 0) + (rsi_bull_ok ? 1 : 0)

内容来源: tensortrade-org/tensortrade