开拓者期货期权程序化系统交易论坛

标题: 突破型日内交易策略源码 [打印本页]

作者: ssj918918    时间: 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

作者: charlie830    时间: 2014-1-17 14:05:08

有源码的都要顶!

作者: wenhaoen    时间: 2014-1-19 13:16:41

顶你
作者: qustzhl    时间: 2014-1-22 17:29:37

顶一下吧
作者: luofeid    时间: 2014-1-22 21:39:48

必须的
作者: bahu8888    时间: 2014-1-22 22:40:43


作者: lhxhuishang    时间: 2014-4-22 13:14:37

必须顶

作者: cswave    时间: 2014-5-1 23:01:47


作者: liuzifanok    时间: 2014-5-6 14:58:42

谢谢楼主 发源代码之前有简介就好了
作者: tzr002    时间: 2014-5-26 16:02:51

支持无私源码
作者: mm000yy    时间: 2015-1-1 12:23:57

这代码是不是有错啊?搞不懂
作者: hhkj168    时间: 2015-7-24 02:05:28

大大顶你了
作者: zengwenjian    时间: 2015-10-8 15:56:05

谢谢楼主分享啊

作者: DocterWU    时间: 2015-10-8 17:05:42


作者: fzzq71670238    时间: 2015-10-8 19:23:45


作者: xxhq100tb    时间: 2016-2-19 20:33:17

支持!
作者: banhot    时间: 2016-3-16 13:14:38

感谢分享
作者: 陈九    时间: 2016-4-30 13:02:47

怎么不对呢
作者: hs175731    时间: 2016-5-5 18:51:49

顶!虽然看不懂。。。。。。
作者: maxulun    时间: 2019-10-25 12:35:16

海龟~~~~~~~~~~~~




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2