以文本方式查看主题

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

--  作者:老鼠吃猫
--  发布时间:2014/8/18 12:20:34
--  平仓问题
 下单开2单,满足条件1平1单,剩下的满足条件2全平。怎么编写?
--  作者:老鼠吃猫
--  发布时间:2014/8/18 12:20:53
--  
 谢谢指导
--  作者:老鼠吃猫
--  发布时间:2014/8/18 12:30:10
--  
 比如 5日穿10日 开2单,破5日平半仓,破10日全平。执行完半仓平仓后,中间不允许再开单,只等全平信号。辛苦图片点击可在新窗口打开查看
--  作者:pyd
--  发布时间:2014/8/18 13:11:17
--  

1,谁破5日,谁破10日?

2,执行完半仓平仓后,中间不允许再开单,等全平后再开仓?

[此贴子已经被作者于2014/8/18 13:16:12编辑过]

--  作者:老鼠吃猫
--  发布时间:2014/8/18 13:41:29
--  
 比如5日穿10日 开2单,收盘价格破5日平半仓,破10日全平。执行完半仓平仓后,中间不允许再开单,只等全平信号。等全平信号持仓单子全部结束后再开。辛苦
--  作者:pyd
--  发布时间:2014/8/18 13:49:16
--  

VARIABLE:n:=0;
ma5:ma(c,5);
ma10:ma(c,10);
jc:cross(ma5,ma10);
p1:cross(ma5,c);
p2:cross(ma10,c);
if jc and n=0 then buy(holding=0,2,market);

if p1 then
begin
sell(holding>0,0.5*holding,market);
n:=1;
end

if p2 then
begin
sell(holding>0,holding,market);
n:=0;
end


--  作者:老鼠吃猫
--  发布时间:2014/8/18 14:35:57
--  
 

VARIABLE:n:=0;
ma5:ma(c,5);
ma10:ma(c,10);
jc1:cross(ma5,ma10);

jc2:cross(ma10,ma5);

p11:cross(ma5,c);
p12:cross(ma10,c);

p21:cross(c,ma5);

p22:cross(c,ma10);





if jc1 and n=0 then buy(holding=0,2,market);

if p11 then
begin
sell(holding>0,0.5*holding,market);
n:=1;
end

if p21 then
begin
sell(holding>0,holding,market);
n:=0;
end



if jc2 and n=0 then buy(holding=0,2,market);

if p21 then
begin
sell(holding>0,0.5*holding,market);
n:=1;
end

if p22 then
begin
sell(holding>0,holding,market);
n:=0;
end




加进空头怎么空头测不出来。谢谢。


--  作者:pyd
--  发布时间:2014/8/18 14:43:26
--  

你没有写空头代码啊,你下边加buy sell的还是开多平多。

if p21 then //应该是p12吧?
begin
sell(holding>0,holding,market);
n:=0;
end


--  作者:老鼠吃猫
--  发布时间:2014/8/18 14:56:54
--  

VARIABLE:n:=0;
ma5:ma(c,5);
ma10:ma(c,10);


jc1:cross(ma5,ma10);

jc2:cross(ma10,ma5);


p11:cross(ma5,c);
p12:cross(ma10,c);

p21:cross(c,ma5);

p22:cross(c,ma10);





if jc1 and n=0 then buy(holding=0,2,market);

if p11 then
begin
sell(holding>0,0.5*holding,market);
n:=1;
end

if p12 then
begin
sell(holding>0,holding,market);
n:=0;
end



if jc2 and n=0 then buyshort(holding=0,2,market);

if p21 then
begin
sellshort(holding>0,0.5*holding,market);
n:=1;
end

if p22 then
begin
sellshort(holding>0,holding,market);
n:=0;
end


这样写还是不行呢。

 5日穿10日 开2单,收盘价格破5日平半仓,破10日全平。执行完半仓平仓后,中间不允许再开单,只等全平信号。等全平信号持仓单子全部结束后再开。
5日下穿10日,开2单,收盘价格上5日平半仓,上10日全平。执行完半仓平仓后,中间不允许再开单,只等全平信号。等全平信号持仓单子全部结束后再开。
还是老大把完整的给写写,我学习图片点击可在新窗口打开查看

--  作者:pyd
--  发布时间:2014/8/18 15:18:09
--  

VARIABLE:n:=0,m:=0;//开多开空分别设置变量
ma5:ma(c,5);
ma10:ma(c,10);

jc:cross(ma5,ma10);//金叉开多

sc:cross(ma10,ma5);//死叉开空

pd1:cross(ma5,c);//平多条件1
pd2:cross(ma10,c);//平多条件2

pk1:cross(c,ma5);//平空条件1

pk2:cross(c,ma10);//平空条件2

if jc and n=0 then buy(holding=0,2,market);//开仓时要限制holding=0

if pd1 then
begin
sell(holding>0,0.5*holding,market);//平多仓时要限制holding>0
n:=1;
end

if pd2 then
begin
sell(holding>0,holding,market);//平多仓时要限制holding>0
n:=0;
end


if sc and m=0 then buyshort(holding=0,2,market);//开仓时要限制holding=0

if pk1 then
begin
sellshort(holding<0,0.5*holding,market);//平空仓时要限制holding<0
m:=1;
end

if pk2 then
begin
sellshort(holding<0,holding,market);//平空仓时要限制holding<0
m:=0;
end