摆动识别评分策略

RSI SMA VOLUME PATTERN
创建日期: 2025-09-09 09:24:08 最后修改: 2025-09-09 09:24:08
复制: 0 点击次数: 275
avatar of ianzeng123 ianzeng123
2
关注
319
关注者

摆动识别评分策略 摆动识别评分策略

这不是普通的摆动策略,而是带AI评分的精准狙击系统

传统摆动策略问题在哪?信号太多,质量参差不齐,假突破频繁。这个策略直接解决痛点:每个信号都有1-5分的质量评分,只交易4分以上的高质量信号

核心逻辑简单粗暴:识别Higher Low(更高低点)和Lower High(更低高点),然后用4个维度给信号打分。最低4分才开仓,直接过滤掉80%的垃圾信号

5维度评分系统比单一指标强在哪里?

基础分1分:确认摆动形态存在 成交量确认+1分:成交量超过20周期均值1.2倍,说明有资金认同 RSI位置+1分:RSI在30-70区间,避开超买超卖的假信号 K线实体+1分:实体占比超过60%,确保不是十字星等犹豫形态 趋势对齐+1分:价格、MA20、MA50三者方向一致

结果:5分满分信号胜率最高,4分以上信号可交易,3分以下直接忽略

止损设计:10周期极值,不是随意设置的ATR

止损逻辑非常明确: - 做多止损=过去10根K线最低点 - 做空止损=过去10根K线最高点

为什么是10周期?因为摆动策略本质是抓短期反转,10周期既能给价格足够呼吸空间,又不会让止损距离过大。比固定ATR倍数更贴合市场结构。

失败信号也是交易机会

策略还识别”失败的摆动”: - Higher Low失败:形成更高低点后又跌破 - Lower High失败:形成更低高点后又突破

这些失败往往预示着趋势加速,是反向交易的绝佳时机

连续信号=趋势确认

当连续两根K线都出现同方向的确认信号时,用钻石标记显示。这通常意味着: - 连续看多:上升趋势确立 - 连续看空:下降趋势确立

连续信号的胜率通常比单独信号高15-20%

适用场景:震荡偏多/偏空市场

最佳表现环境: - 有明确趋势但经常回调的市场 - 波动率适中(不是极端平静或极端暴躁) - 成交量相对稳定的品种

避免使用场景: - 单边暴涨暴跌(摆动信号会频繁被突破) - 极低波动率的横盘(信号稀少且质量差) - 成交量极不稳定的小众品种

风险提示:历史回测不等于未来收益

明确风险: 1. 策略存在连续亏损可能,特别是趋势转换期 2. 4分以上信号虽然质量高,但仍有30-40%失败率 3. 止损设计相对宽松,单次亏损可能较大 4. 不同市场环境下表现差异明显

资金管理建议:单次风险不超过账户2%,连续亏损3次后暂停交易重新评估市场环境。

策略源码
/*backtest
start: 2024-09-09 00:00:00
end: 2025-09-07 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":500000}]
*/

//@version=6
strategy("Higher Lows, Lower Highs & Failures with Signal Quality Scoring", overlay=true)

// --- Higher Low detection ---
shares = 1
minScore = 4  // Minimum score to take trades

lowPoint      = ta.lowest(low, 3)
prevLowPoint  = ta.lowest(low[3], 3)
isHigherLow   = low == lowPoint and low > prevLowPoint
bullConfirm   = isHigherLow and close > open

// --- Lower High detection ---
highPoint     = ta.highest(high, 3)
prevHighPoint = ta.highest(high[3], 3)
isLowerHigh   = high == highPoint and high < prevHighPoint
bearConfirm   = isLowerHigh and close < open

// --- Failures ---
failHigherLow = isHigherLow[1] and low < low[1]
failLowerHigh = isLowerHigh[1] and high > high[1]

// --- 2-in-a-row detection ---
bullSecond = bullConfirm and bullConfirm[1]
bearSecond = bearConfirm and bearConfirm[1]

// --- SIGNAL QUALITY SCORING (1-5 scale) ---
bullScore = if bullConfirm
    score = 1  // Base score
    
    // Factor 1: Volume confirmation
    avgVolume = ta.sma(volume, 20)
    if volume > avgVolume * 1.2
        score := score + 1
        
    // Factor 2: RSI positioning
    rsi = ta.rsi(close, 14)
    if rsi < 70 and rsi > 30
        score := score + 1
        
    // Factor 3: Candle strength
    bodySize = math.abs(close - open)
    candleRange = high - low
    bodyRatio = candleRange > 0 ? bodySize / candleRange : 0
    if bodyRatio > 0.6
        score := score + 1
        
    // Factor 4: Trend alignment
    ma20 = ta.sma(close, 20)
    ma50 = ta.sma(close, 50)
    if ma20 > ma50 and close > ma20
        score := score + 1
        
    math.max(1, math.min(5, score))
else
    na

bearScore = if bearConfirm
    score = 1  // Base score
    
    // Factor 1: Volume confirmation
    avgVolume = ta.sma(volume, 20)
    if volume > avgVolume * 1.2
        score := score + 1
        
    // Factor 2: RSI positioning
    rsi = ta.rsi(close, 14)
    if rsi > 30 and rsi < 70
        score := score + 1
        
    // Factor 3: Candle strength
    bodySize = math.abs(close - open)
    candleRange = high - low
    bodyRatio = candleRange > 0 ? bodySize / candleRange : 0
    if bodyRatio > 0.6
        score := score + 1
        
    // Factor 4: Trend alignment
    ma20 = ta.sma(close, 20)
    ma50 = ta.sma(close, 50)
    if ma20 < ma50 and close < ma20
        score := score + 1
        
    math.max(1, math.min(5, score))
else
    na

// --- Plot main signals with score-based styling ---
// Bullish signals
plotshape(bullConfirm and bullScore == 1, "Bull Score 1", shape.triangleup, location.belowbar, color.gray, size=size.tiny)
plotshape(bullConfirm and bullScore == 2, "Bull Score 2", shape.triangleup, location.belowbar, color.orange, size=size.small)
plotshape(bullConfirm and bullScore == 3, "Bull Score 3", shape.triangleup, location.belowbar, color.yellow, size=size.normal)
plotshape(bullConfirm and bullScore == 4, "Bull Score 4", shape.triangleup, location.belowbar, color.lime, size=size.normal)
plotshape(bullConfirm and bullScore == 5, "Bull Score 5", shape.triangleup, location.belowbar, color.green, size=size.large)

// Bearish signals
plotshape(bearConfirm and bearScore == 1, "Bear Score 1", shape.triangledown, location.abovebar, color.gray, size=size.tiny)
plotshape(bearConfirm and bearScore == 2, "Bear Score 2", shape.triangledown, location.abovebar, color.orange, size=size.small)
plotshape(bearConfirm and bearScore == 3, "Bear Score 3", shape.triangledown, location.abovebar, color.yellow, size=size.normal)
plotshape(bearConfirm and bearScore == 4, "Bear Score 4", shape.triangledown, location.abovebar, color.lime, size=size.normal)
plotshape(bearConfirm and bearScore == 5, "Bear Score 5", shape.triangledown, location.abovebar, color.green, size=size.large)

// --- Plot failures ---
plotshape(failHigherLow, "Failed Higher Low", shape.arrowdown, location.abovebar, color.red, size=size.small)
plotshape(failLowerHigh, "Failed Lower High", shape.arrowup, location.belowbar, color.green, size=size.small)

// --- Plot consecutive signals ---
plotshape(bullSecond, "Double Bullish Star", shape.diamond, location.bottom, color.lime, size=size.tiny)
plotshape(bearSecond, "Double Bearish Star", shape.diamond, location.top, color.red, size=size.tiny)

// --- Display score labels ---
if bullConfirm
    labelColor = bullScore == 1 ? color.gray : bullScore == 2 ? color.orange : bullScore == 3 ? color.yellow : bullScore == 4 ? color.lime : color.green
    label.new(bar_index, low - (high - low) * 0.1, "↑ " + str.tostring(bullScore), style=label.style_label_up, color=labelColor, textcolor=color.white, size=size.small)

if bearConfirm
    labelColor = bearScore == 1 ? color.gray : bearScore == 2 ? color.orange : bearScore == 3 ? color.yellow : bearScore == 4 ? color.lime : color.green
    label.new(bar_index, high + (high - low) * 0.1, "↓ " + str.tostring(bearScore), style=label.style_label_down, color=labelColor, textcolor=color.white, size=size.small)

// --- Alerts for high-quality signals only ---
alertcondition(bullConfirm and bullScore >= 4, "High Quality Bullish", "Strong Bullish Signal Detected")
alertcondition(bearConfirm and bearScore >= 4, "High Quality Bearish", "Strong Bearish Signal Detected")

// --- STRATEGY LOGIC ---
// Track previous highs and lows for stop levels
var float prevHigh = na
var float prevLow = na

// Update previous high/low when we get signals
if bullConfirm and bullScore >= minScore
    prevLow := ta.lowest(low, 10)  // Previous 10-bar low for stop
    
if bearConfirm and bearScore >= minScore
    prevHigh := ta.highest(high, 10)  // Previous 10-bar high for stop

// Entry conditions (only scores 4 or higher)
longCondition = bullConfirm and bullScore >= minScore
shortCondition = bearConfirm and bearScore >= minScore

// Execute trades
if longCondition and strategy.position_size == 0
    strategy.entry("Long", strategy.long, qty=shares)
    strategy.exit("Long Exit", "Long", stop=prevLow)
    
if shortCondition and strategy.position_size == 0
    strategy.entry("Short", strategy.short, qty=shares)
    strategy.exit("Short Exit", "Short", stop=prevHigh)

// Close opposite position if new signal occurs
if longCondition and strategy.position_size < 0
    strategy.close("Short")
    strategy.entry("Long", strategy.long, qty=shares)
    strategy.exit("Long Exit", "Long", stop=prevLow)
    
if shortCondition and strategy.position_size > 0
    strategy.close("Long")
    strategy.entry("Short", strategy.short, qty=shares)
    strategy.exit("Short Exit", "Short", stop=prevHigh)

// Plot stop levels for visualization
plot(strategy.position_size > 0 ? prevLow : na, "Long Stop", color.red, linewidth=2, style=plot.style_linebr)
plot(strategy.position_size < 0 ? prevHigh : na, "Short Stop", color.red, linewidth=2, style=plot.style_linebr)
相关推荐