本策略是一个基于平滑型Heikin-Ashi蜡烛图和简单移动平均线(SMA)交叉的趋势跟踪系统。策略通过EMA平滑处理后的Heikin-Ashi蜡烛图与44周期SMA的交叉来识别趋势的变化,从而捕捉市场的主要趋势性机会。策略设计了动态的仓位管理机制,当价格与长期均线距离过近时会自动平仓,以规避盘整市场的震荡风险。
策略的核心逻辑包含三个关键要素:首先是将传统K线转换为Heikin-Ashi蜡烛图,通过计算开高低收四个价格的算术平均值来过滤市场噪音;其次使用6周期EMA对Heikin-Ashi进行平滑处理,进一步提升信号的可靠性;最后将平滑后的Heikin-Ashi收盘价与44周期SMA结合,通过上穿产生做多信号,下穿产生做空信号。同时引入了”无仓位阈值”的概念,当价格与长期均线距离小于阈值时触发平仓信号,有效避免横盘整理行情带来的频繁交易。
该策略通过结合Heikin-Ashi蜡烛图和SMA均线系统,构建了一个稳健的趋势跟踪交易系统。策略的信号生成机制完善,风险控制合理,特别适合在具有明显趋势特征的市场中应用。通过建议的优化方向,策略的实战效果还可以进一步提升。总体而言,这是一个设计合理、逻辑清晰的趋势跟踪策略。
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Smoothed Heikin Ashi with SMA Strategy", overlay=true)
// Input parameters for SMAs
s1 = input.int(11, title="Short SMA Period")
s2 = input.int(44, title="Long SMA Period")
noPositionThreshold = input.float(0.001, title="No Position Threshold", step=0.0001)
// Calculate the original Heikin-Ashi values
haClose = (open + high + low + close) / 4
var float haOpen = na
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))
// Smoothing using exponential moving averages
smoothLength = input.int(6, title="Smoothing Length")
smoothedHaClose = ta.ema(haClose, smoothLength)
smoothedHaOpen = ta.ema(haOpen, smoothLength)
smoothedHaHigh = ta.ema(haHigh, smoothLength)
smoothedHaLow = ta.ema(haLow, smoothLength)
// Calculate SMAs
smaShort = ta.sma(close, s1)
smaLong = ta.sma(close, s2)
// Plotting the smoothed Heikin-Ashi values
plotcandle(smoothedHaOpen, smoothedHaHigh, smoothedHaLow, smoothedHaClose, color=(smoothedHaClose >= smoothedHaOpen ? color.green : color.red), title="Smoothed Heikin Ashi")
plot(smaShort, color=color.blue, title="SMA Short")
plot(smaLong, color=color.red, title="SMA Long")
// Generate buy/sell signals based on SHA crossing 44 SMA
longCondition = ta.crossover(smoothedHaClose, smaLong)
shortCondition = ta.crossunder(smoothedHaClose, smaLong)
noPositionCondition = math.abs(smoothedHaClose - smaLong) < noPositionThreshold
// Strategy logic
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (noPositionCondition and strategy.position_size != 0)
strategy.close_all("No Position")
// Plot buy/sell signals
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", size=size.small)
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", size=size.small)
plotshape(series=noPositionCondition and strategy.position_size != 0, location=location.belowbar, color=color.yellow, style=shape.labeldown, text="EXIT", size=size.small)