全品种短线商品期货通用交易策略
一、双均线DDI策略交易思路

          1、定义两均线,用于判断K线走势趋势

              VAR2:=MA(CLOSE,N1);

              VAR3:=MA(VAR2,N2);

              VAR9:=MA(VAR8,2*N1);
              VAR10:=MA(VAR9,N1);

          2、定义DDI指标,用于判断进仓时机

              VAR8:VAR6-VAR7;

          3、设置默认为3%的止盈止损比例,稳定盈利和及时止损。

       二、金字塔策略源码

        //该策略适用图表程序化交易

        //该策略适用日线周期、分钟周期

         INPUT:N1(30,1,1000,1),N2(150,1,1000,1),N3(1,1,100,1),SS(1,1,100,1);

         //中间变量

         VAR2:=MA(C,N2);
         VAR3:=MA(VAR2,N1);
         VAR4:=IF((H+L)<=(REF(H,1)+REF(L,1)),0,MAX(ABS(H-REF(H,1)),ABS(L-REF(L,1))));
         VAR5:=IF((H+L)>=(REF(H,1)+REF(L,1)),0,MAX(ABS(H-REF(H,1)),ABS(L-REF(L,1))));
         VAR6:=SUM(VAR4,N1)/(SUM(VAR4,N1)+SUM(VAR5,N1));
         VAR7:=SUM(VAR5,N1)/(SUM(VAR4,N1)+SUM(VAR5,N1));
         VAR8:=VAR6-VAR7;
         VAR9:=MA(VAR8,2*N1);
         VAR10:=MA(VAR9,N1);

         //开平仓条件

         CONKD:=BARPOS>N2 AND C>VAR2 AND VAR2>VAR3 AND VAR8>0 AND VAR9>VAR10;
         CONKK:=BARPOS>N2 AND CENTERPRICE*(1+0.03*N3);
         CONPK:C>VAR2 AND CENTERPRICE*(1+0.03*N3);

         //交易系统

         SELL(HOLDING>0 AND CONPD,HOLDING,MARKET);
         SELLSHORT(HOLDING<0 AND CONPK,HOLDING,MARKET);
         BUY(HOLDING=0 AND CONKD,SS,MARKET);
         BUYSHORT(HOLDING=0 AND CONKK,SS,MARKET);

         SELL(HOLDING>0 AND DTZS,HOLDING,MARKET);
         SELLSHORT(HOLDING<0 AND KTZS,HOLDING,MARKET);

        三、策略回测

          回测对象:沪铜连续合约

          回测周期:5分钟周期

          回测时段:2019.1-至今

          回测初始资金:10W

双均线DDI策略_第1张图片