本帖最后由 技术009 于 2022-11-14 15:30 编辑
[PEL] 复制代码 variable:len1:=0,len2:=0;
ema30:ema(c,30),colorwhite;
ktxs:=ema30>ref(ema30,1) and ref(ema30,1)>ref(ema30,2);//拐头向上
ktxx:=ema30<ref(ema30,1) and ref(ema30,1)<ref(ema30,2);//拐头向下
if ktxs or (not(ktxs or ktxx) and len1<>0) then len1:=len1+1;//仅在红绿转换时候进行 拐头的切换,否则沿用最近的拐头方向,这样做是因为一个趋势中间个别突破的K会造成趋势断开。
if ktxx then len1:=0;
if ktxx or (not(ktxs or ktxx) and len2<>0) then len2:=len2+1;
if ktxs then len2:=0;
if ktxs or (not(ktxs or ktxx) and len1<>0) then red:ema30,colorred;
if ktxx or (not(ktxs or ktxx) and len2<>0) then green:ema30,colorgreen;
jc:cross(c,ema30);
sc:cross(ema30,c);
if count(sc,len1)<=2 and len1>0 and isup and sc then buy(holding=0,1,market);
if count(jc,len2)<=2 and len2>0 and isdown and jc then buyshort(holding=0,1,market);
hc:hhv(h,len1),nodraw;//多趋势最大的C
lc:llv(l,len2),nodraw;
if c>hc then dzy:sell(1,holding,market);
if c<lc then kzy:sellshort(1,holding,market);
if len2>0 then dzs:sell(1,holding,market);
if len1>0 then kzs:sellshort(1,holding,market);
做了调整:
然后就是 拐头切换时候会有1个K的延迟,这个无法解决。原因是 个别K情况下会出现既不是 上拐,也不是下拐的情况,这种情况不能直接全过滤掉,直接过滤否则会导致趋势在个别K上断开。也就是出现 红线-灰线-红线 或者绿线-灰线-绿线 情况。上面那个开多K 位置其实就是没过滤情况下的结果,否则那个地方其实不符合代码判断的拐头向上的条件,也不符合向下的条件。 |