欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → [求助]为什么该程序只开多不开空?

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有5539人关注过本帖树形打印复制链接

主题:[求助]为什么该程序只开多不开空?

美女呀,离线,留言给我吧!
ppliu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:25 积分:156 威望:0 精华:0 注册:2010/12/22 16:29:24
[求助]为什么该程序只开多不开空?  发帖心情 Post By:2011/2/25 11:12:01    Post IP:118.132.166.236[只看该作者]

我是新手上路,对金子塔语言正在学习中,下面是试着编写的程序,开仓条件是随机的,但是不知为什么只开多,不开空,请求帮助,谢谢啊!

input:n1(3,1,50,2);
input:n2(30,5,60,5);
variable:win1=0,win2=0,maxprofit=0,b=0,s=0;
a:=rand(10000);        //产生随机数,判断其奇偶性,确定做多做空//
if a%2=0 then
b:=1;
else
s:=1;
if b and holding=0 and time=90100 then begin
buy(1,1,limitr,close);
maxprofit:=0;
end
if s and holding=0 and time=90100 then begin
buyshort(1,1,limitr,close);
maxprofit:=0;
end
if holding>0 then begin
  if enterbars>0 then begin
win1:=(close-ENTERPRICE)/ENTERPRICE*100;
         IF win1>MAXPROFIT THEN
             MAXPROFIT:=WIN1;
         WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
     END
     if win1<-n1 then
     sell(1,holding,limitr,close);
     if win2>n2 and openprofit>0 then
     sell(1,holding,limitr,close);
end
if holding<0 then begin
   if enterbars>0 then begin
   win1:=(enterprice-close)/enterprice*100;
   if win1>maxprofit then
   maxprofit:=win1;
   win2:=(maxprofit-win1)/maxprofit*100;
   end
   if win1<-n1 then
    buyshort(1,holding,limitr,close);
    if win2>n2 and openprofit>0 then
    buyshort(1,holding,limitr,close);
end
if time=145800 and holding<>0 then begin
   sell(holding>0,holding,limitr,close);
   sellshort(holding<o,holding,limitr,close);
end


 回到顶部
帅哥哟,离线,有人找我吗?
fly
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:5082 积分:17642 威望:0 精华:6 注册:2010/7/15 9:05:58
  发帖心情 Post By:2011/2/25 11:24:36    Post IP:58.246.57.26[只看该作者]

楼主可以直接设定 S:=1.看看会不会开空



金字塔—专业程序化交易量化投资平台

客户服务部

-----------------------------------------------------------

欢迎您参加我公司的技术培训,具体培训需求请发邮件到

service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
美女呀,离线,留言给我吧!
ppliu
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:25 积分:156 威望:0 精华:0 注册:2010/12/22 16:29:24
  发帖心情 Post By:2011/2/25 11:32:45    Post IP:118.132.166.236[只看该作者]

直接设置s:=1,也还是不做空,很奇怪呢!


 回到顶部
帅哥哟,离线,有人找我吗?
阿火
  4楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 原leevolvo
等级:版主 帖子:2160 积分:10563 威望:0 精华:11 注册:2010/11/3 11:21:19
  发帖心情 Post By:2011/2/25 14:08:45    Post IP:120.32.130.106[只看该作者]

b 是全局变量。

a是偶数的话,b=1,

下一根K线,a是奇数的话。此时b依然等于1.

 

在平仓后,你要把b重新赋值为 0


 回到顶部