本期分享MACD+MA指标组合策略,在技术分析中,指标的组合使用是非常常见的,不同的指标组合在一起具有不同的操作要点和分析方法,指标的组合使用可以增强信号的准确性。该策略正是通过比较价格与MA的相互关系,再以MACD指标衡量价格运动加速度,来判断市场所处的状态,构建一种简单的择时交易策略。
(*backtest start: 2018-11-01 00:00:00 end: 2018-11-22 00:00:00 period: 1h exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}] *) // MACD calculation FASTLENGTH:=12; SLOWLENGTH:=26; MACDLENGTH:=9; // Length of MA L1:=50; L2:=120; // stop loss 止损 5% STOPLOSS:=5; //MACD MACDVALUE:=EMA(CLOSE,FASTLENGTH)-EMA(CLOSE,SLOWLENGTH); AVGMACD:=EMA(MACDVALUE,MACDLENGTH); MACDDIFF:=MACDVALUE-AVGMACD; //MA1、MA2 DMA1:=MA(C,L1); DMA2:=MA(C,L2); BUYCONDITION:=MACDVALUE>0 && DMA1>DMA2 && MACDDIFF>0 && C>DMA1 && REF(C,1)>REF(DMA1,1); SELLCONDITION:=MACDVALUE<0 && DMA1<DMA2 && MACDDIFF<0 && C<DMA1 && REF(C,1)<REF(DMA1,1); // 开仓条件 When to open position BKVOL=0 AND BUYCONDITION,BK; SETSIGPRICETYPE(BK,NEW_ORDER); SKVOL=0 AND SELLCONDITION,SK; SETSIGPRICETYPE(SK,NEW_ORDER); // 离场条件 When to close position BKVOL>0 AND (REF(MACDVALUE,1)<0 OR REF(DMA1,1)<REF(DMA2,1)),SP; SKVOL>0 AND (REF(MACDVALUE,1)>0 OR REF(DMA1,1)>REF(DMA2,1)),BP; // 启动止损 Start stop loss SKVOL>0 AND HIGH>=SKPRICE*(1+STOPLOSS*0.01),BP; BKVOL>0 AND LOW<=BKPRICE*(1-STOPLOSS*0.01),SP; AUTOFILTER;