楼主: 挖矿专家
4996 13

[源码分享] MATLAB量化交易策略源码分享之 布林通道+高低点 [推广有奖]

  • 0关注
  • 74粉丝

讲师

22%

还不是VIP/贵宾

-

威望
0
论坛币
2016 个
通用积分
5.2622
学术水平
21 点
热心指数
21 点
信用等级
21 点
经验
6055 点
帖子
403
精华
0
在线时间
151 小时
注册时间
2017-2-8
最后登录
2017-6-27

楼主
挖矿专家 发表于 2017-2-27 10:13:01 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
策略原理:
          通过布林带以及突破后的高低点的形成产生交易信号
          采取跟踪止损出场


回测曲线:


布林带通道+高低点.png

策略代码:

function  Strategy1(default_unit,default_exitway,freq)%


targetList  =  traderGetTargetList();  

%获取目标资产信息

HandleList  =  traderGetHandleList();

%获取账户句柄

global  entry;

global  record;

global  stopprice;

global  boll;

for  k=1:length(targetList);


        %--------------------仓位、K线、当前bar的提取-----------------------------%

        %获取当前仓位

        [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);

        %策略中每次取数据的长度

        dlags=10;

        lags=60;

        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');

%          [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,Dturnover,Dopeninterest]  =  traderGetKData(targetList(k).Market,targetList(k).Code,'day',1,0-dlags,  0,false,'FWard');

        if  length(close)<lags

                continue;

        end;


        %-------------------------交易逻辑-------------------------------%

        %----------入场信号--------------------%

        len=30;

        p=2.5;

        p2=0;

        percent=0.1;

        percent2=0.5;

        ma0=ma(close,len);

        std0=stdev(close,len);

        upline=ma0+p*std0;

        dnline=ma0-p*std0;

        upline2=ma0+p2*std0;

        dnline2=ma0-p2*std0;

        s(1).buycon=0;

        s(1).sellshortcon=0;

        if  boll.switch==0;

                if  close(end)>upline(end)

                        boll.num=boll.num+1;

                        boll.value(boll.num)=close(end);

                        boll.switch=1;

                elseif  close(end)<dnline(end)

                        boll.num=boll.num+1;

                        boll.value(boll.num)=close(end);

                        boll.switch=-1;

                end;

        elseif  boll.switch==1;

                if  close(end)>upline(end)  &&  close(end)>boll.value(boll.num)

                        boll.value(boll.num)=close(end);

                elseif  close(end)<dnline(end)

                        boll.num=boll.num+1;

                        boll.value(boll.num)=close(end);

                        boll.switch=-1;

                end;

        elseif  boll.switch==-1;

                if  close(end)<dnline(end)  &&  close(end)<boll.value(boll.num)

                        boll.value(boll.num)=close(end);

                elseif  close(end)>upline(end)

                        boll.num=boll.num+1;

                        boll.value(boll.num)=close(end);

                        boll.switch=1;

                end;

        end;

        if  length(boll.value)>=2;

                if  record==1

                        con1=boll.value(end)<boll.value(end-1);

                        con2=close(end)>(boll.value(end-1)-boll.value(end))*percent+boll.value(end);

                        s(1).buycon=con1  &&  con2;

                end;

                if  record==-1

                        con3=boll.value(end)>boll.value(end-1);

                        con4=close(end)<-(boll.value(end)-boll.value(end-1))*percent+boll.value(end);

                        s(1).sellshortcon=con3  &&  con4;

                end;

        end;

        %------------被动出场操作------------------%

        %找到未平仓的订单

        remain=remainorder(entry,k);

        %对未平仓的订单进行平仓判断及操作

        for  i=1:length(remain.entrybar);

                %  进仓以来的bar个数

                longstopcon=0;

                shortstopcon=0;

                barsinceentry=barnum-remain.entrybar(i);

                backlen=50;        %  回溯的长度(进仓bar之前)

                %  回溯的信息提取

                [backtime,backopen,backhigh,backlow,backclose,~,~,~]  =  traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq,  0-barsinceentry-backlen,  0,false,'FWard');

                %  根据出场方式计算出场条件

                if  remain.entryexitway(i)==1;

                        AFinitial=0;

                        AFparam=0.02;

                        AFmax=0.2;

                        Firstbarmultp=1;    %影响第一根bar的止损价,调高表示可忍受的回撤越多

                        [longstopcon,shortstopcon,exitline]=exit1(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,AFinitial,AFparam,AFmax,Firstbarmultp);

                elseif  remain.entryexitway(i)==2;

                        initialATRparam=3;

                        AF=0.1;

                        minATRparam=1;

                        [longstopcon,shortstopcon,exitline]=exit2(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,initialATRparam,AF,minATRparam);

                elseif  remain.entryexitway(i)==3;

                        [longstopcon,shortstopcon,exitline]=exit3(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen);

                elseif  remain.entryexitway(i)==4

                        startpoint=10;

                        percent=0.3;

                        TRmutlp=1;

                        [longstopcon,shortstopcon,exitline]=exit4(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,startpoint,percent,TRmutlp);

                elseif  remain.entryexitway(i)==5;

                        stdlen=20;

                        initialstdparam=3;

                        minstdparam=1;

                        AF=0.25;

                        [longstopcon,shortstopcon,exitline]=exit5(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,stdlen,initialstdparam,minstdparam,AF);  

                elseif  remain.entryexitway(i)==6;

                        longstopcon=0;

                        shortstopcon=0;

                        sellcon=0;

                        buytocovercon=0;

                        if  remain.entrydirection(i)==1;

                                sellcon=high(end)>upline2(end);

                                longstopcon=close(end)<stopprice;

                        elseif  remain.entrydirection(i)==-1

                                buytocovercon=low(end)<dnline2(end);

                                shortstopcon=close(end)>stopprice;

                        end;

                        longstopcon=longstopcon  ||  sellcon;

                        shortstopcon=shortstopcon  ||  buytocovercon;

                elseif  remain.entryexitway(i)==7;

                        ATRparam=1.5;

                        [longstopcon,shortstopcon,exitline]=exit7(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,len,stopprice,p2,ATRparam);

                elseif  remain.entryexitway(i)==8;

                        ATRparam=1.5;

                        [longstopcon,shortstopcon,exitline]=exit8(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,len,stopprice,p2,ATRparam);

%                          sellcon=0;

%                          buytocovercon=0;

%                          if  remain.entrydirection(i)==1;

%                                  sellcon=high(end)>upline(end);

%                                  longstopcon=close(end)<stopprice.loss;

%                          elseif  remain.entrydirection(i)==-1

%                                  buytocovercon=low(end)<dnline(end);

%                                  shortstopcon=close(end)>stopprice.loss;

%                          end;

%                          longstopcon=longstopcon  ||  sellcon;

%                          shortstopcon=shortstopcon  ||  buytocovercon;

                end;



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

下载Auto-trader软件助您成为策略开发高手,现在下载还送3年免费分时数据~

下载地址:http://www.atrader.com.cn/software.php



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:通道

本帖被以下文库推荐

沙发
yditjn 发表于 2017-2-27 18:32:14
策略说明

藤椅
ghjktdf 发表于 2017-2-28 12:20:54
详细策略代码及说明可以登录atrader社区-策略服务查看

板凳
挖矿专家 发表于 2017-3-1 11:16:35
楼上正解~

报纸
65425856 发表于 2017-3-1 16:20:16
我看这社区已经有104个策略了。。。强

地板
peppep 发表于 2017-3-2 14:44:54
谢谢分享~~

7
挖矿专家 发表于 2017-3-3 10:33:56
65425856 发表于 2017-3-1 16:20
我看这社区已经有104个策略了。。。强
感谢支持,现在都是免费下载的

8
挖矿专家 发表于 2017-3-3 10:36:56
65425856 发表于 2017-3-1 16:20
我看这社区已经有104个策略了。。。强
感谢支持,目前都是免费的

9
ghjktdf 发表于 2017-3-3 14:32:55
挖矿专家 发表于 2017-3-3 10:33
感谢支持,现在都是免费下载的
是嘛,我去试下

10
peppep 发表于 2017-3-3 15:58:40
挖矿专家 发表于 2017-3-3 10:33
感谢支持,现在都是免费下载的
OKokokok

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

本版微信群
加好友,备注jr
拉您进交流群
GMT+8, 2026-1-28 17:29