设为首页收藏本站

 找回密码
 注册
查看: 2916|回复: 2
打印 上一主题 下一主题

这个棉花套利策略怎么不能实现加仓,在线等 [复制链接]

Rank: 4

精华
0
UID
6686
积分
420
帖子
111
主题
25
阅读权限
50
注册时间
2010-1-16
最后登录
2019-3-24
跳转到指定楼层
1#
发表于 2012-5-4 10:57:57 |显示全部楼层 |倒序浏览
本帖最后由 lzl563 于 2012-5-4 11:15 编辑

Params
     Numeric uprice1(700);
         Numeric uprice2(750);
         Numeric uprice3(800);
         Numeric dprice1(-700);
         Numeric dprice2(-750);
         Numeric dprice3(-800);
         Numeric lots1(1);
         Numeric lots2(2);
         Numeric lots3(4);
   


Vars
        Numeric NO1(0);
    Numeric M;
    Numeric M1;
        NumericSeries buyprice;
        NumericSeries sellprice;
        BoolSeries Upline;
        BoolSeries Upline1;
        BoolSeries Upline2;
        BoolSeries downline;
        BoolSeries downline1;
        BoolSeries downline2;
Begin
     M=Data0.close-Data1.close;
     M1=(Data0.open)-(Data1.open);
     //PlotNumeric("M",M);
         //PlotNumeric("M1",M1);
          upline=CrossOver(M,uprice1);
          upline1=CrossOver(M,uprice2);
          upline2=CrossOver(M,uprice3);
          downline=CrossUnder(M,dprice1);
          downline1=CrossUnder(M,dprice2);
          downline2=CrossUnder(M,dprice3);               
If(MarketPosition==0 and upline)
  {
  data0.SellShort(lots1,data0.close);
  data1.buy(lots1,data0.close);
  Return;
  }
If(MarketPosition==1 and upline1)
  {
  data0.SellShort(lots2,data0.close);
  data1.buy(lots2,data1.close);
  Return;
  }
If(MarketPosition==1 and upline2)
  {
  data0.SellShort(lots3,data0.close);
  data1.buy(lots3,data1.close);
  Return;
  }
If(MarketPosition==0 and downline )
{data0.buy(lots1,data0.close);
data1.SellShort(lots1,data1.close);
Return;
  }
If(MarketPosition==-1 and downline1 )
{data0.buy(lots2,data0.close);
data1.SellShort(lots2,data1.close);
Return;
  }
If(MarketPosition==-1 and downline2 )
{data0.buy(lots3,data0.close);
data1.SellShort(lots3,data1.close);
Return;
  }

End

Rank: 4

精华
0
UID
6686
积分
420
帖子
111
主题
25
阅读权限
50
注册时间
2010-1-16
最后登录
2019-3-24
2#
发表于 2012-5-4 11:58:48 |显示全部楼层
自己顶一下,没人看啊?

使用道具 举报

Rank: 4

精华
0
UID
6686
积分
420
帖子
111
主题
25
阅读权限
50
注册时间
2010-1-16
最后登录
2019-3-24
3#
发表于 2012-5-4 14:29:18 |显示全部楼层
改了一下好了点,但是还有个问题,就是相同的条件会出现两次开仓,怎么不让相同的条件重复开仓呢
Params
     Numeric uprice1(700);
         Numeric uprice2(750);
         Numeric uprice3(800);
         Numeric dprice1(-700);
         Numeric dprice2(-750);
         Numeric dprice3(-800);
         Numeric lots1(1);
         Numeric lots2(2);
         Numeric lots3(4);   
Vars
        Numeric NO1(0);
    Numeric M;
    Numeric M1;
        NumericSeries buyprice;
        NumericSeries sellprice;
        BoolSeries Upline;
        BoolSeries Upline1;
        BoolSeries Upline2;
        BoolSeries downline;
        BoolSeries downline1;
        BoolSeries downline2;
Begin
     M=Data0.close-Data1.close;
     M1=(Data0.open)-(Data1.open);
     //PlotNumeric("M",M);
         //PlotNumeric("M1",M1);
          upline=CrossOver(M,uprice1);
          upline1=CrossOver(M,uprice2);
          upline2=CrossOver(M,uprice3);
          downline=CrossUnder(M,dprice1);
          downline1=CrossUnder(M,dprice2);
          downline2=CrossUnder(M,dprice3);       
//M>700的时候开仓加仓          
If(data0.MarketPosition !=-1 and (upline==true))
  {
  data0.SellShort(lots1,data0.close);
  data1.buy(lots1,data0.close);

  }
If(data0.MarketPosition==-1 and (upline1==true))
  {
  data0.SellShort(lots2,data0.close);
  data1.buy(lots2,data1.close);
  
  }
If(data0.MarketPosition==-1 and (upline2==true))
  {
  data0.SellShort(lots3,data0.close);
  data1.buy(lots3,data1.close);
  
  }
//M<700的时候开仓加仓
If(data0.MarketPosition!=1 and (downline==true) )
{data0.buy(lots1,data0.close);
data1.SellShort(lots1,data1.close);

  }
If(data0.MarketPosition==1 and (downline1==true) )
{data0.buy(lots2,data0.close);
data1.SellShort(lots2,data1.close);

  }
If(data0.MarketPosition==1 and (downline2==true) )
{data0.buy(lots3,data0.close);
data1.SellShort(lots3,data1.close);

  }

End

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-18 06:33

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部