上轨,公式:UPBAND^^O_TODAY+BAND; 下轨,公式:DOWNBAND^^O_TODAY-BAND;
(*backtest start: 2018-03-01 00:00:00 end: 2018-09-30 00:00:00 period: 1d exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}] args: [["ContractType","rb888",126961]] *) NN:=BARSLAST(DATE<>REF(DATE,1))+1; LENGTH_DAY:=HHV(NN,NN+62); O_TODAY:=VALUEWHEN(NN=1,OPEN); H_TODAY:=HHV(HIGH,NN); L_TODAY:=LLV(LOW,NN); H_YESTERDAY:=REF(H_TODAY,NN); L_YESTERDAY:=REF(L_TODAY,NN); C_YESTERDAY:=REF(C,NN); LENGTH:=N_DAY*LENGTH_DAY; DISTANCE:=MA(H_YESTERDAY-L_YESTERDAY,LENGTH); ORB:=MIN(ABS(H_YESTERDAY-C_YESTERDAY),ABS(L_YESTERDAY-C_YESTERDAY)); BAND:=MAX(ORB,DISTANCE*0.1); UPBAND^^O_TODAY+BAND; DOWNBAND^^O_TODAY-BAND; MAC^^MA(CLOSE,LENGTH); MA_HH^^MA(HHV(HIGH,LENGTH),LENGTH); MA_LL^^MA(LLV(LOW,LENGTH),LENGTH); BUYPK:=CLOSE>UPBAND AND CLOSE>MAC AND CLOSE>MA_HH; SELLPK:=CLOSE<DOWNBAND AND CLOSE<MAC AND CLOSE<MA_LL; SELLY:=CLOSE<MAC AND CLOSE>BKPRICE; BUYY:=CLOSE>MAC AND CLOSE<SKPRICE; IF BARPOS>LENGTH THEN BEGIN BKVOL=0 AND BUYPK,BPK; SKVOL=0 AND SELLPK,SPK; END SELLY,SP(BKVOL); BUYY,BP(SKVOL);