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

求助代码问题。 [MC]

  • MC用户求助:

    [IntrabarOrderGeneration=False];

    Inputs:X(50);

    inputs: DataSeries1( Close of data1 ), DataSeries2( Close of data2 );

    variable:close1(0),var1(0),sell1(0),sell2(0),sell3(0),sell4(0),sell5(0),sell6(0),buy1(0),buy2(0),buy3(0),buy4(0),buy5(0),buy6(0);

     

     

    close1=DataSeries1-DataSeries2;

     

     

      var1=-150;

       sell1=var1+X;

      sell2=var1+2*X;

        sell3=var1+3*X;

          sell4=var1+4*X;

            sell5=var1+5*X;

            sell6=var1+6*X;

    buy1=var1-X;

      buy2=var1-2*X;

      buy3=var1-3*X;

      buy4=var1-4*X;

      buy5=var1-5*X;

        buy6=var1-6*X;

     

    condition1=Close1 cross over  sell1;

    condition2=Close1 cross over sell2;

    condition3=Close1 cross over sell3;

    condition4=Close1 cross over  sell4;

    condition5=Close1 cross over  sell5;

     

    {condition11=Close1 < 200;

    condition21=Close1 <  250;

    condition31=Close1 < 300;

    condition41=Close1 <  350;

    condition51=Close1 <   400;}

     

     

    condition6=Close1 cross under buy1;

    condition7=Close1 cross under buy2;

    condition8=Close1 cross under buy3;

    condition9=Close1 cross under buy4;

    condition10=Close1 cross under buy5;

     

     

     

    {condition61=Close1 > buy1;

    condition71=Close1 > buy2;

    condition81=Close1 >buy3;

    condition91=Close1 > buy4;

    condition11=Close1 > buy5;}

     

    if  condition1 then sellshort("s1") 1 contracts next bar at market;

    if condition2 then sellshort("s2") 1 contracts next bar at market;

    if  condition3  then sellshort("s3") 1 contracts next bar at market;

    if  condition4  then sellshort("s4") 3 contracts next bar at market;

    if  condition5  then sellshort ("s5")6 contracts next bar at market;

    //if marketposition=1 and condition6 and currentcontracts=12 then sellshort 12 contracts next bar at market;

    if Close1[1] > sell4  and Close1 <= sell4 and marketposition=-1 then buytocover from entry("s5") next bar at market;

    if  Close1[1] > sell3  and Close1 <= sell3 and marketposition=-1  then buytocover from entry("s4")  next bar at market;

    if Close1[1] > sell2  and Close1<=sell2 and marketposition=-1  then buytocover from entry("s3")  next bar at market;

    if Close1[1] > sell1 and Close1 <= sell1 and marketposition=-1 then buytocover  from entry("s2")   next bar at market;

    if Close1[1] > var1 and  close1 <= var1  and marketposition=-1   then buytocover from entry("s1") next bar at market;

    if close1<150   then buytocover next bar at market;

     

     

     

    if  condition6  then buy("b1") 1 contracts next bar at market;

    if condition7 then buy("b2") 1 contracts next bar at market;

    if  condition8  then buy("b3") 1 contracts next bar at market;

    if  condition9  then buy("b4") 3 contracts next bar at market;

    if  condition10  then buy ("b5")6 contracts next bar at market;

    //if marketposition=1 and condition6 and currentcontracts=12 then sellshort 12 contracts next bar at market;

    if  Close1[1] < buy4 and  Close1 >= buy4 and marketposition=1 then buytocover from entry("b5")  next bar at market;

    if  Close1[1] < buy3 and  Close1 >= buy3 and marketposition=1  then buytocover from entry("b4")   next bar at market;

    if  Close1[1] < buy2 and  Close1 >= buy2 and marketposition=1  then buytocover from entry("b3")  next bar at market;

    if  Close1[1] < buy1 and  Close1 >= buy1 and marketposition=1 then buytocover  from entry("b2")   next bar at market;

    if   Close1[1] < var1 and  Close1 >= var1  and marketposition=1   then buytocover from entry("b1") next bar at market;

    if close1>150   then sell next bar at market;

     

    我想实现类似网格策略,进仓点位正确,平仓点位不正确。如何找出问题

     

  • MC回复讨论一:

    https://forum.multicharts.cn/forum/cat/0/thread/33
    这个帖子有关于进场出场语句的介绍,另外官网上有网格策略可以看一下。

    您可以在策略关键位置使用关键字print将该行相关的信息输出出来进行debug;或者使用commentry进行debug

    从您的代码来看,buytocover平仓语句对应的是空头持仓,而sell平仓语句对应的是多头持仓,这个地方在您的后半段的语句中是错误的。

    对于您所说的“进场和平仓点位不正确”,您需要将“不正确”叙述清楚,哪里不正确?

 

有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友

可联系技术人员 QQ: 511411198  点击这里给我发消息进行 有偿 编写!不贵!点击查看价格!


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

相关文章

    没有相关内容