设为首页收藏本站

 找回密码
 注册
查看: 2472|回复: 0

另类突破策略(附源码) [复制链接]

精华
0
UID
247176
积分
162
帖子
72
主题
68
阅读权限
0
注册时间
2017-2-14
最后登录
2017-5-18
发表于 2017-2-17 10:31:39 |显示全部楼层
策略名称:另类突破策略

策略原理:
         多头入场:当前价格大于前60个交易日到前20个交易日之间的最高价且当前价格大于65日均线
         空头入场:当前价格小于前60个交易日到前20个交易日之间的最低价且当前价格小于65日均线

         出场:采取动态跟踪止损出场

回测曲线:




策略代码:

function  Strategy1(default_unit,default_exitway,freq)%
targetList  =  traderGetTargetList();  
%获取目标资产信息
HandleList  =  traderGetHandleList();
%获取账户句柄
global  entrybar;
for  k=1:length(targetList);
        
        %--------------------仓位、K线、当前bar的提取-----------------------------%
        %获取当前仓位
        [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);
        %策略中每次取数据的长度
        lags=80;
        barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code);
        %数据长度限制
        if(barnum<lags)
                continue;
        end
        %获取K线数据
        [time,open,high,low,close,volume,turnover,openinterest]  =  traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq,  0-lags,  0,false,'FWard');
        if  length(close)<lags
                continue;
        end;      
        %-------------------------交易逻辑-------------------------------%
        %----------入场信号--------------------%
        len1=20;
        len2=40;
        ma0=ma(close,65);
        buycon=close(end)>max(high(end-len2-len1+1:end-len1))  &&  close(end)>ma0(end);
        sellshortcon=close(end)<min(low(end-len2-len1+1:end-len1))  &&  close(end)<ma0(end);
        if  default_exitway==1
                sellcon=low(end)<min(low(end-20:end-1));
                buytocovercon=high(end)>max(high(end-20:end-1));
        elseif  default_exitway==2
                TRvalue=TR(close,high,low);
                ATR=ma(TRvalue,4);
                barsinceentry=barnum-entrybar(k);
                [~,entryopen,entryhigh,entrylow,entryclose,~,~,~]  =  traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq,  0-barsinceentry,  0,false,'FWard');
                range=8*ATR(end-1);
                [sellcon,buytocovercon]=exitway1(entryopen,entryclose,entryhigh,entrylow,marketposition,range);
        elseif  default_exitway==3
                TRvalue=TR(close,high,low);
                ATR=ma(TRvalue,4);
                std0=stdev(close,60);
                barsinceentry=barnum-entrybar(k);
                [~,entryopen,entryhigh,entrylow,entryclose,~,~,~]  =  traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq,  0-barsinceentry,  0,false,'FWard');
                range=6*ATR(end-1);
                stopgap=std0(end);
                [sellcon,buytocovercon]=exitway4(entryopen,entryclose,entryhigh,entrylow,marketposition,range,stopgap);
        end;
        %---------------------------入场操作--------------------------------%
        if  sellcon  &&  marketposition>0
                orderID1=traderPositionTo(HandleList(1),targetList(k).Market,targetList(k).Code,0,0,'market','sell');
                if  orderID1==0
                        continue;
                end;
        end;
        if  buytocovercon  &&  marketposition<0
                orderID2=traderPositionTo(HandleList(1),targetList(k).Market,targetList(k).Code,0,0,'market','sell');
                if  orderID2==0
                        continue;
                end;
        end;
        if  buycon  &&  marketposition==0
                buyunit=default_unit;
                orderID3=traderBuy(HandleList(1),targetList(k).Market,targetList(k).Code,buyunit,0,'market','buy');
                if  orderID3==0
                        continue;
                end;
                entrybar(k)=barnum;
        end;
        if  sellshortcon  &&  marketposition==0
                sellshortunit=default_unit;
                orderID4=traderSellShort(HandleList(1),targetList(k).Market,targetList(k).Code,sellshortunit,0,'market','sell');
                if  orderID4==0
                        continue;
                end;
                entrybar(k)=barnum;
        end;  
end
end


更多免费策略下载 请登录 atrader社区-策略服务 下载,http://www.atrader.com.cn/stra.php

另类突破策略源码下载:http://www.atrader.com.cn/stra.php?mod=model&pid=147
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
您需要登录后才可以回帖 登录 | 注册

bottom

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

GMT+8, 2024-3-29 05:09

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部