本策略为双向开仓策略,麻烦更改为只开多,只开空两个单向策略,谢谢
input:S(10,1,10,1);
时间:=TIME;
SHORT:=1;
LONG:=3;
M:=3;
DIF:=(EMA(CLOSE,SHORT) - EMA(CLOSE,LONG));
DEA:=EMA(DIF,M);
MACD:=(2 * (DIF - DEA));
KK:=IF((DIF > DEA),3,-(3));
JCSC:=((((M - 1) / (M + 1)) * DEA) / (1 - (2 / (M + 1))));
DD:=(((MACD / 2) + ((DEA * (M - 1)) / (M + 1))) / (1 - (2 / (M + 1))));
拐头:=(((((DIF * (SHORT + 1)) * (LONG + 1)) - (((LONG + 1) * (SHORT - 1)) * EMA(CLOSE,SHORT))) + (((SHORT + 1) * (LONG - 1)) * EMA(CLOSE,LONG))) / (2 * ((LONG + 1) - (SHORT + 1))));
TYP:=(((HIGH + LOW) + (2 * CLOSE)) / 4);
龙线:EMA(TYP,12),COLORMAGENTA,LINETHICK2;
最高价:=HHV(HIGH,(TIME = 10000));
最低价:=LLV(LOW,(TIME = 10000));
A:=REF(HHV(HIGH,最高价),2);
AA:=SYSPARAM(4);
B:=REF(LLV(LOW,最低价),2);
BB:=SYSPARAM(5);
ZJ1:=(((HIGH + LOW) + (2 * CLOSE)) / 4);
ZJ2:=(((ZJ1 - EMA(ZJ1,59)) / STD(ZJ1,59)) * 100);
ZJ3:=EMA(ZJ2,10);
ZJ4:=EMA(ZJ3,4);
ZJ5:=EMA(ZJ4,4);
ZJ6:=(((3 * ZJ4) - (2 * ZJ5)) / 2);
VAR1:=IF((ZJ6 > 99.99),(AA * 1),AA);
VAR2:=IF((ZJ6 < (0 - 99.99)),(BB * 1),BB);
差:=(VAR1 - VAR2);
百1:=((差 * 0.99) + VAR2);
百2:=((差 * 0.01) + VAR2);
最高价1:=HHV(VAR1,(TIME = 10000));
最低价1:=LLV(VAR2,(TIME = 10000));
开多1:=CROSS(拐头,百2);
开空1:=CROSS(百1,拐头);
百3:=REFDATE(最高价1,DATE,0);
百4:=REFDATE(最低价1,DATE,0);
VARIABLE:SS:=1;
VARIABLE:NUM:=0;
IF (SS = S) THEN
BEGIN
NUM:=0;
END
IF (SS = 1) THEN
BEGIN
NUM:=1;
END
IF (开空1 AND (TIME < 185000)) THEN
BEGIN
SELL(1,HOLDING,market);
IF (HOLDING = 0) THEN
BEGIN
BUYSHORT(1,SS,market);
IF (NUM = 1) THEN
BEGIN
SS:=(SS + 0.5);
END
ELSE
BEGIN
IF (NUM = 0) THEN
BEGIN
SS:=(SS - 1);
END
END
END
END
IF (开多1 AND (TIME < 185000)) THEN
BEGIN
SELLSHORT(1,HOLDING,market);
IF (HOLDING = 0) THEN
BEGIN
BUY(1,SS,market);
IF (NUM = 1) THEN
BEGIN
SS:=(SS + 0.5);
END
ELSE
BEGIN
IF (NUM = 0) THEN
BEGIN
SS:=(SS - 1);
END
END
END
END
IF (TIME > 185000) THEN
BEGIN
SELL(1,HOLDING,market);
SELLSHORT(1,HOLDING,market);
END
{
KD:=; //开多条件
PD:=; //平多条件
KK:=; //开空条件
PK:=; //平空条件
平空:SELLSHORT(PK,1,THISCLOSE); //平空信号
开多:BUY(KD AND HOLDING=0,1,THISCLOSE); //开多信号
平多:SELL(PD,1,THISCLOSE); //平多信号
开空:BUYSHORT(KK AND HOLDING=0,1,THISCLOSE); //开空信号
}
{
VARIABLE:SS:=1;
VARIABLE:NUM:=0;
IF (SS = S) THEN
BEGIN
NUM:=0;
END
IF (SS = 1) THEN
BEGIN
NUM:=1;
END
IF (开空1 AND (TIME < 185000)) THEN
BEGIN
SELL(1,HOLDING,market);
IF (HOLDING = 0) THEN
BEGIN
BUYSHORT(1,SS,market);
IF (NUM = 1) THEN
BEGIN
SS:=(SS + 0.5);
END
ELSE
BEGIN
IF (NUM = 0) THEN
BEGIN
SS:=(SS - 1);
END
END
END
END
IF (开多1 AND (TIME < 185000)) THEN
BEGIN
SELLSHORT(1,HOLDING,market);
IF (HOLDING = 0) THEN
BEGIN
BUY(1,SS,market);
IF (NUM = 1) THEN
BEGIN
SS:=(SS + 0.5);
END
ELSE
BEGIN
IF (NUM = 0) THEN
BEGIN
SS:=(SS - 1);
END
END
END
END
IF (TIME > 185000) THEN
BEGIN
SELL(1,HOLDING,market);
SELLSHORT(1,HOLDING,market);
END