代码如下:input fudu(0.1);
variable: qushi=0,gaodian=close,didian=close;
duo:didian*(1+fudu);
kong:gaodian*(1-fudu);
kd:=cross(close,duo);//如果收盘上穿低点*1.1,开多;
kk:= cross(kong,close);//如果收盘下穿高点*0.9,开空;
if holding=0 then //开始时没有持仓,以第一天的收盘价为基准,如果低于这个位置的0.9开空,高于这个位置的1.1做多
begin
if kk then
begin
gaodian:=close;
buyshort(1,1,thisclose);
end;
if kd then
begin
didian:=close;
buy(1,1,thisclose);
end;
end;
if holding>0 then //如果已经做多,等待发出做空信号,当收盘价低于做多期间最高点的0.9,平多开空
begin
if close>gaodian then gaodian:=close;
if kk then
begin
sell(1,1,thisclose);
buyshort(1,1,thisclose);
didian:=close;
end;
end;
if holding<0 THEN //如果已经做空,等待做多信号,当收盘价高于做空期间最低点的1.1,平空开多
begin
if close<didian then didian:=close;
if kd then
begin
buy(1,1,thisclose);
sellshort(1,1,thisclose);
gaodian:=close;
end;
end;