金字塔专用Q2策略源码[金字塔模型]
input:TD(10,0,20,1),RATIO(1.75,0,2.55,0.2),MINLOCALVOLATILI(2.42,1.62,2.62,0.1),STOPLOSS(15,10,20,1),P(19,12,20,1),P2(20,1,20,1),STOP3(10,0,20,1),KS(19000,10000,20000,1000),STOP1(30,20,40,1);
if not((UPPERSTR(STRLEFT(STKLABEL,2)) = \'IF\') or (UPPERSTR(STRLEFT(STKLABEL,2)) = \'IH\') or (UPPERSTR(STRLEFT(STKLABEL,2)) = \'IC\')) then begin
DRAWTEXTEX(CLOSE,1,450,470,\'当前品种不适合本策略量化交易\',COLORRED);
EXIT;
END
IF (DATATYPE <> 2) THEN
BEGIN
DRAWTEXTEX(CLOSE,1,450,530,\'当前周期不适合本策略量化交易\',COLORRED);
EXIT;
END
LOTS:max(FLOOR(150000/(c*MULTIPLIER*0.1)),1),linethick0;
B2N:=(BARSLAST((DATE <> REF(DATE,1))) + 1),NOAXIS;
昨收:=VALUEWHEN((B2N = 1),REF(C,1)),NOAXIS;
今开:=VALUEWHEN((B2N = 1),O),NOAXIS;
今收:=VALUEWHEN((B2N = 1),C),NOAXIS;
今开盘收:=VALUEWHEN((B2N = 1),C),NOAXIS;
今开最高:=VALUEWHEN((B2N = 1),H),NOAXIS;
今开最低:=VALUEWHEN((B2N = 1),L),NOAXIS;
TRADEBEGIN:=94500;
LASTTRADE:=143000;
TRADECLOSE:=150000;
LENGTH1:=4;
LENGTH2:=10;
LENGTH3:=4;
LENGTH4:=15;
LENGTH:=20;
VARIABLE:MA1:=0;
VARIABLE:MA2:=0;
VARIABLE:MA3:=0;
VARIABLE:MA4:=0;
VARIABLE:过程高低:=c;
VARIABLE:开仓价:=c;
C1:=c;
H1:=h;
L1:=l;
O1:=o;
V1:=v;
MA1:=MA(C1,LENGTH1);
MA2:=MA(C1,LENGTH2);
MA3:=MA(C1,LENGTH3);
MA4:=MA(C1,LENGTH4);
MIDLINE:=MA(C1,LENGTH);
BAND:=STD(c,LENGTH);
UPLINE:=(MIDLINE + (RATIO * BAND)),COLORYELLOW;
DOWNLINE:=(MIDLINE - (RATIO * BAND)),COLORGREEN;
RSV:=(((C1 - LLV(L1,9)) / (HHV(H1,9) - LLV(L1,9))) * 100);
K:=SMA(RSV,3,1);
D:=SMA(K,3,1);
J:=((3 * K) - (2 * D));
DIFF:=(EMA(CLOSE,22) - EMA(CLOSE,56));
DEA:=EMA(DIFF,9);
MACD:=(2 * (DIFF - DEA));
B2:=(MA(C1,10) - MA(C1,52));
KKXD:=(B2 < REF(B2,2));
MACDPDKK:=(MACD < REF(MACD,1));
CROSS43:=((((((((HOLDING > 0) AND (COUNT(CROSS(MA4,MA3),5) >= 1)) AND (C1 < REF(LLV(H1,3),1))) AND KKXD) AND(MACD < REF(MACD,1))) AND (O1 < UPLINE)) AND (L1 < (DOWNLINE + 10))) AND (COUNT((C1 < (O1 - 1)),3) >= 1));
CROSS21:=(((((HOLDING > 0) AND (COUNT(CROSS(MA2,MA1),5) >= 1)) AND (C1 > REF(HHV(O1,3),1))) AND (C1 < (O1 + 8))) AND (C1 < REF(HHV(C1,10),1)));
CROSS212:=(((COUNT(CROSS21,5) >= 1) AND (C1 < UPLINE)) AND (今开 > (昨收 - 9)));
CROSS212K:=((((COUNT(CROSS21,5) >= 1) AND (C1 < UPLINE)) AND (今开 > (昨收 - 9))) AND NOT((COUNT((C1 > O1),3) = 3)));
CROSS43PK:=((((COUNT(CROSS43,20) >= 1) AND (C1 > UPLINE)) AND (ENTERBARS > 1)) AND (COUNT((C1 > O1),3) = 3));
KKXD2:=(COUNT((C1 > UPLINE),2) < 2),NOAXIS;
CROSS12:=((((HOLDING < 0) AND CROSS(MA1,MA2)) AND (K > D)) AND (ENTERBARS > 1));
CROSS12KK:=(((COUNT(CROSS12,30) >= 1) AND (C1 < REF(LLV(L1,10),1))) AND (C1 > MIDLINE));
IF ISLASTBAR THEN
BEGIN
SPLITRATE:=((MINDIFF * TD) * 2);
SPLITRATE2:=(MINDIFF * (TD + 5));
SPLITRATE3:=(MINDIFF * (TD + 10));
END
ELSE
BEGIN
SPLITRATE:=0;
SPLITRATE2:=0;
SPLITRATE3:=0;
END
VARIABLE:YTDASSET:=0;
IF (DATE <> REF(DATE,1)) THEN
BEGIN
YTDASSET:=ASSET;
END
MAXRKKC:=((ASSET - YTDASSET) > (-(LOTS) * KS)),NOAXIS;
MAXRKPC:=((ASSET - YTDASSET) < (-(LOTS) * KS));
BO:=((HOLDING > 0) AND (ENTERBARS > 0));
SO:=((HOLDING < 0) AND (ENTERBARS > 0));
TP:=IF(BO,HHV(HIGH,ENTERBARS),IF(SO,LLV(LOW,ENTERBARS),0)),NOAXIS;
放量PK:=((COUNT(((VOL = HHV(VOL,10)) AND (CLOSE < (OPEN - 7))),3) >= 1) AND (CLOSE > (OPEN + 6)));
放量PD:=(((COUNT(((VOL = HHV(VOL,10)) AND (CLOSE > (OPEN + 10))),5) >= 1) AND (CLOSE < (OPEN - 9))) AND (CLOSE < UPLINE));
4阳PK:=(((COUNT((CLOSE > OPEN),4) = 4) AND (CLOSE > (REF(CLOSE,4) + 5))) AND (CLOSE > ENTERPRICE));
大阴平多:=(((CLOSE < (OPEN - 15)) AND (CLOSE < REF(LLV(LOW,5),1))) AND (COUNT((HIGH > UPLINE),4) >= 1));
长阴UPLINEPD:=(((COUNT((CLOSE > (OPEN + 20)),5) >= 1) AND (COUNT(((CLOSE < (OPEN - 9)) AND (HIGH < REF(HIGH,1))),5) >= 1)) AND CROSS(UPLINE,CLOSE));
SLYPD:=((((COUNT((C1 < O1),3) = 3) AND (C1 < (REF(H1,2) - 10))) AND (COUNT((H1 > UPLINE),2) >= 1)) AND (COUNT(CROSS(D,K),2) >= 1));
UPLINEPD:=(CROSS(UPLINE,C1) AND (C1 < (REF(O1,1) - 14)));
UPLINEPD2:=((((COUNT((COUNT((H1 > UPLINE),3) = 3),15) >= 1) AND (C1 < REF(LLV(L1,5),1))) AND (COUNT(((H1 < UPLINE) AND (C1 < UPLINE)),3) >= 2)) AND (C1 < (TP - 18)));
KDPK:=(((((COUNT((CROSS(K,D) AND (K < 20)),5) >= 1) AND (COUNT((L1 < DOWNLINE),3) >= 1)) AND (L1 > DOWNLINE)) AND (C1 > ENTERPRICE)) AND (C1 > REF(LLV(H1,3),1)));
一阳三线PK:=(((CROSS(CLOSE,MA2) AND CROSS(CLOSE,UPLINE)) AND (K > 50)) AND (COUNT((L1 > MIDLINE),3) = 3))NOAXIS;
CYFTPK:=(((((COUNT((((VOL = HHV(VOL,10)) AND (VOL > (MA(VOL,20) * 2))) AND (CLOSE < (REF(CLOSE,1) - 21))),5) >= 1) AND (CLOSE > MA(CLOSE,2))) AND (CLOSE > OPEN)) AND (CLOSE < ENTERPRICE)) AND (TIME > 94500)),NOAXIS;
CYFTPK2:=(((COUNT((((VOL = HHV(VOL,10)) AND (VOL > (MA(VOL,10) * 2.8))) AND (CLOSE < OPEN)),4) >= 1) AND (CLOSE > REF(HIGH,1))) AND (CLOSE > OPEN)),NOAXIS;
KDKD:=(K > REF(K,1));
跳空KK:=(((今开 < (昨收 - 4)) AND (C1 < (O1 - 13))) AND (C1 > (昨收 - 30)));
跳空KD:=(((今开 > (昨收 + 4)) AND (C1 > (O1 + 13))) AND (C1 < (昨收 + 22)));
CROSS12KK2:=(((COUNT(CROSS12,4) >= 1) AND (COUNT((C1 < O1),3) = 3)) AND (今开 > (昨收 + 7)));
上轨开多:=(((((COUNT((C1 > UPLINE),3) = 3) AND (TIME < 95000)) AND (COUNT((K > D),10) = 10)) AND (C1 > REF(HHV(H1,10),1))) AND (今开 < (昨收 + 21))),NOAXIS;
开多4条件:=BAND >= MINLOCALVOLATILI AND KKXD2 AND TIME >= TRADEBEGIN AND TIME <= LASTTRADE AND MAXRKKC and L1 < DOWNLINE,linethick0;//防止平多3开多4
///////////////////////////////////////////////////
hc1:=ref(h,1);
if Hc1>过程高低 and HOLDING>0 then begin
过程高低:=Hc1;
end
lc1:=ref(l,1);
if lc1<过程高低 and HOLDING<0 then begin
过程高低:=lc1;
end
HHV1:=HHV(REF(HIGH,1),5);
LLV1:=LLV(REF(LOW,1),5);
HAE:=IF((ENTERBARS = 1),开仓价,过程高低);
LAE:=IF((ENTERBARS = 1),开仓价,过程高低);
IF ((((HOLDING > 0) AND (LOW <= LLV1)) AND (LOW <= (HAE - P))) AND (LOW <= (开仓价 - STOP3))) THEN BEGIN
PRICE:=MIN(MIN(LLV1,(HAE - P)),(开仓价 - STOP3));
IF (OPEN < PRICE) THEN BEGIN
PRICE:=OPEN;
END
YD止多:SELL(1,LOTS,LIMITR,(PRICE - SPLITRATE2),1);
IF ( (HOLDING = 0) AND (TIME <= TRADECLOSE)) THEN BEGIN
止多空:BUYSHORT(1,LOTS,LIMITR,(PRICE - SPLITRATE3),1);
过程高低:=c;
开仓价:=PRICE;
END
END
IF ((((HOLDING < 0) AND(HIGH >= HHV1)) AND (HIGH >= (LAE + P2))) AND (HIGH >= (开仓价 + STOP3))) THEN BEGIN
PRICE:=MAX(MAX(HHV1,(LAE + P2)),(开仓价 + STOP3));
IF (o > PRICE) THEN BEGIN
PRICE:=o;
END
YD止空:SELLSHORT( 1 ,LOTS,LIMITR,(PRICE + SPLITRATE2),1);
IF ((HOLDING = 0) AND (TIME <= TRADECLOSE)) THEN BEGIN
止空多:BUY(1,LOTS,LIMITR,(PRICE + SPLITRATE3),1);
过程高低:=c;
开仓价:=PRICE;
END
END
////////////////////////////////////////////////////
IF ((( (HOLDING = 0) AND (TIME = 94500)) AND 跳空KK) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
开空1:BUYSHORT(1,LOTS,LIMITR,(c - SPLITRATE),1);
过程高低:=c;
开仓价:=c;
END
IF (((( HOLDING = 0) AND (TIME = 94500)) AND 跳空KD) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
开多1:BUY(1,LOTS,LIMITR,(c + SPLITRATE),1);
过程高低:=c;
开仓价:=c;
END
IF (TIME >= TRADEBEGIN) THEN BEGIN
IF (((TIME = TRADECLOSE) OR MAXRKPC) AND (HOLDING <> 0)) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
IF (HOLDING < 0) THEN BEGIN
平空1:SELLSHORT(1,LOTS,LIMITR,(c + SPLITRATE),1);
END
IF (HOLDING > 0) THEN BEGIN
平多1:SELL(1,LOTS,LIMITR,(c - SPLITRATE),1);
END
END
IF ((HOLDING > 0)AND (ENTERBARS >1) ) THEN BEGIN
IF (((CROSS43 OR 大阴平多) OR UPLINEPD) OR UPLINEPD2) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
平多2:SELL(1,LOTS,LIMITR,(c - SPLITRATE2),1);
IF ((((HOLDING = 0) AND ((CROSS43 OR UPLINEPD) OR UPLINEPD2)) AND (TIME <= LASTTRADE)) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
开空2:BUYSHORT(1,LOTS,LIMITR,(c - SPLITRATE3),1);
过程高低:=c;
开仓价:=c;
END
END
IF ((((放量PD OR CROSS212) OR SLYPD) OR 长阴UPLINEPD) AND (C1 > ENTERPRICE)) and not(开多4条件) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
平多3:SELL(1,LOTS,LIMITR,(c - SPLITRATE),1);
IF (((( (HOLDING = 0) AND (TIME <= LASTTRADE)) AND MAXRKKC) AND CROSS212K) AND (BAND >= 2.42)) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
开空3:BUYSHORT(1,LOTS,LIMITR,(c - SPLITRATE3),1);
过程高低:=c;
开仓价:=c;
END
END
END
ELSE
BEGIN
//-------------------------------------------------------------------------
IF (( HOLDING < 0) AND (ENTERBARS>1)) THEN BEGIN
IF (((一阳三线PK OR (C1 > (ENTERPRICE + STOPLOSS))) OR CYFTPK) OR CYFTPK2) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
平空2:SELLSHORT(1,LOTS,LIMITR,(c + SPLITRATE2),1);
IF ((TIME <= LASTTRADE) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
开多2:BUY(1,LOTS,LIMITR,(c + SPLITRATE3),1);
过程高低:=c;
开仓价:=c;
END
END
IF (((放量PK OR KDPK) OR (CROSS12 AND (C1 < ENTERPRICE))) OR CROSS43PK) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
平空3:SELLSHORT(1,LOTS,LIMITR,(c + SPLITRATE2),1);
过程高低:=c;
开仓价:=c;
END
END
END
IF ((( (HOLDING = 0) AND (BAND >= MINLOCALVOLATILI)) AND (TIME < 95500)) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
IF 上轨开多 THEN BEGIN
开多3:BUY(1,LOTS,LIMITR,(c + SPLITRATE),1);
过程高低:=c;
开仓价:=c;
END
END
IF ((((( (HOLDING = 0) AND (BAND >= MINLOCALVOLATILI)) AND KKXD2) AND (TIME >= TRADEBEGIN)) AND (TIME <= LASTTRADE)) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
IF (L1 < DOWNLINE) THEN BEGIN
开多4:BUY(1,LOTS,LIMITR,(c + SPLITRATE),1);
过程高低:=c;
开仓价:=c;
END
IF (((( (HOLDING = 0) AND (BAND >= MINLOCALVOLATILI)) AND (TIME >= TRADEBEGIN)) AND (TIME <= LASTTRADE)) AND MAXRKKC) and (TIME0 - TIMETOT0(DYNAINFO(207))<=5 or NOT(ISLASTBAR)) THEN BEGIN
IF (((H1 > UPLINE) OR CROSS12KK) OR CROSS12KK2) THEN BEGIN
开空4:BUYSHORT(1,LOTS,LIMITR,(c - SPLITRATE),1);
过程高低:=c;
开仓价:=c;
END
END
END
END
盈亏:VALUEWHEN(holding=0,ASSET-1000000),NOAXIS,COLORRED,linethick4;
{别忘了将本网告诉您身边的朋友,向朋友传达有用资料,也是一种人情,你朋友会感谢你的。}
有思路,想编写各种指标公式,交易模型,选股公式,还原公式的朋友
可联系技术人员 QQ: 262069696 或微信:cxhjy888 进行 有偿收费 编写!(注:由于人数限制,QQ或微信请选择方便的一个联系我们就行,加好友时请简单备注下您的需求,否则无法通过。谢谢您!)
(注:由于人数限制,QQ或微信请选择方便的一个联系我们就行,加好友时请简单备注下您的需求,否则无法通过。谢谢您!)
相关文章
-
没有相关内容