
EMA, ATR, MOMENTUM, EFFICIENCY, BREAKOUT
别被表面的18/50/120三均线设置骗了。这套策略的核心是8个独立维度的趋势验证系统,每个维度都有明确的数值标准。不是简单的金叉死叉,而是通过加权评分机制(最低5.0分入场,2.5分以下出场)来判断趋势质量。
传统均线策略的问题在于假信号太多,这套系统通过路径效率(最低33%)、动量持续性(57%以上上涨K线比例)、波动率状态(ATR比值95%以上)等多重过滤,将入场成功率提升到新高度。
市场上90%的突破都是假突破。这套策略设定突破强度必须达到0.15倍ATR,意味着突破幅度要超过近期平均波动的15%才认定为有效信号。
回调重夺机制更精妙:要求价格距离快线至少0.9倍ATR的深度回调,然后重新站上均线时强度达到0.15倍ATR。这种设计有效过滤了浅层假突破,只捕捉真正有资金推动的趋势启动。
杠杆设置2倍看似激进,但配合2%硬止损和2.8倍ATR动态追踪,实际风险可控。更关键的是20.8倍ATR的利润锁定机制,当浮盈达到这个水平时自动提升止损位,确保大趋势中的利润不会回吐。
强制持仓1根完整K线的设计防止了高频进出,5根K线的冷却期避免了情绪化连续交易。这种节奏控制比纯技术指标更重要。
趋势延续入场:适用于已确立的强势趋势,要求突破+斜率+效率+动量全部达标。回调重入:针对健康的趋势回调,要求深度足够且重夺有力。早期趋势入场:捕捉趋势转换的黄金14根K线窗口期。
这种多模式设计的优势在于不会错过任何类型的趋势机会,同时每种模式都有严格的质量标准。不是广撒网,而是精准狙击。
路径效率计算18周期内净位移与累计位移的比值,低于33%的趋势一律不碰。这个指标能有效识别震荡行情中的假趋势,避免在横盘市场中被反复止损。
动量持续性要求57%以上的K线收阳,配合12周期动量必须为正。这种双重验证确保了趋势的内在强度,而不仅仅是价格的表面突破。
这套策略明显偏向趋势市场,在震荡行情中会频繁触发出场信号。ATR状态低于80%且效率低于25%时强制出场的设计,说明策略对市场环境有明确要求。
最大的风险在于趋势转换期的滞后性,虽然有快速EMA交叉等早期预警,但在急速反转中仍可能面临较大回撤。建议在波动率较高的成长股或加密货币市场使用,避免在大盘蓝筹等低波动品种上应用。
风险提示:历史回测不代表未来收益,策略存在连续亏损风险,需严格执行风险管理,不同市场环境下表现差异显著。
/*backtest
start: 2026-01-07 15:30:00
end: 2026-03-15 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"XAG_USDT","balance":500000}]
*/
//@version=5
strategy("Quant Trend Engine Long Only v2 - Manual Leverage Fixed", overlay=true)
// === Core lengths ===
fastLen = input.int(18, "Fast EMA")
midLen = input.int(50, "Mid EMA")
slowLen = input.int(120, "Slow EMA")
smoothLen = input.int(3, "EMA Smoothing")
pullbackLen = input.int(8, "Pullback Lookback")
breakoutLen = input.int(20, "Breakout Length")
effLen = input.int(18, "Efficiency Length")
persistLen = input.int(7, "Persistence Length")
momLen = input.int(12, "Momentum Length")
slopeLen = input.int(10, "Slope Length")
atrLen = input.int(14, "ATR Length")
atrBaseLen = input.int(40, "ATR Baseline Length")
// === Thresholds ===
minScore = input.float(5.0, "Minimum Entry Score", step=0.25)
exitScore = input.float(2.5, "Weak Trend Exit Score", step=0.25)
minSepPerc = input.float(0.30, "Min EMA Separation %", step=0.05)
minSlowSlopePerc = input.float(0.03, "Min Slow Slope %", step=0.01)
minEff = input.float(0.33, "Min Efficiency", step=0.01)
minAtrRegime = input.float(0.95, "Min ATR Regime", step=0.05)
minBreakoutAtr = input.float(0.15, "Min Breakout ATR Strength", step=0.05)
pullbackAtrMult = input.float(0.90, "Pullback Distance ATR", step=0.05)
reclaimAtrMult = input.float(0.15, "Reclaim Distance ATR", step=0.05)
cooldownBars = input.int(5, "Cooldown Bars After Exit")
// === Risk ===
leverage = input.float(2.0, "Leverage", step=0.1, minval=0.1)
hardStopPerc = input.float(2.0, "Hard Stop %", step=0.1)
trailAtrMult = input.float(2.8, "ATR Trail Mult", step=0.1)
profitLockAtrMult = input.float(20.8, "Profit Lock ATR Mult", step=0.1)
// === Smoothed EMAs ===
fast = ta.ema(ta.ema(close, fastLen), smoothLen)
mid = ta.ema(ta.ema(close, midLen), smoothLen)
slow = ta.ema(ta.ema(close, slowLen), smoothLen)
// === Regime structure ===
bullStack = fast > mid and mid > slow
sepPerc = slow != 0 ? math.abs(fast - slow) / slow * 100 : 0.0
sepOk = sepPerc >= minSepPerc
fastSlope = fast[slopeLen] != 0 ? (fast - fast[slopeLen]) / fast[slopeLen] * 100 : 0.0
midSlope = mid[slopeLen] != 0 ? (mid - mid[slopeLen]) / mid[slopeLen] * 100 : 0.0
slowSlope = slow[slopeLen] != 0 ? (slow - slow[slopeLen]) / slow[slopeLen] * 100 : 0.0
slopeOk = slowSlope >= minSlowSlopePerc and midSlope > 0 and fastSlope > 0
// === Path efficiency ===
netMove = math.abs(close - close[effLen])
stepMove = 0.0
for i = 1 to effLen
stepMove += math.abs(close[i - 1] - close[i])
efficiency = stepMove != 0 ? netMove / stepMove : 0.0
effOk = efficiency >= minEff
// === Momentum persistence ===
upBars = 0.0
for i = 0 to persistLen - 1
upBars += close[i] > close[i + 1] ? 1 : 0
persistRatio = persistLen > 0 ? upBars / persistLen : 0.0
momRaw = close[momLen] != 0 ? (close - close[momLen]) / close[momLen] * 100 : 0.0
momOk = momRaw > 0 and persistRatio >= 0.57
// === Volatility regime ===
atr = ta.atr(atrLen)
atrBase = ta.sma(atr, atrBaseLen)
atrRegime = atrBase != 0 ? atr / atrBase : 0.0
atrOk = atrRegime >= minAtrRegime
// === Breakout quality ===
hh = ta.highest(high, breakoutLen)[1]
breakoutDist = close - hh
breakoutStrength = atr != 0 ? breakoutDist / atr : 0.0
breakoutOk = close > hh and breakoutStrength >= minBreakoutAtr
// === Pullback / reclaim logic ===
pullbackLow = ta.lowest(low, pullbackLen)
distFromFastAtr = atr != 0 ? (fast - pullbackLow) / atr : 0.0
deepEnoughPullback = distFromFastAtr >= pullbackAtrMult
reclaimFast = close > fast and close[1] <= fast[1]
reclaimMid = close > mid and close[1] <= mid[1]
reclaimStrength = atr != 0 ? (close - fast) / atr : 0.0
reclaimOk = (reclaimFast or reclaimMid) and reclaimStrength >= reclaimAtrMult
// === Transition memory ===
bullCross = ta.crossover(fast, mid) or ta.crossover(fast, slow) or ta.crossover(mid, slow)
barsSinceBullCross = ta.barssince(bullCross)
recentTrendBirth = barsSinceBullCross >= 0 and barsSinceBullCross <= 14
// === Weighted score ===
trendScore = 0.0
trendScore += bullStack ? 1.50 : 0.0
trendScore += sepOk ? 0.90 : 0.0
trendScore += slopeOk ? 1.10 : 0.0
trendScore += effOk ? 1.00 : 0.0
trendScore += atrOk ? 0.80 : 0.0
trendScore += momOk ? 1.00 : 0.0
trendScore += breakoutOk ? 1.25 : 0.0
trendScore += reclaimOk ? 1.10 : 0.0
// === Entry models ===
trendContinuationEntry = bullStack and breakoutOk and slopeOk and effOk and momOk
pullbackReentry = bullStack and sepOk and slopeOk and deepEnoughPullback and reclaimOk and effOk
earlyTrendEntry = recentTrendBirth and bullStack and sepOk and slopeOk and atrOk and momOk
// === Cooldown ===
var int lastExitBar = na
cooldownOk = na(lastExitBar) or bar_index - lastExitBar > cooldownBars
// === Final entry ===
enterLong = strategy.position_size == 0 and cooldownOk and trendScore >= minScore and close > slow and (trendContinuationEntry or pullbackReentry or earlyTrendEntry)
// === Manual leveraged sizing only ===
equity = math.max(strategy.equity, 0)
positionValue = equity * leverage
qty = positionValue > 0 ? positionValue / (close * syminfo.pointvalue) : 0.0
// === Entry tracking / mandatory 1 full candle hold ===
var int entryBarIndex = na
justOpened = strategy.position_size > 0 and strategy.position_size[1] == 0
if justOpened
entryBarIndex := bar_index
canExitNow = strategy.position_size > 0 and not na(entryBarIndex) and bar_index > entryBarIndex
// === Entry order ===
if enterLong and qty > 0
strategy.entry("Long", strategy.long, qty=qty)
// === Risk logic ===
hardStopPrice = strategy.position_size > 0 ? strategy.position_avg_price * (1 - hardStopPerc / 100) : na
var float trailStop = na
var float highSinceEntry = na
highSinceEntry := strategy.position_size > 0 ? (na(highSinceEntry) ? high : math.max(highSinceEntry, high)) : na
rawTrail = strategy.position_size > 0 ? close - atr * trailAtrMult : na
profitLock = strategy.position_size > 0 ? highSinceEntry - atr * profitLockAtrMult : na
combinedTrail = strategy.position_size > 0 ? math.max(rawTrail, profitLock) : na
trailStop := strategy.position_size > 0 ? (na(trailStop) ? combinedTrail : math.max(trailStop, combinedTrail)) : na
// === Exit logic ===
bearCross = ta.crossunder(fast, mid) or ta.crossunder(fast, slow)
structureBreak = close < mid and fast < mid
scoreWeak = trendScore <= exitScore
momentumFailure = persistRatio < 0.40 and momRaw < 0
regimeFailure = atrRegime < 0.80 and efficiency < 0.25
exitLong = strategy.position_size > 0 and canExitNow and (bearCross or structureBreak or scoreWeak or momentumFailure or regimeFailure)
// Only allow stop/trailing exits after 1 full candle has passed
if strategy.position_size > 0 and canExitNow
strategy.exit("Risk Exit", from_entry="Long", stop=math.max(hardStopPrice, trailStop))
justClosed = strategy.position_size[1] > 0 and strategy.position_size == 0
if justClosed
lastExitBar := bar_index
trailStop := na
highSinceEntry := na
entryBarIndex := na
if exitLong
strategy.close("Long")
// === Plots ===
plot(fast, color=color.green, linewidth=2, title="Fast EMA")
plot(mid, color=color.orange, linewidth=2, title="Mid EMA")
plot(slow, color=color.red, linewidth=2, title="Slow EMA")
plot(strategy.position_size > 0 ? trailStop : na, color=color.blue, linewidth=2, title="Adaptive Trail")
plot(trendScore, title="Trend Score", color=color.aqua)
plot(efficiency, title="Efficiency", color=color.fuchsia)
plot(atrRegime, title="ATR Regime", color=color.yellow)
plot(breakoutStrength, title="Breakout Strength", color=color.lime)
plot(persistRatio, title="Persistence Ratio", color=color.white)