您现在的位置:程序化交易>> 期货公式>> 交易开拓者(TB)>> 开拓者知识>>正文内容

平仓错误 [开拓者 TB]

  • 咨询内容: 想请教一下,下面是我的代码,我设置的平多条件是紫色的LLH小于黄色的ma时才能平多,为什么这里给我平了呢?

     

     来源:CXH99.COM

  • TB技术人员:
    Params
             
            Numeric N(600);
            Numeric FastLength(12);
            Numeric SlowLength(26);
            Numeric MACDLength(18);
    Numeric FastLength0(500);
            Numeric SlowLength0(1000);
            Numeric MACDLength0(700);
    Vars
            Series<Numeric> LOTS;
            Series<Numeric> MA;
    Series<Numeric> MACDValue0;
            Series<Numeric> AvgMACD0;
            Series<Numeric> Diff0;
    Series<Numeric> MACDValue;
            Series<Numeric> AvgMACD;
            Series<Numeric> Diff;
            Series<Numeric> Diff1;
    Series<Numeric> HH;
    Series<Numeric> HH1;
    Series<Numeric> HHH;
    Series<Numeric> HHL;
    Series<Numeric> HHLB;
    Series<Numeric> LLHB;
            Series<Numeric> LL;
            Series<Numeric> LL1;
            Series<Numeric> LLL;
            Series<Numeric> LLH;
    Series<Numeric> FLAG1;
            Series<Numeric> FLAG2;
            Series<Numeric> FLAG11;
            Series<Numeric> FLAG22;
    Series<Numeric> X;
            Series<Numeric> Y;
    Series<Numeric> DKH;
    Series<Numeric> DKL;
    Series<Numeric> myPrice;
    Bool validTime;
    Bool ZD1;
    Bool ZD2;
    Bool ZD3;
    Bool ZD4;
    Bool ZK1;
    Bool ZK2;
    Bool ZK3;
    Bool ZK4;
    Bool PD1;
    Bool PK1;




    Events
             onBar(ArrayRef<Integer> indexs)
    {
    LOTS=1;

    validTime = (TIME>=0.0900 and time <=0.1500) and (time >=0.2100 and time <=0.0100);

    MA=AverageFC(C[1],N);
             

            PlotNumeric("MA",ma);


    MACDValue0 = XAverage(Close, FastLength0) - XAverage(Close, SlowLength0) ;
    AvgMACD0= XAverage(MACDValue0,MACDLength0);
    Diff0= MACDValue0[1] - AvgMACD0[1];

    MACDValue = XAverage( Close, FastLength ) - XAverage(Close, SlowLength ) ;
    AvgMACD = XAverage(MACDValue,MACDLength);
    Diff = MACDValue[1] - AvgMACD[1];
    Diff1 = MACDValue[1] - AvgMACD[1];

    IF(diff>0 and diff[1]>0 and diff[2]>0 and diff[3]>0 and diff[4]>0 and diff[5]>0 and diff[6]>0 and diff[7]<0){FLAG1=CurrentBar;}
    IF(diff<0 and diff[1]<0 and diff[2]<0 and diff[3]<0 and diff[4]<0 and diff[5]<0 and diff[6]<0 and diff[7]>0){FLAG2=CurrentBar;}
    x=flag2-FLAG1;
    HH=Highest (H[1],x+7);
    IF(diff<0 and diff[1]<0 and diff[2]<0 and diff[3]<0 and diff[4]<0 and diff[5]<0 and diff[6]<0 and diff[7]>0){HH1=HH;}Else{HH1=HH1[1]; }
    IF(HH1[1]>HH1[2]){HHH=HH1[1];}
    IF(HH1<>HH1[1]){HHLB=CurrentBar;}Else{HHLB=HHLB[1];}
    HHL=Lowest(L[1],CurrentBar[1]-HHLB+7);

    IF(diff1>0 and diff1[1]>0 and diff1[2]>0 and diff1[3]>0 and diff1[4]>0 and diff1[5]>0 and diff1[6]>0 and diff1[7]<0){FLAG11=CurrentBar;}
    IF(diff1<0 and diff1[1]<0 and diff1[2]<0 and diff1[3]<0 and diff1[4]<0 and diff1[5]<0 and diff1[6]<0 and diff1[7]>0){FLAG22=CurrentBar;}
    y=FLAG11-FLAG22;
    LL=Lowest (L[1],Y+7);
    IF(diff1>0 and diff1[1]>0 and diff1[2]>0 and diff1[3]>0 and diff1[4]>0 and diff1[5]>0 and diff1[6]>0 and diff1[7]<0){LL1=LL;}Else{LL1=LL1[1];}
    IF(LL1[1]<LL1[2]){LLL=LL1[1];}
    IF(LL1<>LL1[1]){LLHB=CurrentBar;}Else{LLHB=LLHB[1];}
    LLH=Highest(H[1],CurrentBar[1]-LLHB+7);
    PlotNumeric("LLH",LLH);
    PlotNumeric("HHL",HHL);

    ZD1=Diff0>=0 and MA[1]<=HH1 and L[2]<=HH1 and H>HH1;
    ZD2=Diff0>=0 and MA[1]>=HH1 and L[2]<=HH1 and H>MA[1];
    ZD3=Diff0>=0 and MA[1]>=HHH and L[2]<=HHH and H>MA[1];
    ZD4=Diff0>=0 and MA[1]<=HHH and L[2]<=HHH and H>HHH;


    ZK1=Diff0<=0 and MA[1]>=LL1 and H[2]>=LL1 and L<LL1;
    ZK2=Diff0<=0 and MA[1]<=LL1 and H[2]>=LL1 and L<MA[1];
    ZK3=Diff0<=0 and MA[1]<=LLL and H[2]>=LLL and L<MA[1];
    ZK4=Diff0<=0 and MA[1]>=LLL and H[2]>=LLL and L<LLL;


    PD1=L>=EntryPrice and LLH<MA[1] and H[1]>=LL1 and L<LL1;


    PK1=H<=EntryPrice and HHL>MA[1] and L[1]<=HH1 and H>HH1;


            If (validTime=True and MarketPosition<>1 and CurrentBar>=1)
            {
            If( ZD1){myPrice = Max (HH1,open);myPrice = IIF (BarStatus==2,0,myPrice);Buy(Lots,myPrice);}
    Else If ( ZD4){myPrice = Max (HHH,open);myPrice = IIF (BarStatus==2,0,myPrice);Buy(Lots,myPrice);}
    Else If (ZD2 OR ZD3){myPrice = Max (MA[1],open);myPrice = IIF (BarStatus==2,0,myPrice);Buy(Lots,myPrice);}
    }//开多

    IF (validTime=True AND MarketPosition<>-1 and CurrentBar>=1)
    {
    If (ZK1){myPrice = Min(LL1,open);myPrice = IIF (BarStatus==2,0,myPrice);SellShort(Lots,myPrice);}
             Else If (ZK4){myPrice = Min (LLL,open);myPrice = IIF (BarStatus==2,0,myPrice);SellShort(Lots,myPrice);}
             Else If (ZK2 OR ZK3){myPrice = Min (MA[1],open);myPrice = IIF (BarStatus==2,0,myPrice);SellShort(Lots,myPrice);}
            }//开空仓
             
             
            If (validTime=True AND MarketPosition==1 and BarsSinceLastEntry >= 1 )
    {
            If(PD1){Sell(0,Min(LL1,Open));}
            }//平多
             
            If (validTime=True AND MarketPosition==-1 and BarsSinceLastEntry >= 1 )
            {
            If(PK1){BuyToCover(0,Max(HH1,Open));}
    }//平
             
             
             
    }

     

  • TB客服: 发不出来图,就描述一下。我的想法是:平多条件是LLH小于ma时才能平多,平空的条件是HHL大于ma时才能平空,但是在图表上看这个条件没起作用,不知道是怎么回事。特在此请教。

     

  • 网友回复:
    armyhuan 发表于 2019-11-4 09:06
    发不出来图,就描述一下。我的想法是:平多条件是LLH小于ma时才能平多,平空的条件是HHL大于ma时才能平空, ...

    代码有误吧?
    条件中应该写为validtime==true吧? 判断式是双等号。

 

有思路,想编写各种指标公式,交易模型,选股公式,还原公式的朋友

可联系技术人员 QQ: 262069696  点击在线交流或微信号:cxh99cxh99  进行 有偿收费 编写!

怎么收费,代编流程等详情请点击阅读!

(注:由于人数限制,QQ或微信请选择方便的一个联系我们就行,加好友时请简单备注下您的需求,否则无法通过。谢谢您!)


【字体: 】【打印文章】【查看评论

相关文章

    没有相关内容