设为首页收藏本站

 找回密码
 注册
查看: 2562|回复: 2

如何在同一BAR连续多次开仓? [复制链接]

Rank: 2

精华
0
UID
7457
积分
110
帖子
25
主题
10
阅读权限
30
注册时间
2010-3-16
最后登录
2018-4-20
发表于 2018-3-8 16:22:40 |显示全部楼层
问题描述:使用突破加仓原则,在做历史测试时,如果一根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

Rank: 10Rank: 10Rank: 10

精华
3
UID
5
积分
26584
帖子
12686
主题
49
阅读权限
200
注册时间
2007-7-20
最后登录
2021-11-3
发表于 2018-3-9 09:05:41 |显示全部楼层
合理的公式代码,并在全局交易设置中勾选允许连续建仓,即可实现。
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

使用道具 举报

Rank: 2

精华
0
UID
7457
积分
110
帖子
25
主题
10
阅读权限
30
注册时间
2010-3-16
最后登录
2018-4-20
发表于 2018-4-20 09:45:01 |显示全部楼层
小米 发表于 2018-3-9 09:05
合理的公式代码,并在全局交易设置中勾选允许连续建仓,即可实现。

对,就是您这个效果,但我的公式实现不了,能帮我修改一下吗?或者我的代码有什么问题呀?

使用道具 举报

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

bottom

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

GMT+8, 2024-4-19 09:16

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部