以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  初学者求助关于交易按程序的编写问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=63886)

--  作者:crocodile
--  发布时间:2014/4/14 14:46:11
--  初学者求助关于交易按程序的编写问题

思路如下:

1:空仓情况下(2个常量:X/Y)

   收盘价上穿X开多,如果收盘前下破X平多,否则持多仓过夜;
   收盘价下破Y开空,如果收盘前上穿Y平空,否则持空仓过夜;


2:持仓情况下(2个常量:X/Y)

   持多仓:
   收盘价下破Y平多开空,如果收盘前上穿Y平空开多,否则持空仓过夜;

   持空仓:
   收盘价上穿X平空开多,如果收盘前下穿X平多开空,否则持多仓过夜;

 

已经请人编好的如下:

 

 

if holding=0 and cross(close,x) then begin

   buy(1,1,market);

end

 

if cross(x,close) and holding>0 then begin

   sell(1,0,market);

 end

 

if holding=0 and cross(y,close) then begin

    buyshort(1,1,market);

end

 

if holding<0 and cross(close,y) then begin

    sellshort(1,0,market);

end

 

 

if holding>0 and cross(y,close) then begin

    sell(1,0,market);

    buyshort(holding=0,1,market);

end

 

if  cross(close,y) then begin

   sellshort(1,0,market);

   buy(holding=0,1,market);

end

 

if holding<0 and cross(close,x) then begin

  sellshort(1,0,market);

  buy(holding=0,1,market);

end

 

if cross(x,close) then begin

   sell(1,0,market);

   buyshort(holding=0,1,market);

end

 

问题是:

 

在我持有隔夜多单时,次日日内在没有出现平多开空动作情况下,直接开多了,也就是这段指令发生作用了:

if holding<0 and cross(close,x) then begin

  sellshort(1,0,market);

  buy(holding=0,1,market);

end

 

我是想在我持有隔夜多单时,次日日内如果没有下破Y则持有多单过夜,若下破Y,则平多开空,若再次上穿X,则平空开多,上述条件循环执行。能力有限,不知我表达清楚了没有,还请各位老师不吝赐教!

[此贴子已经被作者于2014/4/14 14:46:39编辑过]

--  作者:lichenghu
--  发布时间:2014/4/14 15:02:47
--  

if cross(close,y) then begin

sellshort(1,0,market);

buy(holding=0,1,market);

end

//是你这段代码出现问题,此处没有限制有仓或无仓的情况。

另外CROSS函数不能在IF条件语句里使用

 

 

例如代码第一段

if holding=0 and cross(close,x) then begin

buy(1,1,market);

end

 

应该是这样写

cond1:CROSS(C,X);

IF HOLDING=0 AND COND1 THEN

BEGIN

BUY();

END

[此贴子已经被作者于2014/4/14 15:07:03编辑过]

--  作者:crocodile
--  发布时间:2014/4/14 15:14:44
--  
非常感谢超版,我再好好研究一下。。。
--  作者:crocodile
--  发布时间:2014/4/14 17:05:19
--  
老师好,上述代码里的‘buyshort(holding=0,1,market);可以这么写吗?holding=0可以放在这里吗?谢谢
--  作者:lichenghu
--  发布时间:2014/4/14 17:25:21
--  
可以的
--  作者:Crocodile
--  发布时间:2014/4/14 18:19:39
--  
非常感谢!
--  作者:crocodile
--  发布时间:2014/4/15 7:57:02
--  

老师麻烦看一下,这样写对吗?我试了一下,主图没有显示,软件好像还是不能判断持仓情况:

 

持多仓:
   收盘价下破Y平多开空,如果收盘前上穿Y平空开多,否则持空仓过夜;

cond3:=CROSS(C,Y);
cond4:=CROSS(Y,C);

 

if holding>0 and cond4 then
begin

sell(1,0,market);

buyshort(holding=0,1,market);

end


if  holding>0 and cond3 then
begin

   sellshort(1,0,market);

   buy(holding=0,1,market);

end


--  作者:qq代人发帖
--  发布时间:2014/4/15 9:09:51
--  

“if holding>0 and cond3 then ”
平空时应该时holding<0,另外平仓手数最好写holding,不要写0,holding是平掉本策略里的持仓,0会平掉此品种所有持仓,包括其他策略开的仓。


--  作者:jinzhe
--  发布时间:2014/4/15 9:10:22
--  
if  holding>0 and cond3 then
begin

   sellshort(1,0,market);

   buy(holding=0,1,market);

end

 

平空的持仓判断是<0不是>0


--  作者:Crocodile
--  发布时间:2014/4/15 10:29:16
--  
非常感谢,受教了