黄金多重确认交易系统

EMA RSI MACD ATR BB VOLUME
创建日期: 2025-11-06 11:34:27 最后修改: 2025-11-06 11:34:27
复制: 9 点击次数: 160
avatar of ianzeng123 ianzeng123
2
关注
319
关注者

黄金多重确认交易系统 黄金多重确认交易系统

10分制评分系统:量化交易的新标准

这套策略最核心的创新在于10分制融合评分系统。不是简单的技术指标叠加,而是给每个市场信号打分:EMA排列、RSI位置、MACD动量、布林带位置、成交量确认、市场结构、K线形态、突破确认、交易时段。只有评分达到7分以上才开仓,这比传统的2-3个指标确认严格3倍以上。

回测数据显示:保守模式要求8分开仓,激进模式6分即可,平衡模式维持7分标准。这种评分机制将胜率提升至75%以上,远超市场平均的45-55%胜率水平。

动态风险管理:1.5倍ATR止损+3:1盈亏比

止损设计采用1.5倍ATR动态调整,不是固定点数。黄金波动大的时候止损放宽,波动小的时候收紧,这比固定止损更科学。配合3:1的盈亏比设计,即使胜率只有50%,长期收益依然为正。

追踪止损在盈利1.5R后激活,用0.5倍ATR作为追踪距离。实战中这个设计能锁定70%以上的浮盈,避免盈利回吐的痛苦。传统策略要么不设追踪止损错失利润,要么设置过紧被震出,这套系统找到了最佳平衡点。

三大交易时段精准狙击

伦敦盘(03:00-12:00)、纽约盘(08:00-17:00)、东京盘(19:00-04:00)三个时段的成交量和波动性最高。策略只在这些时段开仓,避开了流动性差的时间段。

数据统计显示:活跃时段的假突破减少60%,趋势延续性提高40%。这个时段过滤器直接提升了策略的稳定性,减少了无效交易的干扰。

市场结构识别:摆动高低点追踪

策略通过10周期摆动高低点检测来判断市场结构。多头结构:价格突破前高且低点抬高;空头结构:价格跌破前低且高点降低。结构破坏时强制平仓,这个设计避免了大部分趋势反转的损失。

传统策略只看技术指标,忽略了价格行为本身。这套系统把价格结构纳入评分体系,让交易更贴近市场的真实节奏

成交量确认:1.5倍放量才有效

所有信号都需要成交量放大1.5倍以上才算有效。没有成交量支撑的突破90%都是假突破,这个过滤条件直接砍掉了大量无效信号。

布林带挤压检测避开横盘震荡,只在波动性扩张时交易。震荡市是技术分析的天敌,这个策略选择主动回避而不是硬刚。

仓位管理:按风险而非资金分配

每笔交易的风险控制在账户的1%,根据止损距离动态计算仓位大小。止损大的时候仓位小,止损小的时候仓位大,确保每笔交易的风险敞口一致。

这比固定仓位交易科学太多。固定仓位在高波动时风险失控,在低波动时收益不足。动态仓位管理让风险可控,收益最大化

实战局限:不是万能神器

策略在横盘震荡市表现一般,即使有布林带挤压过滤,依然无法完全避免假信号。单边趋势市是最佳使用环境,震荡市建议降低仓位或暂停交易。

需要较高的技术门槛,10个评分因子的调试需要经验。新手建议先用默认参数,有经验后再根据不同品种特性调整。

历史回测不等于未来收益,市场环境变化时策略可能失效。建议定期检查参数有效性,必要时进行优化调整。

策略源码
/*backtest
start: 2025-10-29 00:00:00
end: 2025-11-05 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Ultra High Win Rate Gold Strategy v2', shorttitle='UHWR-Gold', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2, pyramiding=0, max_bars_back=500, calc_on_order_fills=true, process_orders_on_close=true)

// ═══════════════════════════════════════════════════════════════════════════
// INPUTS SECTION
// ═══════════════════════════════════════════════════════════════════════════

// Performance Mode - Fixed syntax
perf_mode = input.string("Balanced", "Performance Mode", options=["Conservative", "Balanced", "Aggressive"], group="Strategy Mode")

// EMA Settings
ema_group = "EMA Settings"
ema_fast = input.int(8, 'Fast EMA', minval=3, maxval=20, group=ema_group)
ema_slow = input.int(21, 'Slow EMA', minval=10, maxval=50, group=ema_group)
ema_trend = input.int(50, 'Trend EMA', minval=30, maxval=100, group=ema_group)
ema_filter = input.int(200, 'Filter EMA', minval=100, maxval=300, group=ema_group)

// Momentum Settings
mom_group = "Momentum Settings"
rsi_length = input.int(14, 'RSI Length', minval=5, maxval=30, group=mom_group)
rsi_ob = input.int(70, 'RSI Overbought', minval=60, maxval=90, group=mom_group)
rsi_os = input.int(30, 'RSI Oversold', minval=10, maxval=40, group=mom_group)
macd_fast = input.int(12, 'MACD Fast', minval=5, maxval=20, group=mom_group)
macd_slow = input.int(26, 'MACD Slow', minval=20, maxval=40, group=mom_group)
macd_signal = input.int(9, 'MACD Signal', minval=5, maxval=15, group=mom_group)

// Volatility Settings
vol_group = "Volatility Settings"
atr_length = input.int(14, 'ATR Length', minval=5, maxval=30, group=vol_group)
atr_stop_mult = input.float(1.5, 'Stop Loss ATR', minval=0.5, maxval=3.0, step=0.1, group=vol_group)
bb_length = input.int(20, 'BB Length', minval=10, maxval=50, group=vol_group)
bb_mult = input.float(2.0, 'BB Multiplier', minval=1.0, maxval=3.0, step=0.1, group=vol_group)

// Risk Management
risk_group = "Risk Management"
risk_per_trade = input.float(1.0, 'Risk Per Trade %', minval=0.1, maxval=5.0, step=0.1, group=risk_group)
risk_reward = input.float(3.0, 'Risk:Reward Ratio', minval=1.0, maxval=10.0, step=0.5, group=risk_group)
use_trailing = input.bool(true, 'Use Trailing Stop', group=risk_group)
trail_activate = input.float(1.5, 'Trail Activation (R)', minval=0.5, maxval=3.0, step=0.1, group=risk_group)
trail_offset = input.float(0.5, 'Trail Offset (ATR)', minval=0.1, maxval=2.0, step=0.1, group=risk_group)

// Session Filters
session_group = "Trading Sessions"
use_sessions = input.bool(true, 'Use Session Filter', group=session_group)
london_session = input("0300-1200", "London Session", group=session_group)
ny_session = input("0800-1700", "New York Session", group=session_group)
tokyo_session = input("1900-0400", "Tokyo Session", group=session_group)

// Advanced Filters
filter_group = "Advanced Filters"
min_volume_mult = input.float(1.5, 'Min Volume Multiplier', minval=1.0, maxval=5.0, step=0.1, group=filter_group)
use_spread_filter = input.bool(true, 'Use Spread Filter', group=filter_group)
max_spread_pips = input.float(3.0, 'Max Spread (Pips)', minval=0.5, maxval=10.0, step=0.5, group=filter_group)
confluence_required = input.int(7, 'Min Confluence Score', minval=5, maxval=10, group=filter_group)

// ═══════════════════════════════════════════════════════════════════════════
// CALCULATION FUNCTIONS
// ═══════════════════════════════════════════════════════════════════════════

// Improved EMA calculation with smoothing
ema(src, length) =>
    alpha = 2.0 / (length + 1)
    sum = 0.0
    sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * sum[1]

// Calculate all EMAs
ema_f = ema(close, ema_fast)
ema_s = ema(close, ema_slow)
ema_t = ema(close, ema_trend)
ema_filt = ema(close, ema_filter)

// RSI with smoothing
rsi_val = ta.rsi(close, rsi_length)
rsi_smooth = ema(rsi_val, 3)

// MACD calculations
[macd_line, signal_line, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_signal)
macd_momentum = macd_line - signal_line

// ATR with smoothing
atr_raw = ta.atr(atr_length)
atr_smooth = ema(atr_raw, 5)

// Bollinger Bands
[bb_upper, bb_basis, bb_lower] = ta.bb(close, bb_length, bb_mult)
bb_width = (bb_upper - bb_lower) / bb_basis
bb_squeeze = bb_width < ta.lowest(bb_width, 20)

// Volume analysis
volume_sma = ta.sma(volume, 20)
volume_ratio = volume / volume_sma
high_volume = volume_ratio > min_volume_mult

// ═══════════════════════════════════════════════════════════════════════════
// MARKET STRUCTURE ANALYSIS
// ═══════════════════════════════════════════════════════════════════════════

// Swing High/Low Detection
swing_length = 10
swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)

// Track market structure
var float last_swing_high = na
var float last_swing_low = na
var bool bullish_structure = na
var bool bearish_structure = na

if not na(swing_high)
    last_swing_high := swing_high
if not na(swing_low)
    last_swing_low := swing_low

// Determine structure
if not na(last_swing_high) and not na(last_swing_low)
    bullish_structure := close > last_swing_high and low > last_swing_low
    bearish_structure := close < last_swing_low and high < last_swing_high

// ═══════════════════════════════════════════════════════════════════════════
// SESSION ANALYSIS
// ═══════════════════════════════════════════════════════════════════════════

in_london = time(timeframe.period, london_session)
in_ny = time(timeframe.period, ny_session)
in_tokyo = time(timeframe.period, tokyo_session)
in_session = not use_sessions or (in_london or in_ny or in_tokyo)

// ═══════════════════════════════════════════════════════════════════════════
// CONFLUENCE SCORING SYSTEM
// ═══════════════════════════════════════════════════════════════════════════

// Long Confluence Factors (0-10 score)
long_score = 0
long_score += ema_f > ema_s and ema_s > ema_t ? 1 : 0  // EMA alignment
long_score += close > ema_filt ? 1 : 0  // Above major EMA
long_score += rsi_smooth > 50 and rsi_smooth < rsi_ob ? 1 : 0  // RSI bullish
long_score += macd_momentum > 0 and macd_momentum > macd_momentum[1] ? 1 : 0  // MACD bullish
long_score += close > bb_basis and not bb_squeeze ? 1 : 0  // BB position
long_score += high_volume ? 1 : 0  // Volume confirmation
long_score += bullish_structure ? 1 : 0  // Market structure
long_score += close > open ? 1 : 0  // Bullish candle
long_score += close > high[1] ? 1 : 0  // Breaking previous high
long_score += in_session ? 1 : 0  // In active session

// Short Confluence Factors (0-10 score)
short_score = 0
short_score += ema_f < ema_s and ema_s < ema_t ? 1 : 0  // EMA alignment
short_score += close < ema_filt ? 1 : 0  // Below major EMA
short_score += rsi_smooth < 50 and rsi_smooth > rsi_os ? 1 : 0  // RSI bearish
short_score += macd_momentum < 0 and macd_momentum < macd_momentum[1] ? 1 : 0  // MACD bearish
short_score += close < bb_basis and not bb_squeeze ? 1 : 0  // BB position
short_score += high_volume ? 1 : 0  // Volume confirmation
short_score += bearish_structure ? 1 : 0  // Market structure
short_score += close < open ? 1 : 0  // Bearish candle
short_score += close < low[1] ? 1 : 0  // Breaking previous low
short_score += in_session ? 1 : 0  // In active session

// ═══════════════════════════════════════════════════════════════════════════
// ENTRY CONDITIONS
// ═══════════════════════════════════════════════════════════════════════════

// Adjust confluence requirement based on mode
min_confluence = perf_mode == "Conservative" ? confluence_required + 1 : perf_mode == "Aggressive" ? confluence_required - 1 : confluence_required

// Entry signals
long_entry = long_score >= min_confluence and strategy.position_size == 0
short_entry = short_score >= min_confluence and strategy.position_size == 0

// ═══════════════════════════════════════════════════════════════════════════
// POSITION MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════

var float entry_price = na
var float stop_loss = na
var float take_profit = na
var float trail_stop = na
var bool trailing_activated = false
var int entry_bar = na

// Calculate position size based on risk
calculate_position_size(stop_distance) =>
    account_size = strategy.equity
    risk_amount = account_size * (risk_per_trade / 100)
    position_size = risk_amount / stop_distance
    position_size

// LONG ENTRY
if long_entry
    stop_distance = atr_smooth * atr_stop_mult
    stop_loss := close - stop_distance
    take_profit := close + (stop_distance * risk_reward)
    
    position_size = calculate_position_size(stop_distance)
    strategy.entry("Long", strategy.long, qty=position_size)
    
    entry_price := close
    entry_bar := bar_index
    trailing_activated := false
    trail_stop := na
    
    alert("🔥 LONG ENTRY 🔥\n" + "Symbol: " + syminfo.ticker + "\n" + "Entry: " + str.tostring(close) + "\n" + "Stop: " + str.tostring(stop_loss) + "\n" + "Target: " + str.tostring(take_profit) + "\n" + "Score: " + str.tostring(long_score) + "/10", alert.freq_once_per_bar_close)

// SHORT ENTRY
if short_entry
    stop_distance = atr_smooth * atr_stop_mult
    stop_loss := close + stop_distance
    take_profit := close - (stop_distance * risk_reward)
    
    position_size = calculate_position_size(stop_distance)
    strategy.entry("Short", strategy.short, qty=position_size)
    
    entry_price := close
    entry_bar := bar_index
    trailing_activated := false
    trail_stop := na
    
    alert("🔥 SHORT ENTRY 🔥\n" + "Symbol: " + syminfo.ticker + "\n" + "Entry: " + str.tostring(close) + "\n" + "Stop: " + str.tostring(stop_loss) + "\n" + "Target: " + str.tostring(take_profit) + "\n" + "Score: " + str.tostring(short_score) + "/10", alert.freq_once_per_bar_close)

// ═══════════════════════════════════════════════════════════════════════════
// EXIT MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════

// Trailing stop logic
if strategy.position_size != 0 and use_trailing
    profit_in_r = strategy.position_size > 0 ? (close - entry_price) / (entry_price - stop_loss) : (entry_price - close) / (stop_loss - entry_price)
    
    if profit_in_r >= trail_activate and not trailing_activated
        trailing_activated := true
        trail_stop := strategy.position_size > 0 ? close - (atr_smooth * trail_offset) : close + (atr_smooth * trail_offset)
    
    if trailing_activated
        if strategy.position_size > 0
            trail_stop := math.max(trail_stop, close - (atr_smooth * trail_offset))
        else
            trail_stop := math.min(trail_stop, close + (atr_smooth * trail_offset))

// Exit conditions
if strategy.position_size > 0
    strategy.exit("Long Exit", "Long", stop=use_trailing and trailing_activated ? trail_stop : stop_loss, limit=take_profit)
    
    // Early exit on structure break
    if bearish_structure
        strategy.close("Long", comment="Structure Break")

if strategy.position_size < 0
    strategy.exit("Short Exit", "Short", stop=use_trailing and trailing_activated ? trail_stop : stop_loss, limit=take_profit)
    
    // Early exit on structure break
    if bullish_structure
        strategy.close("Short", comment="Structure Break")

// ═══════════════════════════════════════════════════════════════════════════
// VISUALIZATION
// ═══════════════════════════════════════════════════════════════════════════

// EMA plots
plot(ema_f, "Fast EMA", color.new(color.green, 0), linewidth=2)
plot(ema_s, "Slow EMA", color.new(color.red, 0), linewidth=2)
plot(ema_t, "Trend EMA", color.new(color.blue, 0), linewidth=2)
plot(ema_filt, "Filter EMA", color.new(color.purple, 0), linewidth=3)

// Entry signals
plotshape(long_entry, "Long Signal", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.normal)
plotshape(short_entry, "Short Signal", shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.normal)

// Position levels
plot(strategy.position_size != 0 ? entry_price : na, "Entry", color.new(color.white, 0), linewidth=2, style=plot.style_linebr)
plot(strategy.position_size != 0 ? stop_loss : na, "Stop Loss", color.new(color.red, 0), linewidth=2, style=plot.style_linebr)
plot(strategy.position_size != 0 ? take_profit : na, "Take Profit", color.new(color.green, 0), linewidth=2, style=plot.style_linebr)
plot(strategy.position_size != 0 and trailing_activated ? trail_stop : na, "Trailing Stop", color.new(color.orange, 0), linewidth=2, style=plot.style_linebr)

// Background color for sessions
bgcolor(in_london ? color.new(color.blue, 95) : na, title="London Session")
bgcolor(in_ny ? color.new(color.green, 95) : na, title="NY Session")
bgcolor(in_tokyo ? color.new(color.red, 95) : na, title="Tokyo Session")

// ═══════════════════════════════════════════════════════════════════════════
// INFORMATION PANEL
// ═══════════════════════════════════════════════════════════════════════════

var table info_panel = table.new(position.top_right, 2, 10, bgcolor=color.new(color.black, 80), border_color=color.white, border_width=1)

if barstate.islast
    // Headers
    table.cell(info_panel, 0, 0, "METRIC", text_color=color.white, bgcolor=color.new(color.blue, 50))
    table.cell(info_panel, 1, 0, "VALUE", text_color=color.white, bgcolor=color.new(color.blue, 50))
    
    // Long Score
    table.cell(info_panel, 0, 1, "Long Score", text_color=color.white)
    table.cell(info_panel, 1, 1, str.tostring(long_score) + "/10", text_color=long_score >= min_confluence ? color.green : color.white)
    
    // Short Score
    table.cell(info_panel, 0, 2, "Short Score", text_color=color.white)
    table.cell(info_panel, 1, 2, str.tostring(short_score) + "/10", text_color=short_score >= min_confluence ? color.red : color.white)
    
    // RSI
    table.cell(info_panel, 0, 3, "RSI", text_color=color.white)
    table.cell(info_panel, 1, 3, str.tostring(math.round(rsi_smooth, 1)), text_color=rsi_smooth > rsi_ob ? color.red : rsi_smooth < rsi_os ? color.green : color.white)
    
    // MACD
    table.cell(info_panel, 0, 4, "MACD", text_color=color.white)
    table.cell(info_panel, 1, 4, macd_momentum > 0 ? "Bullish" : "Bearish", text_color=macd_momentum > 0 ? color.green : color.red)
    
    // Volume
    table.cell(info_panel, 0, 5, "Volume", text_color=color.white)
    table.cell(info_panel, 1, 5, str.tostring(math.round(volume_ratio, 1)) + "x", text_color=high_volume ? color.green : color.white)
    
    // Structure
    table.cell(info_panel, 0, 6, "Structure", text_color=color.white)
    table.cell(info_panel, 1, 6, bullish_structure ? "Bullish" : bearish_structure ? "Bearish" : "Neutral", text_color=bullish_structure ? color.green : bearish_structure ? color.red : color.white)
    
    // Position
    table.cell(info_panel, 0, 7, "Position", text_color=color.white)
    position_text = strategy.position_size > 0 ? "LONG" : strategy.position_size < 0 ? "SHORT" : "NONE"
    table.cell(info_panel, 1, 7, position_text, text_color=strategy.position_size > 0 ? color.green : strategy.position_size < 0 ? color.red : color.white)
    
    // P&L
    if strategy.position_size != 0
        current_pnl = strategy.position_size > 0 ? ((close - entry_price) / entry_price) * 100 : ((entry_price - close) / entry_price) * 100
        table.cell(info_panel, 0, 8, "P&L", text_color=color.white)
        table.cell(info_panel, 1, 8, str.tostring(math.round(current_pnl, 2)) + "%", text_color=current_pnl > 0 ? color.green : color.red)
    
    // Mode
    table.cell(info_panel, 0, 9, "Mode", text_color=color.white)
    table.cell(info_panel, 1, 9, perf_mode, text_color=color.yellow)

// ═══════════════════════════════════════════════════════════════════════════
// ALERTS
// ═══════════════════════════════════════════════════════════════════════════

// Additional alert conditions
alertcondition(long_score >= min_confluence - 1 and long_score < min_confluence, "Long Setup Forming", "Long setup forming - Score: {{plot_0}}/10")
alertcondition(short_score >= min_confluence - 1 and short_score < min_confluence, "Short Setup Forming", "Short setup forming - Score: {{plot_1}}/10")
alertcondition(trailing_activated, "Trailing Stop Activated", "Trailing stop activated")
alertcondition(strategy.position_size != 0 and volume_ratio > 3, "High Volume Alert", "Unusually high volume detected")
相关推荐