[PEL] 复制代码
INPUT:N_DAY(30,1,100,1),N(0.1,0.1,10,0.1);
INPUT:SS(1,1,100,1);
NN:=BARSLAST(DATE<>REF(DATE,1))+1; //当天K线根数
LD:=HHV(NN,NN+62);
O_TODAY:=VALUEWHEN(NN=1,OPEN); //获取当天开盘价
H_TODAY:=HHV(HIGH,NN); //获取当天最高价
L_TODAY:=LLV(LOW,NN); //获取当天最低价
H_YESTERDAY:=REF(O_TODAY,NN); //获取前一天最高价
L_YESTERDAY:=REF(L_TODAY,NN); //获取前一天最低价
C_YESTERDAY:=REF(C,NN); //获取前一天收盘价
LENGTH:=N_DAY*LD;
DISTANCE:=MA(H_YESTERDAY-L_YESTERDAY,LENGTH);
ORB:=MIN(ABS(H_YESTERDAY-C_YESTERDAY),ABS(L_YESTERDAY-C_YESTERDAY));
BAND:=MAX(ORB,DISTANCE*N);
UPBAND:O_TODAY+BAND; //ORB上轨
DOWNBAND:O_TODAY-BAND; //ORB下轨
MAC:MA(CLOSE,LENGTH);
MAHH:MA(HHV(HIGH,LENGTH),LENGTH);
KD:CLOSE>UPBAND AND CLOSE>MAC AND CLOSE>MAHH; //开多条件
KK:CLOSE<DOWNBAND AND CLOSE<MAC AND CLOSE<MAHH; //开空条件
PD:CLOSE<MAC AND C<ENTERPRICE; //平多条件
PK:CLOSE>MAC AND C>ENTERPRICE; //平空条件
SELL(PD,HOLDING,MARKET);
SELLSHORT(PK,HOLDING,MARKET);
BUY(KD AND HOLDING=0,SS,MARKET);
BUYSHORT(KK AND HOLDING=0,SS,MARKET);
IF TIME>185500 THEN BEGIN //收盘前平仓
SELL(HOLDING>0,HOLDING,MARKET);
SELLSHORT(HOLDING<0,HOLDING,MARKET);
END