[PEL] 复制代码
INPUT:N(50,1,100,1),SS(1,1,100,1),N_TMP(1.2,0.1,10,0.1),N_CMI(30,1,100,1),N_KD(9,1,100,1),M1(3,1,100,1),M2(3,1,100,1),MIND(30,1,100,1),STOPLOSS(3,1,100,1);
MAC:=MA(CLOSE,N);
TMP:=STD(CLOSE,N);
TOP:MAC+N_TMP*TMP;
BOTTOM:MAC-N_TMP*TMP;
CMI:ABS(CLOSE-REF(CLOSE,N_CMI-1))/(HHV(HIGH,N_CMI)-LLV(LOW,N_CMI))*100; //CMI指标,用于判断当前是震荡市,还是趋势市
RSV:=(CLOSE-LLV(LOW,N_KD))/(HHV(HIGH,N_KD)-LLV(LOW,N_KD))*100;
K:=SMA(RSV,M1,1);
D:=SMA(K,M2,1);
震荡平空开多条件:=K>D AND D<MIND AND BARPOS>N;
震荡平多开空条件:=K<D AND D>100-MIND AND BARPOS>N;
趋势开多条件:=C>TOP AND BARPOS>N;
趋势平多条件:=C<MAC AND BARPOS>N;
趋势开空条件:=C<BOTTOM AND BARPOS>N;
趋势平空条件:=C>MAC AND BARPOS>N;
IF CMI<20 THEN BEGIN
IF 震荡平空开多条件 THEN BEGIN
SELLSHORT(HOLDING<0,HOLDING,MARKET);
BUY(HOLDING=0,SS,MARKET);
END
IF 震荡平多开空条件 THEN BEGIN
SELL(HOLDING>0,HOLDING,MARKET);
BUYSHORT(HOLDING=0,SS,MARKET);
END
END
IF CMI>=20 THEN BEGIN
SELL(趋势平多条件 AND HOLDING>0,HOLDING,MARKET);
SELLSHORT(趋势平空条件 AND HOLDING<0,HOLDING,MARKET);
BUY(趋势开多条件 AND HOLDING=0,SS,MARKET);
BUYSHORT(趋势开空条件 AND HOLDING=0,SS,MARKET);
END
震荡多单止盈:=REF(CMI,ENTERBARS+1)<20 AND C>ENTERPRICE*(1+0.01*STOPLOSS*3) AND K<D;
震荡空单止盈:=REF(CMI,ENTERBARS+1)<20 AND C<ENTERPRICE*(1-0.01*STOPLOSS*3) AND K>D;
震荡多单止损:=REF(CMI,ENTERBARS+1)<20 AND C>ENTERPRICE*(1-0.01*STOPLOSS*3) AND K<D;
震荡空单止损:=REF(CMI,ENTERBARS+1)<20 AND C>ENTERPRICE*(1+0.01*STOPLOSS*3) AND K>D;
趋势多单止盈:=REF(CMI,ENTERBARS+1)>=20 AND C>ENTERPRICE*(1+0.01*STOPLOSS*3) AND C<MAC;
趋势空单止盈:=REF(CMI,ENTERBARS+1)>=20 AND C>ENTERPRICE*(1-0.01*STOPLOSS*3) AND C>MAC;
趋势多单止损:=REF(CMI,ENTERBARS+1)>=20 AND C>ENTERPRICE*(1-0.01*STOPLOSS*3) AND C<MAC;
趋势空单止损:=REF(CMI,ENTERBARS+1)>=20 AND C>ENTERPRICE*(1+0.01*STOPLOSS*3) AND C>MAC;
S1:SELL(震荡多单止盈 AND HOLDING>0,HOLDING,MARKET);
S2:SELLSHORT(震荡空单止盈 AND HOLDING<0,HOLDING,MARKET);
S3:SELL(震荡多单止损 AND HOLDING>0,HOLDING,MARKET);
S4:SELLSHORT(震荡空单止损 AND HOLDING<0,HOLDING,MARKET);
S5:SELL(趋势多单止盈 AND HOLDING>0,HOLDING,MARKET);
S6:SELLSHORT(趋势空单止盈 AND HOLDING<0,HOLDING,MARKET);
S7:SELL(趋势多单止损 AND HOLDING>0,HOLDING,MARKET);
S8:SELLSHORT(趋势空单止损 AND HOLDING<0,HOLDING,MARKET);