神圣十字策略(Holy Grail Strategy)是一个结合双均线系统和ADX指标的量化交易策略。它旨在识别趋势的方向和力度,并在趋势发生转折时进行交易。
该策略同时使用20日指数移动平均线(EMA)和ADX指标来识别入场时机。具体来说,它会在以下两种情况下发出交易信号:
当ADX值低于30时(表示趋势较弱),并且价格从下方突破20日EMA时,做多;
当ADX值高于30时(表示趋势较强),并且价格从上方突破20日EMA时,做空。
可以看出,该策略依赖ADX判断趋势的力度和方向,再结合移动平均线的支持阻力来寻找反转机会。它融合了趋势跟随和逆势交易的理念。
神圣十字策略最大的优势在于,它同时考量了趋势的方向和力度,可以有效避开假突破,从而减少止损的概率。具体来说,该策略有以下几个优势:
神圣十字策略也存在一些风险,主要集中在以下几个方面:
为降低上述风险,可以调整参数组合以达到最佳效果,也可以设置止损来控制单笔损失。此外,让策略在不同品种和周期上进行回测,也很有必要。
神圣十字策略还有许多优化的方向:
调整参数或加入新指标都有可能提高策略的盈利率或胜率。但任何优化都需要足够的回测以确保其稳健性。
总的来说,神圣十字策略结合双均线和ADX指标的优点,使用清晰的交易规则来捕捉趋势转折。它有望取得不错的效果。但交易者仍需要对参数组合和止损规则进行优化,从而适应不同的市场环境。此外,无论如何改进,也无法完全避免止损,这是每一个交易策略都会面临的困境。
/*backtest
start: 2022-11-24 00:00:00
end: 2023-11-30 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("LAT Holy Grail v3", overlay=true)
/////////////TEST TIME ////////////////////////
testStartYear = input(2018, "Backtest Start Year")
testStartMonth = input(4, "Backtest Start Month")
testStartDay = input(15, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(5, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false
//////////////////////////////////////////////////////////////////////
myema= ema(close, 20)
plot(myema, color=green, title="eMA", linewidth=3)
//longCondition = (crossover(close, myema)) //and adx3 < target
//if (longCondition)
//strategy.entry("My Long Entry Id", strategy.long)
//shortCondition = (crossunder(close, myema)) //and adx3 > target
//if (shortCondition)
//strategy.entry("My Short Entry Id", strategy.short)
//////////////////////////////////////////////////////////
/////////////////////////////////////// DMI ///////////////////////////////////////////////
len3 = input(14, minval=1, title="DI Length") /////////////////////
lensig3 = input(14, title="ADX Smoothing", minval=1, maxval=50) ////////////////////
up3 = change(high) ///////////////////
down3 = -change(low) //////////////////
plusDM3 = na(up3) ? na : (up3 > down3 and up3 > 0 ? up3 : 0) /////////////////
minusDM3 = na(down3) ? na : (down3 > up3 and down3 > 0 ? down3 : 0) ////////////////
trur3 = rma(tr, len3) ///////////////
plus3 = fixnan(100 * rma(plusDM3, len3) / trur3) //////////////
minus3 = fixnan(100 * rma(minusDM3, len3) / trur3) /////////////
sum3 = plus3 + minus3 ////////////
adx3 = 100 * rma(abs(plus3 - minus3) / (sum3 == 0 ? 1 : sum3), lensig3) ///////////
//plot(plus3, color=green, style=circles, linewidth=2, title="+DI") //////////
//plot(minus3, color=red, style=circles, linewidth=2, title="-DI") /////////
plot(adx3, color=aqua, style=line, linewidth=3, title="ADX") ////////
target = input(30, title=" ADX Target Line") ///////
plot(target, color=yellow, title="ADX Target Line") //////
/////////////////////////////////////////////////////////////////////////////////////////////////
plot(hl2)
/////////////////////////////////////////////// eMA SIGNAL LINE ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// HOLY GRAIL STRATEGY ///////////////////////////////////////////////////////////////////
if (adx3 <= target) and crossover(close, myema)
strategy.entry("HolyGrail", strategy.long, comment="Long")
if (adx3 >= target) and crossunder(close, myema)
strategy.entry("HolyGrail", strategy.short, comment="Short")