设为首页收藏本站

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

突破型日内交易策略源码 [复制链接]

Rank: 1

精华
0
UID
176185
积分
26
帖子
13
主题
12
阅读权限
10
注册时间
2013-11-23
最后登录
2014-3-2
跳转到指定楼层
1#
发表于 2014-1-1 15:55:28 |只看该作者 |倒序浏览


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: 2

精华
0
UID
111224
积分
94
帖子
42
主题
14
阅读权限
30
注册时间
2012-6-27
最后登录
2016-11-20
2#
发表于 2014-1-17 14:05:08 |只看该作者
有源码的都要顶!

使用道具 举报

Rank: 1

精华
0
UID
118058
积分
11
帖子
1
主题
0
阅读权限
10
注册时间
2013-4-12
最后登录
2021-5-6
3#
发表于 2014-1-19 13:16:41 |只看该作者
顶你

使用道具 举报

Rank: 1

精华
0
UID
114434
积分
44
帖子
43
主题
1
阅读权限
10
注册时间
2012-12-26
最后登录
2014-11-3
4#
发表于 2014-1-22 17:29:37 |只看该作者
顶一下吧

使用道具 举报

Rank: 2

精华
0
UID
145242
积分
88
帖子
66
主题
4
阅读权限
30
注册时间
2012-11-7
最后登录
2015-2-18
5#
发表于 2014-1-22 21:39:48 |只看该作者
必须的

使用道具 举报

Rank: 1

精华
0
UID
172074
积分
1
帖子
1
主题
0
阅读权限
10
注册时间
2013-9-10
最后登录
2014-1-29
6#
发表于 2014-1-22 22:40:43 |只看该作者

使用道具 举报

Rank: 1

精华
0
UID
185332
积分
2
帖子
2
主题
0
阅读权限
10
注册时间
2014-4-22
最后登录
1970-1-1
7#
发表于 2014-4-22 13:14:37 |只看该作者
必须顶

使用道具 举报

Rank: 1

精华
0
UID
180147
积分
13
帖子
13
主题
0
阅读权限
10
注册时间
2014-2-7
最后登录
2014-6-17
8#
发表于 2014-5-1 23:01:47 |只看该作者

使用道具 举报

Rank: 1

精华
0
UID
184183
积分
5
帖子
5
主题
0
阅读权限
10
注册时间
2014-4-4
最后登录
2014-9-18
9#
发表于 2014-5-6 14:58:42 |只看该作者
谢谢楼主 发源代码之前有简介就好了

使用道具 举报

Rank: 1

精华
0
UID
180274
积分
1
帖子
1
主题
0
阅读权限
10
注册时间
2014-2-10
最后登录
2014-6-25
10#
发表于 2014-5-26 16:02:51 |只看该作者
支持无私源码

使用道具 举报

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

bottom

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

GMT+8, 2024-4-25 12:37

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部