平衡木交易法:当蜡烛遇上云图的完美舞蹈

HEIKEN ASHI ICHIMOKU EMA ATR
创建日期: 2025-10-20 13:19:44 最后修改: 2025-10-20 13:19:44
复制: 0 点击次数: 136
avatar of ianzeng123 ianzeng123
2
关注
329
关注者

平衡木交易法:当蜡烛遇上云图的完美舞蹈 平衡木交易法:当蜡烛遇上云图的完美舞蹈

🎯 这个策略到底在玩什么?

你知道吗?这个策略就像是让蜡烛图在平衡木上跳舞!它把普通的K线图变成了更平滑的Heiken Ashi蜡烛,再配合Ichimoku云图的基准线,简直就是技术分析界的”双人花样滑冰”。划重点!这不是什么复杂的火箭科学,而是把市场噪音过滤掉,让你看清真正的趋势方向。

🔍 核心逻辑:三重过滤的智慧

这个策略的精髓在于”三重过滤系统”,就像你挑选心仪对象一样严格!首先,Heiken Ashi蜡烛必须站在Ichimoku基准线的正确一侧(这是基本门槛);其次,200周期EMA确保你跟着大趋势走(不要逆流而上);最后,Ichimoku背离过滤器确保动量方向正确(避免假突破的坑)。

这就像开车一样:绿灯亮了(HA信号),路况良好(趋势过滤),而且前方没有逆行车辆(背离确认)。三个条件同时满足,才会发出交易信号!

💡 风险管理:ATR动态止盈止损

避坑指南来了!这个策略最聪明的地方是使用ATR(平均真实波幅)来设置止盈止损。它会根据市场波动性自动调整,就像汽车的自适应巡航系统一样。市场波动大的时候,止损距离自动放宽;波动小的时候,止损收紧。

更厉害的是,它还使用了多时间框架:高时间框架的ATR用于止盈(让利润充分奔跑),低时间框架的ATR用于止损(快速止损保护资金)。这种设计真的是太贴心了!

🚀 实战应用:什么时候最好用?

这个策略特别适合趋势明显的市场环境。当市场在横盘震荡时,建议暂时观望,因为Heiken Ashi在震荡市中容易产生假信号。最佳使用场景是:主要货币对的4小时或周期图表,特别是在重要经济数据发布后的趋势确认阶段。

记住,任何策略都不是万能的!这个策略的强项是捕捉中长期趋势,如果你是喜欢快进快出的短线交易者,可能需要调整参数或者寻找其他策略。

策略源码
/*backtest
start: 2024-10-20 00:00:00
end: 2025-10-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":500000}]
*/

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MahdiSalari8
//@version=6
strategy("Heiken Ashi Bas", overlay=true, 
     default_qty_type=strategy.fixed, 
     default_qty_value=0.1, 
     commission_type=strategy.commission.percent, 
     commission_value=0.07,
     initial_capital=10000000,
     pyramiding=0)  // Changed to 0

// Inputs
useTrendFilter = input.bool(true, "Use 200 EMA Trend Filter", group="Filters")
showSignals = input.bool(true, "Show Buy/Sell Signals", group="Visuals")
showEma = input.bool(false, "Show 200 EMA", group="Visuals")
atrPeriod = input.int(14, "ATR Period", minval=1, group="Risk Management")
htf = input.timeframe("5", "Higher Timeframe for TP", group="Timeframes")
ltf = input.timeframe("1", "Lower Timeframe for SL", group="Timeframes")
tpMultiplier = input.float(2.0, "TP Multiplier", minval=0.1, group="Risk Management")
slMultiplier = input.float(1.0, "SL Multiplier", minval=0.1, group="Risk Management")

// Ichimoku Divergence Settings
useDivergenceFilter = input.bool(true, "Use Ichimoku Divergence Filter", group="Ichimoku Divergence")
showDivergenceLine = input.bool(true, "Show Divergence Line", group="Ichimoku Divergence")
divergenceLookback = input.int(2, "Divergence Lookback (bars)", minval=1, maxval=20, group="Ichimoku Divergence")
divergenceLineWidth = input.int(5, "Divergence Line Width", minval=1, maxval=5, group="Ichimoku Divergence")

// Heiken Ashi Calculation
var float haOpen = na
var float haClose = na
var float haHigh = na
var float haLow = na

haClose := (open + high + low + close) / 4
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh := math.max(high, math.max(haOpen, haClose))
haLow := math.min(low, math.min(haOpen, haClose))

// Ichimoku Baseline (Kijun-sen)
kijunPeriod = 26
kijunSen = (ta.highest(high, kijunPeriod) + ta.lowest(low, kijunPeriod)) / 2

// Ichimoku Baseline Divergence Calculation
currentBaseline = kijunSen
pastBaseline = kijunSen[divergenceLookback]

// Calculate slope (divergence)
baselineSlope = (currentBaseline - pastBaseline) / divergenceLookback

// Determine bullish/bearish divergence (exclude when slope is 0)
bullishDivergence = baselineSlope > 0
bearishDivergence = baselineSlope < 0
slopeIsZero = baselineSlope == 0

// Trend Filter (200 EMA)
ema200 = ta.ema(close, 200)

// ATR Calculation for different timeframes
htfAtr = request.security(syminfo.tickerid, htf, ta.atr(atrPeriod))
ltfAtr = request.security(syminfo.tickerid, ltf, ta.atr(atrPeriod))

// Enhanced Entry Conditions with Divergence Filter (exclude when slope is 0)
longCondition = haClose > kijunSen and 
              haClose[1] >= kijunSen[1] and 
              haClose > haOpen and 
              (haHigh - haClose) >= (haClose - haOpen) * 0.3 and 
              (not useTrendFilter or close > ema200) and
              (not useDivergenceFilter or (bullishDivergence and not slopeIsZero))

shortCondition = haClose < kijunSen and 
               haClose[1] <= kijunSen[1] and 
               haClose < haOpen and 
               (haClose - haLow) >= (haOpen - haClose) * 0.3 and 
               (not useTrendFilter or close < ema200) and
              (not useDivergenceFilter or (bearishDivergence and not slopeIsZero))

// Dynamic TP/SL based on ATR
longTp = close + (htfAtr * tpMultiplier)
longSl = close - (ltfAtr * slMultiplier)
shortTp = close - (htfAtr * tpMultiplier)
shortSl = close + (ltfAtr * slMultiplier)

// Strategy Execution
if (longCondition)
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", limit=longTp, stop=longSl)

if (shortCondition)
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short", limit=shortTp, stop=shortSl)

// Plotting
plot(kijunSen, color=color.blue, title="Ichimoku Baseline", linewidth=2, display=display.all)

// Plot Divergence Line (gray when slope is 0)

plot(showEma ? ema200 : na, color=color.purple, title="200 EMA", linewidth=1, display=display.all)

// Heiken Ashi Candles with 25% opacity
candleColor = haClose > haOpen ? color.new(color.green, 75) : color.new(color.red, 75)
plotcandle(haOpen, haHigh, haLow, haClose, title="Heiken Ashi", color=candleColor, wickcolor=candleColor, bordercolor=candleColor, display=display.all)

// Plot Buy/Sell Signals with labelup/labeldown shapes
plotshape(showSignals and longCondition, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.small, title="Buy Signal", display=display.all)
plotshape(showSignals and shortCondition, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.small, title="Sell Signal", display=display.all)

// Plot TP/SL levels - TP as lines with breaks, SL hidden by default
plot(strategy.position_size > 0 ? longTp : na, "Long TP", color=color.green, style=plot.style_linebr, linewidth=1, display=display.all)
plot(strategy.position_size > 0 ? longSl : na, "Long SL", color=color.red, style=plot.style_linebr, linewidth=1, display=display.none)
plot(strategy.position_size < 0 ? shortTp : na, "Short TP", color=color.green, style=plot.style_linebr, linewidth=1, display=display.all)
plot(strategy.position_size < 0 ? shortSl : na, "Short SL", color=color.red, style=plot.style_linebr, linewidth=1, display=display.none)

// Alerts
alertcondition(longCondition, "Long Signal", "HA Cross Above Kijun-sen with Bullish Divergence")
alertcondition(shortCondition, "Short Signal", "HA Cross Below Kijun-sen with Bearish Divergence")
相关推荐