以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  X个交易日后自动退出交易的公示表达法  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=65558)

--  作者:chacterchen
--  发布时间:2014/5/28 11:13:22
--  X个交易日后自动退出交易的公示表达法
如果我想写一个交易系统指标,建仓条件如下:
//交易条件
mashort:= ma(c,9);
malong:=ma(c,8);
开多平空条件:=CROSS(mashort,malong);//开多条件
开空平多条件:=CROSS(malong,mashort);//开空条件

能否帮忙写平仓条件?
平仓条件为在建仓后x个交易日收盘自动卖出。另外如果是X个自然日自动退出又该如何写?

谢谢!


--  作者:jinzhe
--  发布时间:2014/5/28 11:21:28
--  

X个自然日可以写,X个交易日做不到

X个自然日:

DATETOD1970-DATETOD1970(valuewhen(开仓条件,date))>=x


--  作者:chacterchen
--  发布时间:2014/5/28 14:45:38
--  
写了下面的公式,为何在附图中  ‘持仓时间‘     没有显示呢? 烦请帮忙指正 ,谢谢!

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;



--  作者:jinzhe
--  发布时间:2014/5/28 14:49:15
--  
在哪个股票或者期货上用这个公式的?
--  作者:chacterchen
--  发布时间:2014/5/28 14:51:48
--  
股票,股票指数,还有期货的连续合约
--  作者:jinzhe
--  发布时间:2014/5/28 14:52:54
--  

晕啊,你就直接说你现在用在哪个上没有持仓时间的啊

 


--  作者:chacterchen
--  发布时间:2014/5/28 14:54:55
--  
都没有啊,我都试过了 没有一个显示出来持仓时间的啊
比如PTA连续 上证指数等等

--  作者:jinzhe
--  发布时间:2014/5/28 15:09:58
--  

开头加一句

runmode:0;


--  作者:chacterchen
--  发布时间:2014/5/28 16:21:41
--  
谢谢了!
根据您的建议,现在确实能够显示出来了,

我更改了一下程序,变为技术指标。可为何数值只有-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;


--  作者:jinzhe
--  发布时间:2014/5/28 16:25:03
--  

你定义下全局变量

variable:holdingdate=0;

然后就能做你的计算了,不然序列变量你的计算就一直是那样的