Strategy vault / Trend following
Trend Strategy Based on HULL SMA and EMA Crossover
This strategy generates buy and sell signals by calculating the crossover between the HULL Smoothed Moving Average line and the Exponential Moving Average line to determine market trend direction. It belongs to the…

Overview
This strategy generates buy and sell signals by calculating the crossover between the HULL Smoothed Moving Average line and the Exponential Moving Average line to determine market trend direction. It belongs to the category of medium-term trend-following strategies.
Strategy Logic
Calculate the 5-period HULL Smoothed Moving Average (HULL SMA). HULL SMA responds faster to price changes by using weighted moving averages and the square root of the period.
Calculate the 5-period Exponential Moving Average (EMA). EMA gives more weight to recent prices and is more sensitive than SMA in tracking the trend.
Generate buy and sell signals based on the crossover between HULL SMA and EMA.
When HULL SMA crosses above EMA, a buy signal is generated, indicating the short-term trend breaks out above the long-term trend, suggesting an upward price movement.
When HULL SMA crosses below EMA, a sell signal is generated, indicating the short-term trend turning down, suggesting a downward price movement.
- Use HULL SMA as the fast line and EMA as the slow line to determine changes in short-term and medium-term trends based on the crossover, generating trading signals.
Advantage Analysis
HULL SMA is sensitive to price changes and can detect trend changes earlier.
EMA smoothes market noise and tracks long-term trends.
Crossover signals catch trend turning points in a timely manner.
Parameters can be adjusted for different trading timeframes.
Captures upside and downside trends flexibly.
Risk Analysis
More false signals may occur during range-bound markets.
Unable to determine trend strength, may lead to repeated losses in weak trends.
Price movements between the averaging intervals may be missed.
Improper parameter settings affect signal quality.
High trading frequency increases costs and slippage risks.
Improvements can be made via signal filtering, evaluating trend strength, parameter optimization, risk management, etc.
Optimization Directions
Add indicators like MACD, RSI for signal confirmation.
Incorporate trend strength indicators like ADX to avoid trading weak trends.
Optimize moving average parameters for best combinations.
Implement stop loss to control single trade loss.
Manage trade frequency and costs.
Incorporate multi-timeframe analysis to identify cross-cycle trends.
Develop auto parameter optimization programs.
Summary
This strategy judges the trend based on the crossover between the fast HULL SMA and slow EMA. It is a typical moving average crossover system. Compared to traditional moving averages, the more responsive HULL SMA provides earlier trend change detection. But parameters and supplemental indicators should be optimized to reduce false signals. With proper risk and money management, this strategy can be an efficient medium-term trend following system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 5 | Hull EMA Value |
| v_input_1 | 5 | EMA Value |
Source Pine Script
/*backtest
start: 2022-10-23 00:00:00
end: 2023-10-29 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("HULL EMA Crossover", overlay = true, process_orders_on_close = true)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spiritedPerson95700
inSession = true
HULL_INP = input.int(5, "Hull EMA Value")
EMA_INP = input(5, "EMA Value")
/// Indicator
HULL_EMA = ta.hma(close, HULL_INP)
EMA = ta.ema(close, EMA_INP)
prevSignal = ''
if (prevSignal == '')
prevSignal := HULL_EMA > EMA ? 'buy' : 'sell'
/// buy and sell signal
buy = ta.crossover(HULL_EMA, EMA)
short = ta.crossover(EMA, HULL_EMA)
sell = short
cover = buy
if inSession
if buy
prevSignal := 'na'
strategy.entry("long", direction = strategy.long, comment = "Buy")
if sell
prevSignal := 'na'
strategy.close("long", comment = "Sell")
if short
strategy.entry("short", direction = strategy.short, comment = "Short")
if cover
strategy.close("short", comment = "Cover")
plot(HULL_EMA, color = color.green)
plot(EMA, color = color.blue)
// if ( hour(time) == 15 and minute(time) > 25 )
// strategy.close("long", comment="EOD")
// strategy.close("short", comment="EOD")
// buy := false
// sell := false
// prevSignal := ''
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-30. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Trend-Strategy-Based-on-HULL-SMA-and-EMA-Crossover.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- Multi Timeframe Volume and Trend Confluence Trading StrategyPine Script · Trend following · 1d
- Multi timeframe Trend Tracking Strategy Based on Impulse MACD and Dual Moving Average CrossoverPine Script · Trend following · 1d
- WaveTrend and DER Based Swing Trading StrategyPine Script · Trend following · 1d
- RSI MA Crossover Swing Trading Strategy with Trailing Stop SystemPine Script · Trend following · 4h
- Trend Following Strategy Based on Moving Average Crossover 430022Pine Script · Trend following · 1d