里面的几个关键条件 是没有定义的
开仓条件:1;//初始开仓条件
条件2:1;//独立减仓条件
条件3:1;//加仓条件的一部分
条件4:1;//止盈离场条件
我建议你先不要用到自己的代码里去 用简单的开仓,减仓,平仓条件带入进去 校对下逻辑。
上面那几个条件 你可以先用些简单的代替下 比如均线金叉死叉 作为开仓条件 等
有可能理解上还存在偏差 或者逻辑有漏洞 你如果直接用你现在的条件把带入进去 出了问题 很难排查的。
[PEL] 复制代码
input:m(2,1,100,0.1),n(5,1,100,1);
variable:h1:=0,l1:=0;
variable:mark1:=0,dyx_l:=0;
开仓条件:1;//初始开仓条件
条件2:1;//独立减仓条件
条件3:1;//加仓条件的一部分
条件4:1;//止盈离场条件
st:h-l;
dyx:st>ref(hhv(st,10),1) and isup;//大阳线
//zf 是振幅
zf:100*(h-l)/ref(c,1);
//h20,l20: 20周期内,振幅大于m的K线的最高最低价
h20:=ref(hhv(if(zf>m,h,0),20),1);
l20:=ref(llv(if(zf>m,l,-100000),20),1);
if c<l1 then 多止损:sell(1,holding,market);
if 条件2 then 多减仓1:sell(1,1,market);
if 开仓条件 and holding=0 then
begin
buy(1,1,market);
//首次开仓记录 开仓前20周期的最高 最低价
h1:=h20;
l1:=l20;
end
len1:=sumbars(c>h1,2);//统计连续2次收盘价大于H1的周期跨度。如果当前这个周期跨度超过4(函数返回值这时候3)就是不满足的。同时满足周期跨度条件且当前K满足C<H1 则这个条件完全满足
len2:=sumbars(c<h1,2);
//多加仓条件的初始要求:“最高点连续2次以上,或者上破大于N点以后”
cd1:(len1<=3 and c>h1) or (c>h1+n*mindiff) ;
//多减仓条件
cd2:(len2<=3 and c<h1) or (c<h1-n*mindiff);
if cd1 and mark1=0 then mark1:=1;//满足cd1 后标记下来,等到价格回落到L1-H1区间时候 满足条件3就开仓
if cross(h1,c) and c>l1 and mark1=1 and 条件3 then
begin
多加仓:buy(1,1,market);
end
if cross(l1,c) or cross(c,h1) then mark1:=0;//当收盘价脱离l1-h1 区间时候重置为0
if dyx and cross(h,h1) then dyx_l:=l;
if cd2 or cross(dyx_l,c) then 多减仓2:sell(1,1,market);
if 条件4 and openprofit>5000 then 多止盈离场:sell(1,holding,market);//5000 止损平仓 |