X个自然日可以写,X个交易日做不到
X个自然日:
DATETOD1970-DATETOD1970(valuewhen(开仓条件,date))>=x
写了下面的公式,为何在附图中 ‘持仓时间‘ 没有显示呢? 烦请帮忙指正 ,谢谢!
shortday:=9;
longday:=18;
testdate:=5;
mashort:=ma(c,shortday),colorwhite;
malong:=ma(c,longday),colorgreen;
//交易条件
开多条件:=CROSS(mashort,malong);//开多平空条件
开空条件:=CROSS(malong,mashort);//开空平多条件
if (barpos=1) or (barpos<longday) then
holdingDate:=-500;
else
if (开多条件 or 开空条件) and (barpos>=longday) then
holdingdate:=0;
holdingdateYD:=ref(holdingdate,1);
if (mashort>malong) and (holdingDate<-400) then
holdingdate:=holdingdateYD+1;
else
if (holdingDate<-400) then
holdingdate:=holdingdateYD-1;
持仓时间:holdingdate;
都没有啊,我都试过了 没有一个显示出来持仓时间的啊
比如PTA连续 上证指数等等
谢谢了!根据您的建议,现在确实能够显示出来了,
我更改了一下程序,变为技术指标。可为何数值只有-501,-500,-499, 0 这几个值?
我感觉在下面的代码中
holdingDate:=-500;
holdingdateYD:=ref(holdingdate,1);
这出问题了。无论前一天的 holdingDate是什么, holdingdateYD:=ref(holdingdate,1);都是-500?
runmode:0;
shortday:=9;
longday:=18;
testdate:=5;
mashort:=ma(c,shortday),colorwhite;
malong:=ma(c,longday),colorgreen;
//交易条件
开多条件:=CROSS(mashort,malong);//开多平空条件
开空条件:=CROSS(malong,mashort);//开空平多条件
holdingDate:=-500;
holdingdateYD:=ref(holdingdate,1);
if barpos<longday then
holdingDate:=-500;
else
begin
if 开多条件 or 开空条件 then
holdingdate:=0;
else //******************************
begin
if mashort>malong then
holdingdate:=holdingdateYD+1;
else
holdingdate:=holdingdateYD-1;
end;
end;
cjsj:holdingdate;
你定义下全局变量
variable:holdingdate=0;
然后就能做你的计算了,不然序列变量你的计算就一直是那样的