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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件策略编写求助区 → 请高手帮忙看看问题出在哪里

   

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


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

主题:请高手帮忙看看问题出在哪里

帅哥哟,离线,有人找我吗?
kingmoonwang
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
请高手帮忙看看问题出在哪里  发帖心情 Post By:2012/2/22 23:12:06 [只看该作者]

看了论坛上几位大侠的帖子。整合了一个每亏损一次加仓一手,一直加至m手,并加上了止盈止损的模板。不过加上止盈止损以后就有问题了,再测试就不能正确加仓了。感觉应该是止盈止损部分里全局变量赋值的原因。请高手帮忙看看问题出在哪里?

 

 

Input:m(5,1,10,1)

Variable: maxprofit=0;

Variable: sellnum=1;

Variable: buynum=1;

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

Longcond: = cross(ma5,ma10);

Shortcond: = cross(ma10,ma5);

 

if holding>0 then begin
 if Shortcond and c>enterprice then begin

  sell(1,holding,thisclose);
  sellnum:=1;
  buynum:=1;
  end 
 
 
 if Shortcond and c<enterprice then begin

  sell(1,holding,thisclose);
  if sellnum<m then sellnum:=sellnum+1;
  else sellnum:=m; 
  end
 
end


if holding<0 then begin
 if Longcond and c<enterprice then begin

   sellshort(1,holding,thisclose);
   buynum:=1;
   sellnum:=1;
   end

  
 if Longcond and c>enterprice then begin

   sellshort(1,holding,thisclose);
   if buynum<m then buynum:=buynum+1;
   else buynum:=m;
   end
  
end


if holding=0 then begin
 if Longcond then begin

  buy(1,buynum,thisclose);
  maxprofit:=0;
  end


 if Shortcond then begin

  buyshort(1,sellnum,thisclose);
  maxprofit:=0;
  end


end

end


    

 


//止盈止损,止盈止损后下次开仓数归1

win:=0;
win2:=0;


//多头止盈


if holding > 0 and enterbars > 2 then
begin
 win:=(c-enterprice)/enterprice*100; //记录最大盈利
 if win > maxprofit then
  maxprofit:=win;  
  win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end

 

 

//空头止盈
if holding < 0 and enterbars > 2 then

begin
 win:=(enterprice-c)/enterprice*100; //记录最大盈利
 if win > maxprofit then
  maxprofit:=win;
  win2:=(maxprofit-win)/maxprofit*100;//最大盈利后的回调幅度
 
end

 

//出现浮动亏损比如2%平仓

if holding>0  then begin
if win<-2 and numprofit(1)<0 then begin
  多止损: sell(1,holding,thisclose);
   buynum:=1;
   sellnum:=1;
   end
end

 

if holding<0 then begin

if win<-2  and numprofit(1)<0 then
   空止损: sellshort(1,holding,thisclose);
   buynum:=1;
   sellnum:=1;
   end

 

 

//出现最高盈利后,回落到盈利的60%平仓出场
if holding>0 then begin
if  win2>=60 and openprofit>0  then
   多止盈: sell(1,holding,thisclose);
     buynum:=1;
     sellnum:=1;
   end

 

if holding<0 then begin
if win2>=60 and openprofit>0   then
   空止盈: sellshort(1,holding,thisclose);
    buynum:=1;
    sellnum:=1;
   end

[此贴子已经被作者于2012-2-22 23:13:20编辑过]

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


加好友 发短信
等级:论坛游民 帖子:200 积分:1009 威望:0 精华:0 注册:2012/1/12 13:55:27
  发帖心情 Post By:2012/2/22 23:14:32 [只看该作者]

问题是你的总体设计思路是错的

每错一次加仓一手

你离失败就更近一步

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


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
  发帖心情 Post By:2012/2/22 23:16:23 [只看该作者]

楼上。先不管思路。我只是先想知道错在哪里。为什么不能加仓。能否指点一下。


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


加好友 发短信
等级:论坛游民 帖子:200 积分:1009 威望:0 精华:0 注册:2012/1/12 13:55:27
  发帖心情 Post By:2012/2/22 23:17:27 [只看该作者]

 等你亏光以后 就明白了

这行不是懒惰者和没有悟性人可以做的

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


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
  发帖心情 Post By:2012/2/22 23:19:10 [只看该作者]

我问的是程序为什么不能加仓。谢谢。

不是问操作思路为什么不能加仓。我只是想了解程序设计方面的问题。不是要了解怎么怎么操作。


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


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

2个错误比较明显:

1,平仓时,要全部平仓的吧 ,不能填,填0,这样写sell(1,0,thisclose);   sellshort(1,0,thisclose)

 

2

//出现浮动亏损比如2%平仓

if holding>0  then begin
if win<-2 and numprofit(1)<0 then begin
  多止损: sell(1,holding,thisclose);
   buynum:=1;      //止损后是要加仓的,怎么会重置为1呢?
   sellnum:=1;

   end
end

 

if holding<0 then begin

if win<-2  and numprofit(1)<0 then
   空止损: sellshort(1,holding,thisclose);
   buynum:=1;
   sellnum:=1;

   end

 

改为

//出现浮动亏损比如2%平仓

if holding>0  then begin
if win<-2 then begin
  多止损: sell(1,holding,thisclose); 
   end
end

 

if holding<0 then begin

if win<-2 then
   空止损: sellshort(1,holding,thisclose);
   end

 

 

 

另外,平仓最好放开仓前面。

[此贴子已经被作者于2012-2-22 23:51:49编辑过]

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


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
  发帖心情 Post By:2012/2/22 23:51:25 [只看该作者]

火哥这么晚还在啊。 辛苦了。

SELL可不可以不带0呢。之后还想用在图表的框架组合策略,上次回复我如果固定轮询,就不能带0,不然策略间会平仓。

[此贴子已经被作者于2012-2-23 0:09:47编辑过]

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


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
  发帖心情 Post By:2012/2/22 23:54:19 [只看该作者]

火哥。我有注明。 //止盈止损,止盈止损后下次开仓数归1

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


加好友 发短信
等级:论坛游民 帖子:261 积分:1358 威望:0 精华:0 注册:2011/12/13 10:55:10
  发帖心情 Post By:2012/2/23 0:12:42 [只看该作者]

测试了。如图。 还是有点问题。

 

空止盈2手之后的一单开多,直接开了2手。按照赋值,应该这里开一手吧。 请再帮忙看看。


图片点击可在新窗口打开查看此主题相关图片如下:加仓测试.jpg
图片点击可在新窗口打开查看

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


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

Input:m(5,1,10,1);
Variable: maxprofit=0;
Variable: sellnum=1;
Variable: buynum=1;
ma5:=ma(c,5);
ma10:=ma(c,10);
Longcond: = cross(ma5,ma10);
Shortcond: = cross(ma10,ma5);

if holding>0 then begin
 if Shortcond and c>enterprice then begin
  sell(1,holding,thisclose);
  sellnum:=1;
  buynum:=1;
 end 
 if Shortcond and c<enterprice then begin
  sell(1,holding,thisclose);
  if sellnum<m then sellnum:=sellnum+1;
 end
end

if holding<0 then begin
 if Longcond and c<enterprice then begin
  sellshort(1,holding,thisclose);
  buynum:=1;
  sellnum:=1;
 end
 if Longcond and c>enterprice then begin
  sellshort(1,holding,thisclose);
  if buynum<m then buynum:=buynum+1;
 end
end

if holding=0 then begin
 if Longcond then begin
  buy(1,buynum,thisclose);
  maxprofit:=0;
 end
 if Shortcond then begin
  buyshort(1,sellnum,thisclose);
  maxprofit:=0;
 end
end

win:=0;
win2:=0;

//多头止盈
if holding > 0 and enterbars > 2 then begin
 win:=(c-enterprice)/enterprice*100;
 if win > maxprofit then
 maxprofit:=win;    //记录最大盈利
 win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end

//空头止盈
if holding < 0 and enterbars > 2 then begin
 win:=(enterprice-c)/enterprice*100;
 if win > maxprofit then
 maxprofit:=win; //记录最大盈利
 win2:=(maxprofit-win)/maxprofit*100;//最大盈利后的回调幅度
end

//出现浮动亏损比如2%平仓
if holding>0 and win<-2 then begin // and numprofit(1)<0
 多止损: sell(1,holding,thisclose);
 buynum:=1;
 sellnum:=1;
end

if holding<0 and win<-2 then begin
 空止损: sellshort(1,holding,thisclose);
 buynum:=1;
 sellnum:=1;
end

//出现最高盈利后,回落到盈利的60%平仓出场
if holding>0 and win2>=60 and openprofit>0  then begin
 多止盈: sell(1,holding,thisclose);
 buynum:=1;
 sellnum:=1;
end

if holding<0 and win2>=60 and openprofit>0   then begin
 空止盈: sellshort(1,holding,thisclose);
 buynum:=1;
 sellnum:=1;
end


 回到顶部
总数 14 1 2 下一页