HHLL策略 附源码
策略思路:多头条件:最高价大于前一段时间的最高价,且最低价大于前一段时间的最低价
空头条件:最高价小于前一段时间的最高价,且最低价小于前一段时间的最低价
策略源码:
function HHLL(lags,freq,stopgap,trailinggap,shareNum)
%高高低低
global score1;
targetList = traderGetTargetList();
HandleList = traderGetHandleList();
=traderGetAccountPosition(HandleList(1),targetList(1).Market,targetList(1).Code);
= traderGetCurrentBar(targetList(1).Market,targetList(1).Code);
= traderGetKData(targetList(1).Market,targetList(1).Code,'min',freq, 0-lags, 0,false,'FWard');
con11=0;con12=0;
if isempty(score1)
score1.time(1)=BarTime;
score1.high(1)=BarHigh;
score1.low(1)=BarLow;
else
len1=length(score1.high);
if len1==1
if (BarLow<score1.low(1) )
if (BarHigh<score1.high(1) )
score1.time(1+1)=BarTime;
score1.high(1+1)=BarHigh;
score1.low(1+1)=BarLow;
else
score1.time(1)=BarTime;
score1.high(1)=BarHigh;
score1.low(1)=BarLow;
end
elseif (BarLow>=score1.low(1) )
if (BarHigh>score1.high(1) )
con11=1;
score1.time(1+1)=BarTime;
score1.high(1+1)=BarHigh;
score1.low(1+1)=BarLow;
end
end
else
if (score1.low(len1)<score1.low(len1-1) )
if (BarLow<score1.low(len1) )
if (BarHigh<score1.high(len1) )
score1.time(len1+1)=BarTime;
score1.high(len1+1)=BarHigh;
score1.low(len1+1)=BarLow;
else
score1.time(len1)=BarTime;
score1.high(len1)=BarHigh;
score1.low(len1)=BarLow;
end
elseif (BarLow>=score1.low(len1) )
if (BarHigh>score1.high(len1) )
con11=1;
score1.time(len1+1)=BarTime;
score1.high(len1+1)=BarHigh;
score1.low(len1+1)=BarLow;
end
end
elseif (score1.high(len1)>score1.high(len1-1) )
if (BarHigh>score1.high(len1) )
if (BarLow>score1.low(len1) )
score1.time(len1+1)=BarTime;
score1.high(len1+1)=BarHigh;
score1.low(len1+1)=BarLow;
else
score1.time(len1)=BarTime;
score1.high(len1)=BarHigh;
score1.low(len1)=BarLow;
end
elseif (BarHigh<=score1.high(len1) )
if (BarLow<score1.low(len1) )
con12=1;
score1.time(len1+1)=BarTime;
score1.high(len1+1)=BarHigh;
score1.low(len1+1)=BarLow;
end
end
end
end
end
if marketposition <=0 && con11
% fprintf('%s 买 %s %s %d手 市价\n',datestr(BarTime),targetList(1).Market,targetList(1).Code,shareNum);
orderID1=traderDirectBuy(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','buy1');
end
if marketposition >= 0 && con12
% fprintf('%s 卖 %s %s %d手 市价\n',datestr(BarTime),targetList(1).Market,targetList(1).Code,shareNum);
orderID2=traderDirectSell(HandleList(1),targetList(1).Market,targetList(1).Code,shareNum,0,'market','sell1');
end
end
更多免费策略源码下载请登录DigQuant社区-策略资源下载~ http://www.digquant.com.cn/stra.php
HHLL策略源码下载:http://www.digquant.com.cn/stra.php?mod=model&pid=57
页:
[1]