程序化交易模型源码:
{K:10,M:5}
A:=SUM( IF(CLOSE>REF(CLOSE,1), VOL/CLOSE,0), K); 当收大于昨收时成交量 / 收盘价的K周期的的总和
B:=SUM( IF(CLOSE<REF(CLOSE,1), VOL/CLOSE,0), K); 当收小于昨收时成交量 / 收盘价的K周期的的总和
D:=(A - B); {两者之差值}
G:=MA( (A-B), M); { 的均线 }
CROSS(D,G),BK; {差值上穿其均线, 买开 }
CROSS(G,D),SP; { 下穿 卖开}
CROSS(G,D),SK; { 下穿 卖平 }
CROSS(D,G),BP; { 上穿 买平 }
=========================================================================
PEAKBARS(MA(CLOSE,20),10,1,0)=1,SPK;
TROUGHBARS(MA(CLOSE,20),10,1,0)=1,BPK;
H:=HIGH;
L:=LOW;
A:=IF(HIGH>=REF(HIGH,1)&&HIGH>=REF(HIGH,2)&&HIGH>=REF(HIGH,3),LOW,0);
B:=IF(LOW<=REF(LOW,1)&&LOW<=REF(LOW,2)&&LOW<=REF(LOW,3),HIGH,888888);
P1:=IF(A>REF(L,1),REF(L,1),0);
P2:=IF(A>REF(L,2)&&A<=REF(L,1),REF(L,2),0);
P3:=IF(A>REF(L,3)&&A<=REF(L,1)&&A<=REF(L,2),REF(L,3),0);
P4:=IF(A>REF(L,4)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3),REF(L,4),0);
P5:=IF(A>REF(L,5)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4),REF(L,5),0);
P6:=IF(A>REF(L,6)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4)&&A<=REF(L,5),REF(L,6),0);
P7:=IF(A>REF(L,7)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4)&&A<=REF(L,5)&&A<=REF(L,6),REF(L,7),0);
P8:=IF(A>REF(L,8)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4)&&A<=REF(L,5)&&A<=REF(L,6)&&A<=REF(L,7),REF(L,8),0);
P9:=IF(A>REF(L,9)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4)&&A<=REF(L,5)&&A<=REF(L,6)&&A<=REF(L,7)&&A<=REF(L,8),REF(L,9),0);
P10:=IF(A>REF(L,10)&&A<=REF(L,1)&&A<=REF(L,2)&&A<=REF(L,3)&&A<=REF(L,4)&&A<=REF(L,5)&&A<=REF(L,6)&&A<=REF(L,7)&&A<=REF(L,8)&&A<=REF(L,9),REF (L,10),0);
AA:=P1+P2+P3+P4+P5+P6+P7+P8+P9+P10;
PP1:=IF(AA>REF(L,1),REF(L,1),0);
PP2:=IF(AA>REF(L,2)&&AA<=REF(L,1),REF(L,2),0);
PP3:=IF(AA>REF(L,3)&&AA<=REF(L,1)&&AA<=REF(L,2),REF(L,3),0);
PP4:=IF(AA>REF(L,4)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3),REF(L,4),0);
PP5:=IF(AA>REF(L,5)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4),REF(L,5),0);
PP6:=IF(AA>REF(L,6)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4)&&AA<=REF(L,5),REF(L,6),0);
PP7:=IF(AA>REF(L,7)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4)&&AA<=REF(L,5)&&AA<=REF(L,6),REF(L,7),0);
PP8:=IF(AA>REF(L,8)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4)&&AA<=REF(L,5)&&AA<=REF(L,6)&&AA<=REF(L,7),REF(L,8),0);
PP9:=IF(AA>REF(L,9)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4)&&AA<=REF(L,5)&&AA<=REF(L,6)&&AA<=REF(L,7)&&AA<=REF(L,8),REF (L,9),0);
PP10:=IF(AA>REF(L,10)&&AA<=REF(L,1)&&AA<=REF(L,2)&&AA<=REF(L,3)&&AA<=REF(L,4)&&AA<=REF(L,5)&&AA<=REF(L,6)&&AA<=REF(L,7)&&AA<=REF(L,8)&&AA<=REF (L,9),REF(L,10),0);
AAA:=PP1+PP2+PP3+PP4+PP5+PP6+PP7+PP8+PP9+PP10;
C:=VALUEWHEN(AAA>0,AAA);
T1:=IF(B<REF(H,1),REF(H,1),0);
T2:=IF(B<REF(H,2)&&B>=REF(H,1),REF(H,2),0);
T3:=IF(B<REF(H,3)&&B>=REF(H,1)&&B>=REF(H,2),REF(H,3),0);
T4:=IF(B<REF(H,4)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3),REF(H,4),0);
T5:=IF(B<REF(H,5)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4),REF(H,5),0);
T6:=IF(B<REF(H,6)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4)&&B>=REF(H,5),REF(H,6),0);
T7:=IF(B<REF(H,7)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4)&&B>=REF(H,5)&&B>=REF(H,6),REF(H,7),0);
T8:=IF(B<REF(H,8)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4)&&B>=REF(H,5)&&B>=REF(H,6)&&B>=REF(H,7),REF(H,8),0);
T9:=IF(B<REF(H,9)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4)&&B>=REF(H,5)&&B>=REF(H,6)&&B>=REF(H,7)&&B>=REF(H,8),REF(H,9),0);
T10:=IF(B<REF(H,10)&&B>=REF(H,1)&&B>=REF(H,2)&&B>=REF(H,3)&&B>=REF(H,4)&&B>=REF(H,5)&&B>=REF(H,6)&&B>=REF(H,7)&&B>=REF(H,8)&&B>=REF(H,9),REF (H,10),0);
BB:=IF((T1+T2+T3+T4+T5+T6+T7+T8+T9+T10)=0,888888,T1+T2+T3+T4+T5+T6+T7+T8+T9+T10);
TT1:=IF(BB<REF(H,1),REF(H,1),0);
TT2:=IF(BB<REF(H,2)&&BB>=REF(H,1),REF(H,2),0);
TT3:=IF(BB<REF(H,3)&&BB>=REF(H,1)&&BB>=REF(H,2),REF(H,3),0);
TT4:=IF(BB<REF(H,4)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3),REF(H,4),0);
TT5:=IF(BB<REF(H,5)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4),REF(H,5),0);
TT6:=IF(BB<REF(H,6)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4)&&BB>=REF(H,5),REF(H,6),0);
TT7:=IF(BB<REF(H,7)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4)&&BB>=REF(H,5)&&BB>=REF(H,6),REF(H,7),0);
TT8:=IF(BB<REF(H,8)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4)&&BB>=REF(H,5)&&BB>=REF(H,6)&&BB>=REF(H,7),REF(H,8),0);
TT9:=IF(BB<REF(H,9)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4)&&BB>=REF(H,5)&&BB>=REF(H,6)&&BB>=REF(H,7)&&BB>=REF(H,8),REF (H,9),0);
TT10:=IF(BB<REF(H,10)&&BB>=REF(H,1)&&BB>=REF(H,2)&&BB>=REF(H,3)&&BB>=REF(H,4)&&BB>=REF(H,5)&&BB>=REF(H,6)&&BB>=REF(H,7)&&BB>=REF(H,8)&&BB>=REF (H,9),REF(H,10),0);
BBB:=TT1+TT2+TT3+TT4+TT5+TT6+TT7+TT8+TT9+TT10;
D:=VALUEWHEN(BBB>0,BBB);
UD:=IF(CLOSE>D&&REF(CLOSE,1)<=D,1,IF(CLOSE<C&&REF(CLOSE,1)>=C,-3,0));
K:=VALUEWHEN(UD<>0,UD);
G:=IF(K=1,C,D);
CROSS(CLOSE,REF(G,1)),BPK;
CROSS(REF(G,1),CLOSE),SPK;
而效果测试中可选择的测试价位都是当前周期的各个价位,二者的成交价差差距会比较大。(解
|