This strategy is a trend following system based on smoothed Heikin-Ashi candlesticks and Simple Moving Average (SMA) crossovers. It identifies trend changes through the intersection of EMA-smoothed Heikin-Ashi candlesticks with a 44-period SMA to capture major trend opportunities in the market. The strategy incorporates a dynamic position management mechanism that automatically closes positions when prices are too close to the long-term moving average, avoiding oscillation risks in consolidating markets.
The core logic consists of three key elements: First, converting traditional candlesticks into Heikin-Ashi candlesticks by calculating the arithmetic mean of open, high, low, and close prices to filter market noise; Second, using a 6-period EMA to smooth the Heikin-Ashi, further enhancing signal reliability; Finally, combining the smoothed Heikin-Ashi closing price with a 44-period SMA, generating long signals on upward crosses and short signals on downward crosses. The concept of a “no position threshold” is introduced, triggering position closure when the price-to-long-term-average distance is below the threshold, effectively avoiding frequent trades during consolidation phases.
The strategy constructs a robust trend following trading system by combining Heikin-Ashi candlesticks with SMA systems. It features comprehensive signal generation mechanisms and reasonable risk control, particularly suitable for markets with distinct trend characteristics. The strategy’s practical effectiveness can be further enhanced through the suggested optimization directions. Overall, it represents a well-designed trend following strategy with clear logic.
/*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)