- 精华
- 0
- 在线时间
- 37 小时
- UID
- 247176
- 积分
- 162
- 帖子
- 72
- 阅读权限
- 0
- 注册时间
- 2017-2-14
- 最后登录
- 2017-5-18
- 精华
- 0
- UID
- 247176
- 积分
- 162
- 帖子
- 72
- 主题
- 68
- 阅读权限
- 0
- 注册时间
- 2017-2-14
- 最后登录
- 2017-5-18
|
回测标的:沪深300
回测区间:2012年1月1日至2016年11月11日
选股:选出当前处于100日低点的股票
进场:将资金等分为5份,将1份资金的1/7买入股票,当该股票下降10%时,追加买入1份资金的2/7。当股票再下降10%,追加买入1份资金的4/7。
出场: 止损出场:第三次加仓后再下降10%
止盈出场:无论第几次加仓,只要上涨10%,平仓止盈。
回测曲线:
策略代码:
function nsjctest(tc, lags)%
targetList = traderGetTargetList();
%获取目标资产信息
HandleList = traderGetHandleList();
%获取账户信息
%策略中每次取数据的长度
barnum=traderGetCurrentBar(targetList(1).Market,targetList(1).Code);
if(barnum<lags)
return;
end
global pricerecord
global buytime;
% [~,open2,~,~,close2,~,~,openinterest2] = traderGetKData(targetList(301).Market,targetList(301).Code,'day',1, 0-21, 0,true,'FWard');
% if(length(open2) < 21)
% return;
% end
%数据长度限制
% len1 = 5;
% len2 = 20;
len = 60;
for i = 1:50
[time,open,high,low,close,volume,~,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'day',1, 0-lags-3, 0,false,'FWard');
[ValidCash,~,~,~,~] = traderGetAccountInfo(HandleList(1));
valid = tc - sum(buytime == 1) * 3 / 7 / 5 * tc - sum(buytime == 2) * 4 / 7 / 5 * tc - sum(buytime == 3) / 5 * tc;
con3 = ValidCash >= valid;
if(length(close)>lags)
%con1 = mean(close(end-len+1:end)) > mean(close(end-len:end-1));
%[adx]=traderADX(14,14,targetList(i).Market,targetList(i).Code, 'day', 1, -50, 0,false, 'FWard');
%con1 = adx(end) < 20 && adx(end) > -20;
con1 = 1;
if buytime(i) == 0
con0 = close(end) < min(low(1:end-1)) * 1.1 && close(end) > min(low(1:end-1)) * 1;
if con0 && con1 && con3
shareNum = floor(tc / 5 / close(end) / 7 * 1 / 100) * 100;
if shareNum >= 100
orderID=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum,0,'market','buy');
pricerecord(i) = close(end);
buytime(i) = buytime(i) + 1;
end
end
end
if buytime(i) == 1 && close(end) < pricerecord(i) * 0.9 && con1 && con3
shareNum = floor(tc / 5 / close(end) / 7 * 2 / 100) * 100;
if shareNum >= 200
orderID=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum,0,'market','buy');
pricerecord(i) = close(end);
buytime(i) = buytime(i) + 1;
end
end
if buytime(i) == 2 && close(end) < pricerecord(i) * 0.9 && con1 && con3
shareNum = floor(tc / 5 / close(end) / 7 * 4 / 100) * 100 ;
if shareNum >= 400
orderID=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum,0,'market','buy');
pricerecord(i) = close(end);
buytime(i) = buytime(i) + 1;
end
end
if close(end) > pricerecord(i) * 1.1
traderSell (HandleList(1), targetList(i).Market,targetList(i).Code, 'all',0,'market','sell');
pricerecord(i) = 0;
buytime(i) = 0;
end
if (buytime(i) == 3 && close(end) < pricerecord(i) * 0.9) %|| (~con1 && close(end) < pricerecord(i) * 0.95)
traderSell (HandleList(1), targetList(i).Market,targetList(i).Code, 'all',0,'market','sell');
pricerecord(i) = 0;
buytime(i) = 0;
end
end
end
end
更多免费策略源码下载,请登录atrader社区-策略服务 进行下载 http://www.atrader.com.cn/stra.php |
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
|