设为首页收藏本站

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

这新手组合的系统,如何修改才能实盘自动交易呢?【转发】 [复制链接]

Rank: 2

精华
0
UID
112002
积分
53
帖子
13
主题
8
阅读权限
30
注册时间
2012-8-13
最后登录
2013-6-11
跳转到指定楼层
1#
发表于 2012-9-24 12:07:33 |只看该作者 |倒序浏览
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==0.145500 && /*CurrentTime>0.145800 &&*/ MarketPosition<>0)  //收盘平仓用于5Min
        {
                Sell(0,Close);
                BuyToCover(0,Close);
        
        }
        


End

Rank: 3Rank: 3

精华
0
UID
109920
积分
166
帖子
135
主题
1
阅读权限
40
注册时间
2012-4-10
最后登录
2013-5-14
2#
发表于 2012-9-24 12:39:54 |只看该作者
最好能附说下系统原理
这样别人看了也会很好理解,不会浪费时间,
不然一般人也懒得看源码

使用道具 举报

Rank: 4

精华
0
UID
79988
积分
505
帖子
74
主题
10
阅读权限
50
注册时间
2011-11-16
最后登录
2016-2-13
3#
发表于 2012-9-24 22:10:15 |只看该作者
好像海龟系统的代码呢?

使用道具 举报

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

bottom

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

GMT+8, 2024-5-18 05:21

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部