[PEL] 复制代码
INPUT:SS(1000,100,10000,100);
GLOBALVARIABLE:PCCON1=0,PCCON1_1=0; //平仓条件1每日平仓控制
GLOBALVARIABLE:PCCON2=0,PCCON2_1=0; //平仓条件2每日平仓控制
GLOBALVARIABLE:PCCON3=0; //平仓条件3每日平仓控制
REF_VOL:"$VOL##DAY"; //昨日成交量
KDCON1:SUM(VOL,TODAYBAR)>=REF_VOL*0.8;
KDCON2:(C-REF(C,20))/REF(C,20)>=0.03;
KDCON3:(C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.06 AND (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)<=0.08;
KDCON4:TIME>=094500 AND TIME<=145600;
ZT:(C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.1; //这是简单的涨停定义,可以根据你的需要自行定义
PCSS:IF(TBUYHOLDINGEX('','',0)>0 AND INTPART(TBUYHOLDINGEX('','',0)/3)>100,INTPART(TBUYHOLDINGEX('','',0)/3),100); //平仓手数
IF KDCON1 AND KDCON2 AND KDCON3 AND KDCON4 THEN
TBUY(TBUYHOLDINGEX('','',2)=0,SS,MKT);
//平仓条件1逻辑
IF REF(OPEN,TODAYBAR-1)>=REF(C,TODAYBAR) AND (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.03 AND PCCON1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1:=1;
END
IF REF(OPEN,TODAYBAR-1)>=REF(C,TODAYBAR) AND (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.05 AND PCCON1_1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1_1:=1;
END
IF TIME>145600 AND ZT=0 THEN //145600之后,不涨停就清仓
TSELL(TBUYHOLDINGEX('','',0)>0,0,MKT);
//平仓条件2逻辑
IF REF(OPEN,TODAYBAR-1)<REF(C,TODAYBAR) AND PCCON2=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT); //低开,平1/3
PCCON2:=1;
END
IF REF(OPEN,TODAYBAR-1)<REF(C,TODAYBAR) AND PCCON2=1 AND TIME>=103000 AND C>REF(C,TODAYBAR) THEN BEGIN
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.03 AND PCCON1=0 THEN BEGIN //平仓条件2,在103000若上涨,按条件1平仓
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1:=1;
END
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.05 AND PCCON1_1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1_1:=1;
END
END
IF REF(OPEN,TODAYBAR-1)<REF(C,TODAYBAR) AND PCCON2=1 AND TIME>=103000 AND C<REF(C,TODAYBAR) THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT); //平仓条件2,在103000若下跌,平仓1/3
PCCON2_2:=1;
END
IF PCCON2_2=1 THEN BEGIN //平仓条件2,在103000若下跌,平仓1/3后,按条件1平仓
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.03 AND PCCON1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1:=1;
END
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.05 AND PCCON1_1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1_1:=1;
END
END
//平仓条件3逻辑
IF REF(O,TODAYBAR-1)>=REF(C,TODAYBAR) AND C<REF(C,TODAYBAR) AND PCCON3=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT); //平空或高开,股价下跌昨收,平1/3
PCCON3:=1;
END
IF PCCON3=1 THEN BEGIN //条件3平1/3后,按条件1平仓
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.03 AND PCCON1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1:=1;
END
IF (C-REF(C,TODAYBAR))/REF(C,TODAYBAR)>=0.05 AND PCCON1_1=0 THEN BEGIN
TSELL(TBUYHOLDINGEX('','',0)>0,PCSS,MKT);
PCCON1_1:=1;
END
END
IF DATE<>REF(DATE,1) THEN BEGIN //每一天,初始化平仓的次数
PCCON1:=0;
PCCON1_1:=0;
PCCON2:=0;
PCCON2_1:=0;
PCCON3:=0;
END