老师您好,以下底背离开单代码,麻烦帮我换成顶背离开空单的,谢谢!
//MACD指标背离
DIFF := EMA(CLOSE,12) - EMA(CLOSE,26);
DEA := EMA(DIFF,9);
MACD := 2*(DIFF-DEA), COLORSTICK; //MACD原来的
gnum:=barslast(ref(macd>0,1) and macd<0);//红转绿
bnum:=barslast(ref(macd<0,1) and macd>0);//绿转红
if ref(macd,1)>0 and macd<0 then
begin
gsum:=0; //绿柱开始,清0
glong:=0; //绿柱开始,清0
glow:=low; //绿柱开始,初始化
end
if macd<0 then
begin
gsum:=gsum+macd; //累加
if abs(macd)>abs(glong) then glong:=macd;//如果绿柱更长,则记录
if low<glow then glow:=low; //如果价格更低,则记录
end
numb:=max(gnum,bnum)+1;
con1:=abs(gsum)<abs(ref(gsum,numb));//面积小于前一波--面积没创新低
con2:=abs(glong)<abs(ref(glong,numb));//柱子长度小于前一波----长度没创新低
con3:=glow<ref(glow,numb);//价格小于前一波-----价格创新低
{//当绿柱开始收缩时(熊市即将结束,可能反转向上(或低位盘整)),如果出现低背离,则少量建仓
if all(macd<0,3) and ref(macd,1)<macd and ref(macd,1)<ref(macd,2) then
begin
if con1 and con2 and con3 then buy(1,1,market);//低背离,面积没创新低,长度没创新低,价格创新低
end}
//绿柱消失、红柱开始放出时(下跌行情(或低位盘整)已经结束),如果出现低背离,则加仓
if ref(macd<0,1) and macd>0 then
begin
if con1 and con2 and con3 then M背加:buy(1,1,market);//低背离,面积没创新低,长度没创新低,价格创新低
end
//MACD指标背离
DIFF := EMA(CLOSE,12) - EMA(CLOSE,26);
DEA := EMA(DIFF,9);
MACD := 2*(DIFF-DEA), COLORSTICK; //MACD原来的
gnum:barslast(ref(macd>0,1) and macd<0);//红转绿 后到当前的数量
bnum:barslast(ref(macd<0,1) and macd>0);//绿转红 后到当前的数量
if ref(macd,1)<0 and macd>0 then
begin
ssum:=0; //红柱开始,清0
slong:=0; //红柱开始,清0
shigh:=high; //红柱开始,初始化
end
if macd>0 then
begin
ssum:=ssum+macd; //累加红柱
if abs(macd)>abs(slong) then slong:=macd; //如果红柱更惨,则记录红柱
if high>shigh then shigh:=high; //如果价格更高,则记录最高价
end
nums:=max(gnum,bnum)+1;
con4:abs(ssum)<abs(ref(ssum,nums)); //面积小于前一波--面积没创新低
con5:abs(slong)<abs(ref(slong,nums));//柱子长度小于前一波----长度没创新低
con6:shigh>ref(shigh,nums); //价格大于前一波-----价格创新高
if ref(macd>0,1) and macd<0 then
begin
if con4 and con5 and con6 then buyshort(1,1,market);//低背离,面积没创新低,长度没创新低,价格创新低
end