最主要是想把上一个持仓过程中的最大浮盈和最大浮亏作为下一个开仓的依据
VARIABLE:maxprofit:=0,minprofit:=0;//全局变量记录最大最小浮动盈亏
input:n(9,1,100,10),p1(3,2,40,4),p2(3,2,40,4);//参数设置
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,NODRAW;
input:p(26,20,100,8),s(12,5,40,4),m(9,2,60,6);
DIFF :=EMA(CLOSE,S) - EMA(CLOSE,P);
DEA :=EMA(DIFF,M);
MACD1 :=2*(DIFF-DEA), COLORSTICK;
macdjc:=cross(diff,dea),NODRAW;//macd金叉
macdsc:=cross(dea,diff),NODRAW;
kdjjc:=cross(k,d),NODRAW;//kdj金叉
kdjsc:=cross(d,k),NODRAW;
sellshort(kdjjc and holding<0,holding,market);
buy(macdjc and holding=0,1,market);
sell(macdsc and holding>0,holding,market);
buyshort(kdjsc and holding=0,1,market);
//下面这部分代码要放在交易语句后面
Len:=BARSLAST(holding=0);//持仓周期
temp1:=hhv(OPENPROFIT,LEN);//hhv和llv不能在if内部使用,因此先定义成临时变量,然后在if内部调用
temp2:=llv(OPENPROFIT,LEN);
if holding<>0 then
begin
maxprofit:=temp1;
minprofit:=temp2;
end
maxp:ref(maxprofit,Len);//取值时候取上次有持仓期间的最大 最小浮动盈亏
minp:ref(minprofit,Len);