我是新手上路,对金子塔语言正在学习中,下面是试着编写的程序,开仓条件是随机的,但是不知为什么只开多,不开空,请求帮助,谢谢啊!
input:n1(3,1,50,2);
input:n2(30,5,60,5);
variable:win1=0,win2=0,maxprofit=0,b=0,s=0;
a:=rand(10000); //产生随机数,判断其奇偶性,确定做多做空//
if a%2=0 then
b:=1;
else
s:=1;
if b and holding=0 and time=90100 then begin
buy(1,1,limitr,close);
maxprofit:=0;
end
if s and holding=0 and time=90100 then begin
buyshort(1,1,limitr,close);
maxprofit:=0;
end
if holding>0 then begin
if enterbars>0 then begin
win1:=(close-ENTERPRICE)/ENTERPRICE*100;
IF win1>MAXPROFIT THEN
MAXPROFIT:=WIN1;
WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
END
if win1<-n1 then
sell(1,holding,limitr,close);
if win2>n2 and openprofit>0 then
sell(1,holding,limitr,close);
end
if holding<0 then begin
if enterbars>0 then begin
win1:=(enterprice-close)/enterprice*100;
if win1>maxprofit then
maxprofit:=win1;
win2:=(maxprofit-win1)/maxprofit*100;
end
if win1<-n1 then
buyshort(1,holding,limitr,close);
if win2>n2 and openprofit>0 then
buyshort(1,holding,limitr,close);
end
if time=145800 and holding<>0 then begin
sell(holding>0,holding,limitr,close);
sellshort(holding<o,holding,limitr,close);
end
楼主可以直接设定 S:=1.看看会不会开空
直接设置s:=1,也还是不做空,很奇怪呢!
b 是全局变量。
a是偶数的话,b=1,
下一根K线,a是奇数的话。此时b依然等于1.
在平仓后,你要把b重新赋值为 0