开拓者期货期权程序化系统交易论坛

标题: 突破加仓原则历史测试时同一根Bar上连续开仓 [打印本页]

作者: notherask    时间: 2018-3-8 16:30:32     标题: 突破加仓原则历史测试时同一根Bar上连续开仓

问题描述:使用突破加仓原则,在做历史测试时,如果一根Bar上连续满足了两次突破原则,如何开两次仓?比如说3890元开仓,每向下运动38个点位就加一次仓,那么当第二天价格跌破3814元(即两个38点)时,我在实盘中应该加两次仓。但在历史测试中仅显示加了一次,为什么?如何实现?
源码:Params
        Numeric m(4);
Vars
        numeric zdkczj;
        NumericSeries a;
        NumericSeries b;
        NumericSeries e;
        numeric entrylots;
    numericSeries zs;
        NumericSeries myatr;
        NumericSeries jc;
        numericseries scjcss;

Begin
     
        zdkczj=Portfolio_CurrentEquity;
       
       
        a=(3*c+l+o+h)/6;
        b=(20*a+19*a[1]+18*a[2]+17*a[3]+16*a[4]+15*a[5]+14*a[6]+13*a[7]+12*a[8]+11*a[9]+10*a[10]+9*a[11]+8*a[12]+7*a[13]+6*a[14]+5*a[15]+4*a[16]+3*a[17]+2*a[18]+a[20])/210;
        e=average(b,m);
        myatr=IntPart(AvgTrueRange(10));
        zs=1*myatr;
    jc=0.5*myatr;
//多头开仓
    if(crossover(b,e) and MarketPosition!=1)
           {
                SetGlobalVar(0,zs);
                SetGlobalVar(1,jc);
                entryLots= (zdkczj*0.02)/(1.0*zs*ContractUnit);
                entryLots  = IntPart(entryLots );
                Buy(entryLots,C);
                scjcss=entrylots;
                SetGlobalVar(4,scjcss);
           }
//多头开仓结束

//多头加仓
    if(b>e and MarketPosition==1 and h>=LastEntryPrice+GetGlobalVar(1))
           {
                entryLots=Max(Power(0.5,CurrentEntries)*GetGlobalVar(4),1);
        entryLots  = IntPart(entryLots );
        Buy(entryLots,LastEntryPrice+GetGlobalVar(1));
           }

//多头加仓结束

//空头开仓       
        if(Crossover(e,b) and MarketPosition!=(-1))
           {
            SetGlobalVar(2,zs);
                SetGlobalVar(3,jc);
            entryLots= (zdkczj*0.02)/(1.0*zs*ContractUnit);
        entryLots  = IntPart(entryLots );
            SellShort(entryLots,c);
                scjcss=entrylots;
                SetGlobalVar(5,scjcss);
           }
//空头开仓结束


//空头加仓
    if(b<e and MarketPosition==(-1) and l<=LastEntryPrice-GetGlobalVar(3))
           {
                entryLots=Max(Power(0.5,CurrentEntries)*GetGlobalVar(5),1);
        entryLots  = IntPart(entryLots );
        SellShort(entryLots,LastEntryPrice-GetGlobalVar(3));
           }

//空头加仓结束

          
//持仓处理
         If(BarsSinceEntry!=0)
          {
             if(MarketPosition==1 and l<=EntryPrice-GetGlobalVar(0)) Sell(0,EntryPrice-getGlobalVar(0));
             if(MarketPosition==(-1) and h>=EntryPrice+GetGlobalVar(2)) BuyToCover(0,EntryPrice+getGlobalVar(1));
               
           }
//持仓处理结束

       

End




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2