MACD底背离时候开多,顶背离时候开空
背离时候结合前面一个底部或是顶部情况,联动K线符合即可。
请详细说明
开多情况:K线行情较前面30根K线比较有创出新低后,此时MACD,diff高于这30根K线周期内diff最低值,在之后的10根K线周期内MACD若出现金叉则开多。
平多: 在开多之后第一次出现死叉则平多
开空情况:K线行情较前面30根K线比较有创出新高后,此时MACD,diff低于这30根K线周期内diff最高值,在之后的10根K线周期内MACD若出现死叉则开空。
平空: 在开空之后第一次出现金叉则平空
variable:flag=0;
hi30:=ref(hhv(h,30),1);
lo30:=ref(llv(l,30),1);
diff:=ema(close,12) - ema(close,26);
dea:=ema(diff,9);
sc:=cross(dea,diff);
jc:=cross(diff,dea);
hi30_diff:=ref(hhv(diff,30),1);
lo30_diff:=ref(llv(diff,30),1);
if flag<>-1 and h>hi30 and diff<hi30_diff then begin
flag:=-1;
kpos:=barpos;
end
if flag<>1 and l<lo30 and diff>lo30_diff then begin
flag:=1;
kpos:=barpos;
end
if holding>0 and cross(dea,diff) then begin
sell(1,1,limitr,c);
flag:=0;
end
if holding<0 and cross(diff,dea) then begin
sellshort(1,1,limitr,c);
flag:=0;
end
if flag=1 and holding=0 then begin
if barpos-kpos<=10 and jc then begin
buy(1,1,limitr,c);
end
if barpos-kpos=10 then flag:=0;
end
if flag=-1 and holding=0 then begin
if barpos-kpos<=10 and sc then begin
buyshort(1,1,limitr,c);
end
if barpos-kpos=10 then flag:=0;
end
zichan:asset,noaxis;
if barpos=1 then begin
MaxAsset:=zichan;
hc:=0;
end
if zichan>MaxAsset then MaxAsset:=zichan;
if MaxAsset-zichan>hc then hc:=MaxAsset-zichan;
Maxhc:hc,linethick0;
交易次数:totaltrade,linethick0;
正确率:percentwin,linethick0;
你看看行不行
variable:b1=0,b2=0;
input:P(26,20,100,8),S(12,5,40,4),M(9,2,60,6);
DIFF := EMA(CLOSE,S) - EMA(CLOSE,P);
DEA := EMA(DIFF,M);
MACD1 := 2*(DIFF-DEA), COLORSTICK;
if l<ref(llv(l,30),1) and diff>ref(llv(l,30),1) then b1:=BARPOS;
if BARPOS-b1<10 and diff>MACD1 then
begin
sellshort(holding<0,0,market);
buy(holding=0,1,market);
end
if TYPE(1)=1 and diff<MACD1 then sell(holding>0,0,market);
if H>ref(hhv(h,30),1) and diff<ref(hhv(h,30),1) then b2:=BARPOS;
if BARPOS-b1<10 and diff<MACD1 then
begin
sell(holding>0,0,market);
buyshort(holding=0,1,market);
end
if TYPE(1)=3 and diff<MACD1 then sellshort(holding<0,0,market);