以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  开平仓问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=149891)

--  作者:系统使用者
--  发布时间:2017/3/30 10:50:52
--  开平仓问题
VARIABLE:bj=0; 

if aspect=0 and holding=0 and bj=0 then begin
     bj:=1;
     buy(1,1,thisclose);
end
if H>=PBUY and C>=MAX(O,PBUY) AND MA1>REF(MA1,1) and holding=0  and bj=0 then begin
     bj:=2;
     buy(1,1,thisclose);
end
  
if aspect=1 and holding>0 and bj=1 then begin
    sell(1,0,thisclose);
    bj:=0;
end 
if C<stopprice and holding>0 and bj=2 then begin
    sell(1,0,thisclose);
    bj:=0;
end

if aspect=1 and holding=0 and bj=0 then begin
     bj:=1;
     BUYSHORT(1,1,thisclose);
end
if L<=PSELL and C<=MIN(O,PSELL) AND MA1<REF(MA1,1) and bj=0 then begin
     bj:=2;
     BUYSHORT(1,1,thisclose);
end
  
if aspect=1 and holding>0 and bj=1 then begin
    SELLSHORT(1,0,thisclose);
    bj:=0;
end 
if C<stopprice and holding>0 and bj=2 then begin
    SELLSHORT(1,0,thisclose);
    bj:=0;
end

k1的多单子用p1平仓
k2的多单子用p2平仓

Q1的空单子用D1平仓
Q2的空单子用D2平仓
开空同理。

--  作者:系统使用者
--  发布时间:2017/3/30 10:51:25
--  
图标不显示
--  作者:jinzhe
--  发布时间:2017/3/30 11:07:25
--  
你贴完整代码
--  作者:系统使用者
--  发布时间:2017/3/30 12:55:28
--  
这样编写是正确?
--  作者:系统使用者
--  发布时间:2017/3/30 12:56:54
--  
还是做空要另外使用一个变量?
--  作者:jinzhe
--  发布时间:2017/3/30 13:10:25
--  
if L<=PSELL and C<=MIN(O,PSELL) AND MA1<REF(MA1,1) and bj=0 then begin
     bj:=2;
     BUYSHORT(1,1,thisclose);
end

 

像前面那样加一个holding=0的条件

 

if aspect=1 and holding>0 and bj=1 then begin
    SELLSHORT(1,0,thisclose);
    bj:=0;
end 
if C<stopprice and holding>0 and bj=2 then begin
    SELLSHORT(1,0,thisclose);
    bj:=0;
end

这里的两句是holding<0

其他地方没问题

可以公用一个变量

[此贴子已经被作者于2017/3/30 13:10:55编辑过]