The core idea of this strategy is to identify market trend directions by combining Hull moving average and average true range (ATR), and enter positions after the trend direction is confirmed. Specifically, it calculates the difference between the Hull moving averages of a certain period and the previous period. When the difference rises, it indicates a bullish trend; when the difference declines, it indicates a bearish trend. At the same time, the ATR index is used to determine the amplitude. It enters positions when the trend direction is confirmed and the amplitude keeps expanding.
This strategy mainly relies on two types of indicators: Hull moving average and ATR.
The Hull moving average is a trend-following indicator developed by American futures trader Alan Hull. Similar to moving averages, the Hull moving average has higher sensitivity and can capture price changes and trends faster. The strategy sets an adjustable parameter hullLength to control the period of the Hull moving average. By calculating the difference between the current period’s Hull MA and previous period’s, it determines the current price trend direction.
ATR stands for Average True Range. It reflects the amplitude of daily price fluctuations. When volatility increases, ATR rises; when volatility declines, ATR falls. The strategy sets parameters like atrLength and atrSmoothing to control the ATR calculation. And ATR is plotted on the chart as one reference for entries.
Specifically, the strategy logic is:
The advantages of this strategy:
Some risks of this strategy:
Solutions:
There is still large room for optimization:
This strategy integrates the trend following capacity of Hull MA and the heat judgment ability of ATR. It enters positions when trend is confirmed and volatility rises to filter out some invalid signals. Further enhancement can be achieved by parameter optimization and better risk management. In summary, this strategy combines multiple factors of trend tracking and heat judgment. When parameters are fine-tuned, it can deliver good results.
/*backtest start: 2024-01-07 00:00:00 end: 2024-01-14 00:00:00 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=3 // Hull cross and ATR strategy("Hull cross and ATR", shorttitle="H&ATR", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=true, calc_on_every_tick=true, pyramiding=0) keh=input(title="Hull Length",defval=50) length = input(title="ATR Length", defval=50, minval=1) smoothing = input(title="ATR Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"]) p=input(ohlc4,title="Price data") n2ma=2*wma(p,round(keh/2)) nma=wma(p,keh) diff=n2ma-nma sqn=round(sqrt(keh)) n2ma1=2*wma(p[1],round(keh/2)) nma1=wma(p[1],keh) diff1=n2ma1-nma1 sqn1=round(sqrt(keh)) n1=wma(diff,sqn) n2=wma(diff1,sqn) ma_function(source, length) => if smoothing == "RMA" rma(p, length) else if smoothing == "SMA" sma(p, length) else if smoothing == "EMA" ema(p, length) else wma(p, length) plot(ma_function(tr(true), length), title = "ATR", color=black, transp=50) closelong = n1<n2 if (closelong) strategy.close("buy") closeshort = n1>n2 if (closeshort) strategy.close("sell") if (ma_function(tr(true), length)<p and p>p[length] and n1>n2) strategy.entry("buy", strategy.long, comment="BUY") if (ma_function(tr(true), length)>p and p<p[length] and n1<n2) strategy.entry("sell", strategy.short, comment="SELL")