该策略基于增强型MACD指标进行趋势追踪。它同时计算快速移动平均线、慢速移动平均线以及二者的差值,并再对差值进行移动平均来产生交易信号。
具体逻辑是:
计算快速EMA周期,如12日
计算慢速EMA周期,如26日
计算快慢EMA的差值为MACD
对MACD进行信号线EMA,如9日EMA
再对MACD与信号线的差值进行EMA生成增强信号线
当增强信号线上穿零轴时做多
当增强信号线下穿零轴时平多仓
该策略充分发掘MACD指标的趋势跟踪特性,并进行二次优化滤波从而提高信号质量,追捧中长线趋势。
增强MACD降噪提高信号准确度
快慢EMA配合判断方向和力度
较慢参数侧重中长线趋势
需谨慎选择EMA周期参数
仅做多无法利用空头机会
信号出现频率偏少
该策略通过增强MACD的趋势跟踪能力来识别中长线机会。但参数优化和风险控制尤为重要。适当组合其他因素能提高效果。
/*backtest
start: 2022-09-07 00:00:00
end: 2023-09-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//study("MACDAS")
// strategy("macdas",shorttitle="macdas",overlay=true,default_qty_value=10000,initial_capital=10000,currency=currency.USD)
// Date range filter
testStartYear = input(2018, "Backtest Start Year")
testStartMonth = input(4, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)
testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
inTimeRange = true
fastperiod = input(12,title="fastperiod",minval=1,maxval=500)
slowperiod = input(26,title="slowperiod",minval=1,maxval=500)
signalperiod = input(9,title="signalperiod",minval=1,maxval=500)
fastMA = ema(close, fastperiod)
slowMA = ema(close, slowperiod)
macd = fastMA - slowMA
signal = ema(macd, signalperiod)
macdAS = macd - signal
signalAS = ema(macdAS, signalperiod)
plot(macdAS, color=blue, linewidth=2)
plot(signalAS, color=red, linewidth=2)
plot(0, color=black)
strategy.entry("LONG", strategy.long, when =inTimeRange and crossover(macdAS,signalAS))
strategy.close("LONG", when= inTimeRange and crossunder(macdAS,signalAS))
plotshape(crossover(macdAS, signalAS) , style = shape.arrowup, text="Long",color=green,size=size.huge)
plotshape(crossover(signalAS,macdAS) , style = shape.arrowdown, text="End Long",color=red,size=size.huge)