在量化交易领域,我们经常面临一个核心问题:单一技术指标在市场噪音中容易产生假信号,导致频繁止损和资金回撤。那么,如何构建一个既能捕捉趋势又能有效过滤噪音的交易系统呢?
今天分析的这个高斯通道多重过滤策略,通过巧妙地组合四个不同维度的技术指标,为我们提供了一个值得深入研究的解决方案。
1. 高斯通道(Gaussian Channel)- 趋势识别核心
策略的基础是一个4阶高斯滤波器,采用144周期的采样窗口。与传统移动平均线不同,高斯滤波器通过数学建模消除了大部分市场噪音,同时保持了对价格变化的敏感性。
关键参数设置: - 高斯极点数:4(平衡滞后性与平滑度) - 采样周期:144(捕捉中期趋势) - 滤波倍数:1.414(标准差倍数,控制通道宽度)
2. Kijun-Sen线(130周期)- 中长期趋势确认
这里使用了130周期的Kijun-Sen线作为趋势过滤器,而非传统的26周期。这种调整有何深意?
较长的周期设置能够: - 减少假突破信号 - 确保交易方向与主趋势一致 - 提高信号质量,降低交易频率
3. VAPI指标 - 成交量价格分析
VAPI(Volume Adjusted Price Indicator)通过分析成交量与价格变化的关系,判断市场参与者的真实意图。当VAPI > 0时支持做多,< 0时支持做空。
4. ATR动态止损 - 风险控制机制
使用11周期ATR的4.5倍作为止损距离,这种设置既考虑了市场波动性,又避免了过于紧密的止损被市场噪音触发。
这个策略最值得学习的地方在于其独特的资金管理方式:
分仓逻辑: - 75%仓位:固定3.5倍风险回报比止盈 - 25%仓位:动态追踪止损
为什么这样设计?
1. 入场风险控制 - 每笔交易风险限制在账户资金的3% - 基于ATR的动态仓位计算
2. 持仓风险管理 - 主止损:ATR的4.5倍 - 追踪止损:动态调整,锁定浮盈 - 额外止盈:10%固定收益保护
3. 信号过滤机制 四重技术指标同时确认,大幅降低假信号概率。
核心优势:
潜在局限:
1. 品种选择 优先选择趋势性较强的品种,如主要货币对、股指期货等。
2. 参数优化 建议根据具体交易品种的历史数据进行回测优化,特别关注: - 高斯通道的采样周期 - Kijun-Sen的周期长度 - ATR止损倍数
3. 市场环境适配 在明显的震荡市场中,可以考虑暂停策略或调整参数设置。
这个策略的价值不仅在于其技术实现,更在于其体现的系统性思维:
对于量化交易者而言,这个策略提供了一个很好的框架参考。关键不是照搬参数,而是理解其设计思路,并根据自己的交易品种和风险偏好进行适当调整。
记住,最好的策略不是最复杂的,而是最适合你的交易风格和市场环境的。
/*backtest
start: 2025-01-01 00:00:00
end: 2025-09-07 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","FG509",360008]]
*/
// @version=6
strategy("Gaussian Channel Strategy", overlay=true)
// =============================
// ======= INPUTS ==============
// =============================
N_poles = input.int(4, "Gaussian Poles", minval=1, maxval=9)
per = input.int(144, "Sampling Period", minval=2)
mult = input.float(1.414, "Filtered TR Multiplier", step=0.001)
src = input.source(hlc3, "Source")
modeLag = input.bool(false, "Reduced Lag Mode")
modeFast = input.bool(false, "Fast Response Mode")
kijunLen = input.int(130, "Kijun-Sen Period")
vapiLen = input.int(10, "VAPI Length")
vapiThresh= input.float(0.0, "VAPI Threshold (0 = zero line)")
atrLen = input.int(11, "ATR Length (RMA)")
slATRmul = input.float(4.5, "SL = ATR ×", step=0.1)
rr_fixed = input.float(3.5, "Fixed TP RR (Leg A)", step=0.1)
allocA = input.float(75, "Allocation %: Fixed TP Leg", minval=1, maxval=99)
riskPct = input.float(3.0, "Risk % of Equity per Trade", step=0.1, minval=0.1, maxval=10)
tpEnable = input.bool(true, "Enable Extra % Take Profit")
tpPctLong = input.float(10.0, "Extra Long TP % of Entry", step=0.1, minval=0)
tpPctShort = input.float(10.0, "Extra Short TP % of Entry", step=0.1, minval=0)
// =============================
// ===== CORE COMPONENTS =======
// =============================
atr = ta.rma(ta.tr(true), atrLen)
donchian_avg(len) => (ta.highest(high, len) + ta.lowest(low, len)) / 2.0
kijun = donchian_avg(kijunLen)
// --- VAPI_LB (LazyBear) ---
rs(x, len) => ta.cum(x) - nz(ta.cum(x)[len])
v_x = (2*close - high - low) / math.max(high - low, syminfo.mintick)
v_tva = rs(volume * v_x, vapiLen)
v_tv = rs(volume, vapiLen)
v_va = 100 * (v_tva / v_tv)
// =============================
// ===== Gaussian Channel ======
// =============================
f_filt9x(_a, _s, _i) =>
int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0,
int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = 0.0, _x = (1 - _a)
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i) * nz(_s) +
_i * _x * nz(_f[1]) - (_i >= 2 ?
_m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ?
_m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ?
_m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ?
_m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ?
_m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ?
_m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ?
_m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ?
_m9 * math.pow(_x, 9) * nz(_f[9]) : 0)
f_pole(_a, _s, _i) =>
_f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
_f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5) : 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
_f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8) : 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]
beta = (1 - math.cos(4*math.asin(1)/per)) / (math.pow(1.414, 2/N_poles) - 1)
alpha = - beta + math.sqrt(math.pow(beta, 2) + 2*beta)
lag = (per - 1) / (2.0 * N_poles)
srcdata = modeLag ? src + (src - nz(src[lag])) : src
tr_raw = ta.tr(true)
trdata = modeLag ? tr_raw + (tr_raw - nz(tr_raw[lag])) : tr_raw
[filt_n, filt_1] = f_pole(alpha, srcdata, N_poles)
[filt_n_tr, filt_1_tr] = f_pole(alpha, trdata, N_poles)
filt = modeFast ? (filt_n + filt_1)/2.0 : filt_n
filttr = modeFast ? (filt_n_tr + filt_1_tr)/2.0 : filt_n_tr
hband = filt + filttr * mult
lband = filt - filttr * mult
// =============================
// ===== Signals & Filters =====
// =============================
doLong = close > filt and close > kijun and v_va > vapiThresh
doShort = close < filt and close < kijun and v_va < -vapiThresh
// =============================
// ===== Position Sizing =======
// =============================
riskValue = strategy.equity * (riskPct/100.0)
slDist = atr * slATRmul * syminfo.pointvalue
qtyTotal = slDist > 0 ? riskValue / slDist : 0.0
qtyA = qtyTotal * (allocA/100.0)
qtyB = qtyTotal * ((100 - allocA)/100.0)
// =============================
// ===== Order Execution =======
// =============================
var float trailStopL = na
var float trailStopS = na
inLong = strategy.position_size > 0
inShort = strategy.position_size < 0
entryPx = strategy.position_avg_price
// Entries
if doLong and not inLong and strategy.position_size <= 0
strategy.order("L-A", strategy.long, qty=qtyA)
strategy.order("L-B", strategy.long, qty=qtyB)
trailStopL := na
if doShort and not inShort and strategy.position_size >= 0
strategy.order("S-A", strategy.short, qty=qtyA)
strategy.order("S-B", strategy.short, qty=qtyB)
trailStopS := na
// LONG management
if inLong
slL = entryPx - slDist
tpA = entryPx + rr_fixed * slDist
// Leg A: 固定RR止盈 + 止损
strategy.exit("TP/SL-LA", from_entry="L-A", limit=tpA, stop=slL)
// Leg B: 追踪止损
trailStopL := na(trailStopL[1]) or strategy.position_size[1] <= 0 ? slL : math.max(trailStopL[1], close - slDist)
strategy.exit("Trail-LB", from_entry="L-B", stop=trailStopL)
// 额外百分比止盈
if tpEnable and high >= entryPx * (1 + tpPctLong/100.0)
strategy.close("L-A", comment="ExtraTP")
strategy.close("L-B", comment="ExtraTP")
// SHORT management
if inShort
slS = entryPx + slDist
tpA = entryPx - rr_fixed * slDist
// Leg A: 固定RR止盈 + 止损
strategy.exit("TP/SL-SA", from_entry="S-A", limit=tpA, stop=slS)
// Leg B: 追踪止损
trailStopS := na(trailStopS[1]) or strategy.position_size[1] >= 0 ? slS : math.min(trailStopS[1], close + slDist)
strategy.exit("Trail-SB", from_entry="S-B", stop=trailStopS)
// 额外百分比止盈
if tpEnable and low <= entryPx * (1 - tpPctShort/100.0)
strategy.close("S-A", comment="ExtraTP")
strategy.close("S-B", comment="ExtraTP")
// =============================
// ===== 图表绘制 ==============
// =============================
fcolor = filt > nz(filt[1]) ? color.new(color.lime, 0) : filt < nz(filt[1]) ? color.new(color.red, 0) : color.new(color.gray, 0)
plotFilter = plot(filt, title="GC Filter", color=fcolor, linewidth=2)
plotH = plot(hband, title="GC High Band", color=fcolor)
plotL = plot(lband, title="GC Low Band", color=fcolor)
fill(plotH, plotL, color=color.new(fcolor, 80))
plot(kijun, "Kijun-Sen", color=color.new(color.maroon, 0))
// 信号标记
plotshape(doLong, title="Long Setup", style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), size=size.tiny, text="ENTRY L")
plotshape(doShort, title="Short Setup", style=shape.triangledown, location=location.abovebar, color=color.new(color.fuchsia, 0), size=size.tiny, text="ENTRY S")