回测无法平仓
代码如下,谢谢:
input:N(9,1,100,10);
input:P1(3,2,40,4);
input:P2(3,2,40,4);
input:X(10,1,20,1);
Variable:position=0;
//kdj指标
RSV:(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))*100;
K:SMA(RSV,P1,1);
D:SMA(K,P2,1);
J:3*K-2*D;
A1:=every(K<60,30);
A2:=every(K>40,30);
A3:=Cross(K,d) and K<20.5 and D<20.5 and Count(K>40,10)=0;
A4:=Cross(D,K) and K>79.5 and D>79.5 and Count(K<60,10)=0;
B1:=C>enterprice+X*MINDIFF or C<enterprice-X*MINDIFF;
B2:=C<enterprice-X*MINDIFF or C>enterprice+X*MINDIFF;
B3:=every(K>60,15);
B4:=every(K<40,15);
IF Holding=0 and position =0 THEN BEGIN
If A1 then begin
Buy(1,1,Marketr);
Position =1;
end
If A2 then begin
buyshort(1,1,marketr);
position = -1;
end
If A3 then BEGIN
buy(1,1,marketr);
position = 2;
end
If A4 then begin
Buyshort(1,1,marketr);
position = -2;
end
end
If Holding = 1 and position =1 then begin
If B1 then BEGIN
sell(1,1,marketr);
position = 0;
end
end
If if holding = -1 and position = -1 then begin
If B2 then BEGIN
sellshort(1,1,marketr);
position = 0;
end
end
If holding = 1 and position = 2 then begin
If B3 then BEGIN
sell(1,1,marketr);
position = 0;
end
end
If holding = -1 and position = -2 then begin
If B4 then BEGIN
sellshort(1,1,marketr);
position = 0;
end
end
input:N(9,1,100,10);
input:P1(3,2,40,4);
input:P2(3,2,40,4);
input:X(10,1,20,1);
Variable:position=0;
//kdj指标
RSV:(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))*100;
K:SMA(RSV,P1,1);
D:SMA(K,P2,1);
J:3*K-2*D;
A1:=every(K<60,30);
A2:=every(K>40,30);
A3:=Cross(K,d) and K<20.5 and D<20.5 and Count(K>40,10)=0;
A4:=Cross(D,K) and K>79.5 and D>79.5 and Count(K<60,10)=0;
B3:=every(K>60,15);
B4:=every(K<40,15);
IF Holding=0 and position =0 THEN BEGIN
If A1 then begin
Buy(1,1,Marketr);
Position: =1;
end
If A2 then begin
buyshort(1,1,marketr);
position: = -1;
end
If A3 then BEGIN
buy(1,1,marketr);
position: = 2;
end
If A4 then begin
Buyshort(1,1,marketr);
position: = -2;
end
end
B1:=C>enterprice+X*MINDIFF or C<enterprice-X*MINDIFF;
B2:=C<enterprice-X*MINDIFF or C>enterprice+X*MINDIFF;
If Holding = 1 and position =1 then begin
If B1 then BEGIN
sell(1,1,marketr);
position: = 0;
end
end
If if holding = -1 and position = -1 then begin
If B2 then BEGIN
sellshort(1,1,marketr);
position: = 0;
end
end
If holding = 1 and position = 2 then begin
If B3 then BEGIN
sell(1,1,marketr);
position: = 0;
end
end
If holding = -1 and position = -2 then begin
If B4 then BEGIN
sellshort(1,1,marketr);
position: = 0;
end
end
问题在于
sellshort(1,1,marketr);
position= 0;
类似这样的
position后面都少一个冒号
说明你的空头条件难以满足,所以没有空头信号