另类突破策略(附源码)
策略原理:多头入场:当前价格大于前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的提取-----------------------------%
%获取当前仓位
=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线数据
= 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);
=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);
=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 不能编译
页:
[1]