- 精华
- 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
|
策略原理:
以移动平滑均线定义鳄鱼的颚,牙齿和上唇
寻找机会:必须在鳄鱼睡着(最好是沉睡一阵子的鳄鱼,即BRG三线接近或相互纠缠)时进入市场。在市场建立仓位后,根据混沌法则不断加码。在价格未脱离鳄鱼上唇或下颚时不要主观判断方向。
进场:寻找有效碎形,在有效碎形的高/低点加/减一档作为买/卖的参考价位。并非所有有效讯号都能获利。
止损:以鳄鱼的牙齿(红线)作为依据,进场买入时若收盘价低于红线则停损出场,指初期进场时的止损。
加仓:第一个有效碎形触发后,建立原始仓位。之后可根据AC,AO等指标同向进场,例如价格在红线之上一直买入。也可以沿途不做任何加码动作。
出场:收盘低于鳄鱼牙齿(红线)或者鳄鱼上唇(绿线);出场价格在5根连续相同颜色的bar的低点加一档;AO、AC、碎形的反向讯号。
策略代码:
function Strategy1(default_unit,default_exitway,freq)%
targetList = traderGetTargetList();
%获取目标资产信息
HandleList = traderGetHandleList();
%获取账户句柄
global enterprice;
global enterbar;
for k=1:length(targetList);
%--------------------仓位、K线、当前bar的提取-----------------------------%
%获取当前仓位
[marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);
%策略中每次取数据的长度
lags=80;
% dlags=10;
barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code);
%数据长度限制
if(barnum<lags)
continue;
end
%获取K线数据
[time,open,high,low,close,volume,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-lags, 0,false,'FWard');
% [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'day',1, 0-dlags, 0,false,'FWard');
if length(close)<lags
continue;
end;
%-------------------------交易逻辑-------------------------------%
%----------入场信号--------------------%
unit=1;
price=(high+low)/2;
bline=ma(price(1:end-8+1),13);
rline=ma(price(1:end-5+1),8);
gline=ma(price(1:end-3+1),5);
price=price(8:end);
high=high(8:end);
low=low(8:end);
close=close(8:end);
rline=rline(4:end);
gline=gline(6:end);
AO=ma(price,5)-ma(price,34);
AC=ma((AO-ma(AO,5)),5);
% 判断鳄鱼是否在睡觉
state=zeros(length(gline),1);
for i=1:length(state)
if bline(i)>rline(i) && rline(i)>gline(i) % 空头排列
state(i)=-1;
elseif bline(i)<rline(i) && rline(i)<gline(i) % 多头排列
state(i)=1;
else % 非趋势排列
state(i)=0;
end;
end;
sleepinterval=10;
issleep=ones(length(gline),1);
for i=sleepinterval:length(issleep)
vector=state(i-sleepinterval+1:i);
if sum(vector)==sleepinterval || sum(vector)==-sleepinterval
issleep(i)=0;
end;
end;
len=30; % 考察区间
con1=sum(issleep(end-len+1:end))==len; % 连续len个bar鳄鱼是睡着的
% 寻找最近的向上碎形,与向下碎形
i=length(high)-2;
upsx=[];
while i>=length(high)-len+3
if high(i)>max(high(i+1:i+2)) && high(i)>max(high(i-2:i-1)) && high(i)>bline(i) % 有效向上碎形
upsx=[upsx;i];
end;
i=i-1;
end;
i=length(high)-2;
dnsx=[];
while i>=length(high)-len+3
if low(i)<min(low(i+1:i+2)) && low(i)<min(low(i-2:i-1)) && low(i)<bline(i) % 有效向下碎形
dnsx=[dnsx;i];
end;
i=i-1;
end;
% 开仓条件:沉睡的鳄鱼,突破上碎形/下碎形
buycon=0;
sellshortcon=0;
if ~isempty(upsx) && con1
upline=max(high(upsx));
buycon=close(end)>upline && close(end-1)<upline;
end;
if ~isempty(dnsx) && con1
dnline=min(low(dnsx));
sellshortcon=close(end)<dnline && close(end-1)>dnline;
end;
sellcon=close(end)<rline(end);
buytocovercon=close(end)>rline(end);
% TRvalue=TR(close,high,low);
% ATR=ma(TRvalue,20);
% p=2;
% barsinceentry=barnum-enterbar;
% [~,entryopen,entryhigh,entrylow,entryclose,~,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-barsinceentry, 0,false,'FWard');
% highvalue=max(entryhigh(1:end-1));
% lowvalue=min(entrylow(1:end-1));
% sellcon=close(end)<highvalue-p*ATR(end-1);
% buytocovercon=close(end)>lowvalue+p*ATR(end-1);
if buytocovercon && marketposition<0
orderID1=traderBuyToCover(HandleList(1),targetList(k).Market,targetList(k).Code,'all',0,'market','buy');
if orderID1==0
continue;
end;
end;
if sellcon && marketposition>0
orderID1=traderSell(HandleList(1),targetList(k).Market,targetList(k).Code,'all',0,'market','sell');
if orderID1==0
continue;
end;
end;
if buycon && marketposition<=0
orderID1=traderBuy(HandleList(1),targetList(k).Market,targetList(k).Code,unit,0,'market','buy');
if orderID1==0
continue;
end;
enterprice=close(end);
enterbar=barnum;
end;
if sellshortcon && marketposition>=0
orderID1=traderSellShort(HandleList(1),targetList(k).Market,targetList(k).Code,unit,0,'market','sellshort');
if orderID1==0
continue;
end;
enterprice=close(end);
enterbar=barnum;
end;
end
end
更多免费策略源码下载请登录atrader社区-策略服务,http://www.atrader.com.cn/stra.php
鳄鱼交易法则策略源码下载:http://www.atrader.com.cn/stra.php?mod=model&pid=141 |
|