[PEL] 复制代码
//中间变量
variable:zs=c,maxhl=c,maxlow=c;
//顾比倒数线
DISTL:=NEWLBARS(L,1);
DISTH:=NEWHBARS(H,1);
HI20:=REF(HHV(H,20),1);
LO20:=REF(LLV(L,20),1);
GBD1:=REF(L,DISTL);
GBD2:=REF(GBD1,DISTL);
GBD:=IF(GBD2>0,MAX(LLV(L,20),GBD2),LLV(L,20));
GBG1:=REF(H,DISTH);
GBG2:=REF(GBG1,DISTH);
GBG:=IF(GBG2>0,MIN(HHV(H,20),GBG2),HHV(H,20));
//SAR指标
Sar1:SAR(10,2,20),CIRCLEDOT;
//MACD指标
DIFF := EMA(CLOSE,12) - EMA(CLOSE,26);
DEA := EMA(DIFF,9);
MACD := 2*(DIFF-DEA);
//交易条件
con1:=any(ref(Sar1>high,1) and Sar1<high,3)=1; //最近3周期,有SAR向上突破K线
con2:=any(cross(diff,dea),3)=1 and diff<5; //最近3周期,MACD在0线附近金叉
//下单模块
//止盈止损平仓:下破移动止损线后离场
if holding>0 and (low<zs) then sell(1,1,marketr);if holding<0 and (high>zs) then sellshort(1,1,marketr);
//开多仓:SAR向上突破K线,MACD在0线附近金叉
if con1 and con2 and holding=0 then
begin
buy(1,1,market);
zs:=GBD; //调用顾比倒数低点连线做为多单止损
maxhl:=high; //记录当时的高点
end
//开空仓,开空条件请自行添加
if 开空条件 and holding=0 then
begin
buyshort(1,1,market);
zs:=GBG; //调用顾比倒数高点连线做为空单止损
maxlow:=low; //记录当时的低点
end
if holding>0 and high>maxhl and GBD>zs then //顾比低点创新高后,重新定位离场位,以实现多头浮动止损
begin
zs:=GBD;
maxhl:=high;
end
if holding<0 and low<maxlow and GBG<zs then //顾比高点创新低后,重新定位离场位,以实现空头浮动止损
begin
zs:=GBG;
maxlow:=low;
end
止损线:zs;