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

期货期权交流求教代码问题 [MC]

  • 咨询内容:
          你好,下面是我编写的股指期货代码,现在有几个问题想请教一下。
          1、以下的代码有没有地方可以简化?可以减少计算时间。
          2、现在运行中,setstoploss止损后,就不能自动开仓了,如果想止损后依然按条件自动开仓,应该怎么写代码?
         非常感谢!




    inputs:p01(9999),p02(9999),p03(9999),p04(9999);
    variables:co1(0),c02(0),c03(0),c04(0),d01(0),d02(0),d03(0),d04(0);
    begin
    co1=p01-0.2;
    c02=p02-0.2;
    c03=p03-0.2;
    c04=p04-0.2;
    d01=p01+0.2;
    d02=p02+0.2;
    d03=p03+0.2;
    d04=p04+0.2;
    if close cross above co1 and marketposition=0 then sellshort 1 contract next bar at market;
    if close cross above c02 and marketposition=0 then sellshort 1 contract next bar at market;
    if close cross above c03 and marketposition=0 then sellshort 1 contract next bar at market;
    if close cross above c04 and marketposition=0 then sellshort 1 contract next bar at market;
    if close cross under d01 and marketposition=0 then buy 1 contract next bar at market;
    if close cross under d02 and marketposition=0 then buy 1 contract next bar at market;
    if close cross under d03 and marketposition=0 then buy 1 contract next bar at market;
    if close cross under d04 and marketposition=0 then buy 1 contract next bar at market;
    if close cross above co1 and marketposition=1 then sellshort 1 contracts next bar at market;
    if close cross above c02 and marketposition=1 then sellshort 1 contracts next bar at market;
    if close cross above c03 and marketposition=1 then sellshort 1 contracts next bar at market;
    if close cross above c04 and marketposition=1 then sellshort 1 contracts next bar at market;
    if close cross above d01 and marketposition=-1 then buy 1 contract next bar at market;
    if close cross above d02 and marketposition=-1 then buy 1 contract next bar at market;
    if close cross above d03 and marketposition=-1 then buy 1 contract next bar at market;
    if close cross above d04 and marketposition=-1 then buy 1 contract next bar at market;
    if close cross under co1 and marketposition=1 then sellshort 1 contract next bar at market;
    if close cross under c02 and marketposition=1 then sellshort 1 contract next bar at market;
    if close cross under c03 and marketposition=1 then sellshort 1 contract next bar at market;
    if close cross under c04 and marketposition=1 then sellshort 1 contract next bar at market;
    if close cross under d01 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross under d02 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross under d03 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross under d04 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross above d01 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross above d02 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross above d03 and marketposition=-1 then buy 1 contracts next bar at market;
    if close cross above d04 and marketposition=-1 then buy 1 contracts next bar at market;
    setstoploss(600);
    if time>=1457 then
    sell next bar at market;
    buytocover next bar at market;
    end

     

  • MC技术部: 还想请问我的收盘平仓的代码是否正确?

 

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

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


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

相关文章

    没有相关内容