量化交易策略matlab交易方案,【每日一策】Matlab量化交易策略之 另类突破策略...

策略原理:

多头入场:当前价格大于前60个交易日到前20个交易日之间的最高价且当前价格大于65日均线

空头入场:当前价格小于前60个交易日到前20个交易日之间的最低价且当前价格小于65日均线

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

回测曲线:

08b05ce0d596c72a04d00d75c1365631.gif

2017-2-23 11:15:54 上传

下载附件 (81.75 KB)

策略代码:

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

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)

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)

if  default_exitway==1

sellcon=low(end)

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社区-策略服务下载~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值