该策略是一个基于平滑烛线(Heikin-Ashi)与指数移动平均线(EMA)交叉的多重时间周期趋势跟踪系统。通过在不同时间周期上结合Heikin-Ashi烛线的平滑特性和移动平均线的趋势跟踪能力,同时配合MACD指标作为过滤器,实现对市场趋势的准确捕捉。策略采用了时间周期分层设计,分别在60分钟、180分钟和15分钟三个时间周期上进行信号计算和验证。
策略的核心逻辑包括以下几个关键部分: 1. Heikin-Ashi烛线计算:通过特殊的开高低收价格计算方法,平滑原始价格数据,减少市场噪音。 2. 多重时间周期EMA系统:在180分钟周期计算Heikin-Ashi EMA,与60分钟周期的慢速EMA形成交叉信号系统。 3. MACD过滤器:在15分钟周期上计算MACD指标,用于验证交易信号的有效性。 4. 信号生成规则:当快速Heikin-Ashi EMA向上穿越慢速EMA,且MACD指标确认(如果启用)时,产生做多信号;反之产生做空信号。
该策略通过多重时间周期的Heikin-Ashi和EMA系统,结合MACD过滤器,构建了一个完整的趋势跟踪交易系统。策略设计充分考虑了信号的可靠性和系统的稳定性,通过参数优化和风险控制机制的完善,能够适应不同的市场环境。策略的核心优势在于信号的平滑性和多重验证机制,但同时也需要注意震荡市场风险和参数优化问题。
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradingbauhaus
//@version=5
strategy("Heikin Ashi Candle Time Frame @tradingbauhaus", shorttitle="Heikin Ashi Candle Time Frame @tradingbauhaus", overlay=true)
// Inputs
res = input.timeframe(title="Heikin Ashi Candle Time Frame", defval="60")
hshift = input.int(1, title="Heikin Ashi Candle Time Frame Shift")
res1 = input.timeframe(title="Heikin Ashi EMA Time Frame", defval="180")
mhshift = input.int(0, title="Heikin Ashi EMA Time Frame Shift")
fama = input.int(1, title="Heikin Ashi EMA Period")
test = input.int(1, title="Heikin Ashi EMA Shift")
sloma = input.int(30, title="Slow EMA Period")
slomas = input.int(1, title="Slow EMA Shift")
macdf = input.bool(false, title="With MACD filter")
res2 = input.timeframe(title="MACD Time Frame", defval="15")
macds = input.int(1, title="MACD Shift")
// Heikin Ashi calculation
var float ha_open = na
ha_close = (open + high + low + close) / 4
ha_open := na(ha_open[1]) ? (open + close) / 2 : (ha_open[1] + ha_close[1]) / 2
ha_high = math.max(high, math.max(ha_open, ha_close))
ha_low = math.min(low, math.min(ha_open, ha_close))
// Adjusted Heikin Ashi Close for different timeframes
mha_close = request.security(syminfo.tickerid, res1, ha_close[mhshift])
// MACD calculation
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdl = request.security(syminfo.tickerid, res2, macdLine[macds])
macdsl = request.security(syminfo.tickerid, res2, signalLine[macds])
// Moving Averages
fma = ta.ema(mha_close[test], fama)
sma = ta.ema(ha_close[slomas], sloma)
plot(fma, title="Heikin Ashi EMA", color=color.green, linewidth=2)
plot(sma, title="Slow EMA", color=color.red, linewidth=2)
// Strategy Logic
golong = ta.crossover(fma, sma) and (macdl > macdsl or not macdf)
goshort = ta.crossunder(fma, sma) and (macdl < macdsl or not macdf)
// Plot Shapes for Buy/Sell Signals
plotshape(golong, color=color.green, text="Buy", style=shape.triangleup, location=location.belowbar)
plotshape(goshort, color=color.red, text="SELL", style=shape.triangledown, location=location.abovebar)
// Strategy Orders
strategy.entry("Long", strategy.long, when=golong)
strategy.close("Long", when=goshort)
strategy.entry("Short", strategy.short, when=goshort)
strategy.close("Short", when=golong)
// Alerts
alertcondition(golong, "Heikin Ashi BUY", "")
alertcondition(goshort, "Heikin Ashi SELL", "")