设为首页收藏本站

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

求解答,为何我设计的日内交易系统总是不能在收盘前平仓 [复制链接]

Rank: 5Rank: 5

精华
0
UID
58944
积分
665
帖子
226
主题
29
阅读权限
60
注册时间
2011-8-11
最后登录
2018-6-27
跳转到指定楼层
1#
发表于 2011-8-29 10:58:49 |只看该作者 |倒序浏览
一分钟的周期也试过了,不行,现在用的五分钟周期,貌似还是不行。
附上程序 求高人解答


Params   
        Numeric endTime(14.55);                     //结束交易时间
    Numeric RiskRatio(1);                       //风险率(0-100)
    Numeric boLength(18);                       //突破周期
    Numeric ATRLength(20);                      //平均波动周期
        Numeric Quitlength(10);                     //离市周期
        Numeric weightnumber(1);                    //加权参数
        Numeric Limitednumber(3);                   //交易限制次数(能交易的次数为limitednumber+1次)
    Bool Filtercondition(True);                 //入市过滤条件
Vars
    Numeric Minpoint;                           //最小变动单位
        NumericSeries AvgTR;                        //ATR
        Numeric F;                                  //表示市场波动性的F值
        Numeric Capital;                            //入市资本
        Numeric scale;                              //买卖规模
        NumericSeries Passwayhi;                    //通道上轨
        NumericSeries Passwaylo;                    //通道下轨
        NumericSeries quithighprice;                //离市时判断需要的离市周期最高价
        NumericSeries quitlowprice;                 //离市时判断需要的离市周期最低价
        Numeric myEntryPrice;                       //开仓价格
        Numeric myExitPrice;                        //平仓价格
        NumericSeries tempnum(0);                   //临时计数器
        Bool Sendorderthisbar(False);               //当前Bar是否有过交易
        NumericSeries preEntryprice(0);             //前一次开仓的价格
Begin
        Minpoint=Minmove*PriceScale;
        AvgTR=XAverage(TrueRange,ATRlength);
        F=weightnumber*AvgTR[1];
        Capital=Portfolio_CurrentCapital()+Portfolio_UsedMargin();
        scale=(Capital*RiskRatio/100)/(F*ContractUnit()*BigPointValue());
        scale=IntPart(scale);
       
        Passwayhi=HighestFC(High[1],boLength);
        Passwaylo=LowestFC(Low[1],boLength);
       
        quitlowprice=LowestFC(Low[1],Quitlength);
        quithighprice=HighestFC(High[1],Quitlength);
       
        Commentary("scale="+Text(scale));
        Commentary("preEntryprice="+Text(preEntryprice));
       
        If(Date!=currentdate)                       //只限于当日交易
        {return;}                                 
        If((Date!=Date[1])or(CurrentBar==0))
        {
        //当日的第一个Bar
        preEntryprice=InvalidNumeric;
        tempnum=Limitednumber;
        return;
        }
       
        If(tempnum[1]<1)
        {
        tempnum=limitednumber;
        }
       
        //开仓
If(time<endtime/100)
{       
        If(MarketPosition==0 And Filtercondition)
        {
            If(High>Passwayhi And scale>=1)
                {
                myEntryPrice=Min(high,passwayhi+minpoint);
                myentryprice=IIF(myentryprice<open,open,myentryprice);
                preentryprice=myentryprice;
                Buy(scale,myentryprice);
                sendorderthisbar=True;
                }
               
                If(Low<passwaylo And scale>=1)
                {
                myentryprice=Max(low,passwaylo-Minpoint);
                myentryprice=IIF(myentryprice>open,open,myentryprice);
                preentryprice=myentryprice;
                SellShort(scale,myentryprice);
                sendorderthisbar=True;
                }
        }
       
       
        If(Marketposition==1)
        {
            Commentary("quitlowprice="+Text(quitlowprice));
                If(Low<quitlowprice)
                {
                    myexitprice=Max(low,quitlowprice-Minpoint);
                        myexitprice=IIF(myexitprice>open,open,myexitprice);
                        Sell(0,myexitprice);
                        tempnum=limitednumber;
                }Else
                {
                    tempnum=tempnum[1];
                        If(preentryprice!=Invalidnumeric And scale>=1)
                        {
                            If((open>=preentryprice+0.5*F) And (tempnum>=1))
                                {
                                    myentryprice=open;
                                        preentryprice=myentryprice;
                                        Buy(scale,myentryprice);
                                        sendorderthisbar=True;
                                        tempnum=tempnum-1;
                                }
                               
                                While((High>=preentryprice+0.5*F) And (tempnum>=1))
                                {
                                    myentryprice=preentryprice+0.5*F;
                                        preentryprice=myentryprice;
                                        Buy(scale,myentryprice);
                                        sendorderthisbar=true;
                                        tempnum=tempnum-1;
                                }
                        }
                       
                        If(low<=preentryprice-2*F And sendorderthisbar==false)
                        {
                        myexitprice=preentryprice-2*F;
                        Sell(0,myexitprice);
                        tempnum=limitednumber;
                        }
                }
        }Else If(marketposition==-1)
        {
            Commentary("quithighprice="+Text(quithighprice));
                If(high>quithighprice)
                {
                    myexitprice=Min(High,quithighprice+Minpoint);
                        myexitprice=IIF(myexitprice<open,open,myexitprice);
                        BuyToCover(0,myexitprice);
                        tempnum=limitednumber;
                }Else
                {   tempnum=tempnum[1];
                    If(preentryprice!=Invalidnumeric And scale>=1)
                        {
                            If((open<=preentryprice-0.5*F) And (tempnum>=1))
                                {
                                    myentryprice=Open;
                                        preentryprice=myentryprice;
                                        SellShort(scale,myentryprice);
                                        sendorderthisbar=True;
                                        tempnum=tempnum-1;
                                }
                               
                                While((Low<=preentryprice-0.5*F) And (tempnum>=1))
                                {
                                    myentryprice=preentryprice-0.5*F;
                                        preentryprice=myentryprice;
                                        SellShort(scale,myentryprice);
                                        sendorderthisbar=True;
                                        tempnum=tempnum-1;
                                }
                        }
                       
                       
                        If(High>=preentryprice+2*F And sendorderthisbar==False)
                        {
                            myexitprice=preentryprice+2*F;
                                BuyToCover(0,myexitprice);
                                tempnum=limitednumber;
                        }
                }
        }
}


If(time>=endtime/100)
{
    If(marketposition==1)
        {
            Sell(0,Q_AskPrice);
        }Else If(marketposition==-1)
        {
            BuyToCover(0,Q_BidPrice);
        }Else
        {
            return;
        }
}
End


前面应该不用看,因为开仓,加仓,都还蛮正常的,唯独平仓有问题,何解??
乞红日永照吾土  愿国魂常驻中华  怀悲悯敬天畏命  存慈爱推己及人

Rank: 7Rank: 7Rank: 7

精华
0
UID
7437
积分
2872
帖子
537
主题
133
阅读权限
80
注册时间
2010-3-15
最后登录
2013-11-15
2#
发表于 2011-8-29 11:22:08 |只看该作者
回复 1# slarkmonk


     If(marketposition==1)
        {
            Sell(0,close);
        }Else If(marketposition==-1)
        {
            BuyToCover(0,close);
        }Else

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
58944
积分
665
帖子
226
主题
29
阅读权限
60
注册时间
2011-8-11
最后登录
2018-6-27
3#
发表于 2011-8-29 11:51:59 |只看该作者
回复 2# 欲速不达

用close不行吧??不能保证成交
时间和价格都不能保证
乞红日永照吾土  愿国魂常驻中华  怀悲悯敬天畏命  存慈爱推己及人

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
2
UID
4130
积分
20906
帖子
6519
主题
17
阅读权限
200
注册时间
2009-4-15
最后登录
2019-4-12
4#
发表于 2011-8-29 13:01:23 |只看该作者
回复 3# slarkmonk


改用价格close,使用Q函数会导致信号消失,历史测试上是不会出现该信号的

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
58944
积分
665
帖子
226
主题
29
阅读权限
60
注册时间
2011-8-11
最后登录
2018-6-27
5#
发表于 2011-8-29 13:18:58 |只看该作者
回复 4# lh948

意思是 还是用CLOSE?能行?
乞红日永照吾土  愿国魂常驻中华  怀悲悯敬天畏命  存慈爱推己及人

使用道具 举报

Rank: 4

精华
0
UID
6686
积分
420
帖子
111
主题
25
阅读权限
50
注册时间
2010-1-16
最后登录
2019-3-24
6#
发表于 2011-8-29 14:45:29 |只看该作者
Q函数不能用于测试。。。。

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
58944
积分
665
帖子
226
主题
29
阅读权限
60
注册时间
2011-8-11
最后登录
2018-6-27
7#
发表于 2011-8-29 15:17:33 |只看该作者
回复 6# lzl563

跪求教我一个保证一定能成交的命令,是用sell(0,0)么?还是啥?

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
58944
积分
665
帖子
226
主题
29
阅读权限
60
注册时间
2011-8-11
最后登录
2018-6-27
8#
发表于 2011-8-29 15:20:38 |只看该作者
回复 6# lzl563
多问一个问题
那实盘中能否使用Q函数呢?

使用道具 举报

Rank: 4

精华
0
UID
6686
积分
420
帖子
111
主题
25
阅读权限
50
注册时间
2010-1-16
最后登录
2019-3-24
9#
发表于 2011-8-29 16:17:48 |只看该作者
回复 8# slarkmonk


    实盘中可以用吧   也可以加滑点来保证成交吧。。。

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
2
UID
4130
积分
20906
帖子
6519
主题
17
阅读权限
200
注册时间
2009-4-15
最后登录
2019-4-12
10#
发表于 2011-8-29 16:30:41 |只看该作者
回复 8# slarkmonk


实盘中可以使用Q函数。
close是最新价,一般都可以成交的,
没有100%成交的写法的。

Q函数在历史上是无法测试的。建议使用close替换。

使用道具 举报

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

bottom

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

GMT+8, 2024-5-24 04:02

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部