本策略结合使用动量指标和双向追踪指标,在强势趋势中捕捉突破信号,实现趋势跟踪。当价格向上突破时做多,当价格向下突破时做空,属于趋势追踪类策略。
使用HiLo激活器指标计算中期价,该指标将最高价和最低价的中点作为中期价。当价格上涨突破中期价时产生买入信号,当价格下跌突破中期价时产生卖出信号。
平均趋向指数ADX用于判断趋势力度。ADX数值越大,表示趋势越强。本策略配合使用一定阈值的ADX来过滤信号,只在趋势足够强劲时才产生信号。
多向导指标DI+和DI-分别表示多头力度和空头力度。本策略同时配合一定阈值的DI+和DI-来确认多头和空头的力度,防止错误信号。
当价格向上突破中期价、ADX高于阈值、DI+高于阈值时产生买入信号;当价格向下突破中期价、ADX高于阈值、DI-高于阈值时产生卖出信号。
本策略结合动量指标和趋势指标的优点,能够在趋势发展早期捕捉到价格的突破,从而紧贴趋势运行。同时,趋势过滤条件严格,有助于避免 consolidation 市和震荡市的错误信号。
相比单一使用动量指标,本策略在产生信号时加入对趋势力度的判断,可以减少错误信号,提高获利概率。相比单一使用趋势跟踪指标,本策略通过突破产生信号,可以更早进入趋势。
总体来说,策略可以顺利跟踪趋势,及时进入和退出,避免泥淖;同时也可以减少趋势反转的损失。
本策略存在一定的whipsaw风险,即价格可能出现一定程度的回调从而产生反向信号。此外,使用ADX和DI设置过滤条件可能会错过部分运行初期的机会。
为降低whipsaw风险,可以适当调整HiLo激活器的参数,增大突破幅度。为获取更多机会,可以降低ADX和DI的阈值要求,但需要权衡信号质量。
此外,用户需要关注不同品种和市场环境下参数设置的差异。一般来说,大宗商品需要设置更高阈值;股票和外汇则可以使用较低阈值。
本策略可以通过调整参数设置进行优化,主要优化方向包括:
调整HiLo激活器周期和触发幅度,平衡whipsaw风险和进入时机。
调整ADX周期和阈值要求,平衡信号质量和进入频次。
分别调整多头和空头DI的阈值,区分多头和空头环境差异。
添加止损策略,设置止损点以控制单笔损失。
结合其他辅助指标进行优化,提高策略整体稳定性。
本策略综合考虑动量指标和趋势指标,在强势趋势中产生买入和卖出信号。它具有顺势而为、紧贴趋势的特点,适合捕捉趋势早期机会。同时,它也具备一定的风险控制能力,可以减少错误信号和 whipsaw 带来的损失。通过参数调整和止损策略的添加,本策略可以获得持续稳定的表现。它是一种多功能的趋势跟踪策略,适合不同品种和市场环境,值得量化交易者重点研究和应用。
/*backtest
start: 2022-12-11 00:00:00
end: 2023-12-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("HiLo Activator with ADX", shorttitle="HASB_ADX", overlay=true)
// Parameters for the HiLo Activator
length_ha = input(14, title="HiLo Activator Period")
offset_ha = input(0, title="Offset")
trigger_ha = input(1, title="Trigger for Buy/Sell")
// Parameters for ADX
adx_length = input(14, title="ADX Period", minval=1)
adx_threshold = input(25, title="ADX Threshold")
di_threshold = input(50, title="DI Threshold")
// Parameter for choosing the number of candles for backtest
backtest_candles = input(1000, title="Number of Candles for Backtest", minval=1)
// Function to get backtest data
getBacktestData() =>
var float data = na
if bar_index >= backtest_candles
data := security(syminfo.tickerid, "D", close[backtest_candles])
data
// HiLo Activator calculations
ha = (highest(high, length_ha) + lowest(low, length_ha)) / 2
// ADX calculations
trh = high - high[1]
trl = low[1] - low
tr = max(trh, trl)
atr = sma(tr, adx_length)
plus_dm = high - high[1] > low[1] - low ? max(high - high[1], 0) : 0
minus_dm = low[1] - low > high - high[1] ? max(low[1] - low, 0) : 0
smoothed_plus_dm = sma(plus_dm, adx_length)
smoothed_minus_dm = sma(minus_dm, adx_length)
di_plus = 100 * (smoothed_plus_dm / atr)
di_minus = 100 * (smoothed_minus_dm / atr)
dx = 100 * abs(di_plus - di_minus) / (di_plus + di_minus)
adx = sma(dx, adx_length)
// Buy and Sell signals based on HiLo Activator and ADX
signalLong = crossover(close, ha) and adx > adx_threshold and di_plus > di_threshold
signalShort = crossunder(close, ha) and adx > adx_threshold and di_minus > di_threshold
// Plot HiLo Activator and ADX
plot(ha, color=color.blue, title="HiLo Activator")
plot(offset_ha, color=color.red, style=plot.style_histogram, title="Offset")
plot(adx, color=color.purple, title="ADX")
// Backtest strategy
strategy.entry("Buy", strategy.long, when = signalLong)
strategy.entry("Sell", strategy.short, when = signalShort)
strategy.close("Buy", when = signalShort)
strategy.close("Sell", when = signalLong)
// Accuracy percentage
var accuracy = 0.0
var totalTrades = 0
var winningTrades = 0
if (signalLong or signalShort)
totalTrades := totalTrades + 1
if (signalLong and (not na(signalLong[1]) and (not signalLong[1])))
winningTrades := winningTrades + 1
if (signalShort and (not na(signalShort[1]) and (not signalShort[1])))
winningTrades := winningTrades + 1
accuracy := totalTrades > 0 ? (winningTrades / totalTrades) * 100 : 0
// Plot accuracy percentage on the chart
plot(accuracy, title="Accuracy Percentage", color=color.purple, style=plot.style_histogram)