设为首页收藏本站

 找回密码
 注册
查看: 3569|回复: 7
打印 上一主题 下一主题

急!请nopain 老师帮助修改程序 [复制链接]

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
跳转到指定楼层
1#
发表于 2009-9-22 23:20:45 |只看该作者 |倒序浏览
nopain老师您好!再次请教您还是关于  (求助,不同条件下如何平仓!)的问题。我按照您的提示增加了序列变量,但还是未能按照条件设定日期平仓,现将源程序附上,望老师能给予指导修正。不尽感激!


Params
Numeric Length(5);


Numeric Xb1(-4);
Numeric Xs1(2);


Numeric Xb2(-1);
Numeric Xs2(1);


Numeric Xb3(-1);
Numeric Xs3(1);


Numeric Xb4(-1);
Numeric Xs4(1);


Numeric Xb5(-5);
Numeric Xs5(4);


Numeric Xb6(-1);
Numeric Xs6(2);

Vars

Numeric ma1;


Numeric ma2;


Numeric ma3;


Numeric hh;


Numeric ll;


Numeric ROCValue;


Numeric win1;     

Numeric win2;
Numeric win3;
Numeric win4;
Numeric win5;
Numeric win6;
NumericSeries myEntryPrice;                         //记录不同均线排列的开仓,以便为平仓时做判断条件

Begin

ma1=AverageFC(C,8);


ma2=AverageFC(C,13);


ma3=AverageFC(C,21);


ROCValue = (Close - Close[Length])/Close[Length]*100;

if(currentbar>0)


{

myEntryPrice=myEntryPrice[1];       / /
这句是老师提示的,学生不大明白什么意思请老师讲解
}

//
开仓条件如下:

if (ma1>ma2 and ma2>ma3)


{

If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)

buy(1,close);

if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)

SellShort(1,close);
}

hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));

ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));

Win1=abs(hh-ll);                                   //记录此均线排列状态下开仓时收盘与开盘的高低价差,以便
                                                           //于盈利条件平仓时使用(这样写对吗)

myEntryPrice=1;                                  //记录以上开仓时的均线状态,

if (ma1>ma3 and ma3>ma2)

{

If(rocvalue<0 and rocvalue>Xb2 and MarketPosition<>1)
Buy(1,close);

if(rocvalue>0 and rocvalue<XS2 and MarketPosition<>-1)

SellShort(1,close);
}
hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win2=abs(hh-ll);
myEntryPrice=2;

if (ma2>ma1 and ma1>ma3)


...                                        / /
如上
………

if (ma3>ma2 and ma2>ma1)


{

If(rocvalue<0 and rocvalue>Xb6 and MarketPosition<>1)

buy(1,close);

if(rocvalue>0 and rocvalue<XS6 and MarketPosition<>-1)

SellShort(1,close);
}
hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
Win6=abs(hh-ll);
myEntryPrice=6;

//出场条件:1.以建仓时均线排列所设定的日期 2.以建仓时所设定的盈利值

If(myEntryPrice==1)                                      //即满足在ma1>ma2 and ma2>ma3 条件下建仓
{

if( BarsSinceEntry==5 )                                 //按
持仓日期平仓
{

Sell( 0,Close );

BuyToCover( 0,Close );
}
SetProfitTarget(1,win1*0.3,False);               //按盈利百分比平仓
}


If(myEntryPrice==2)                                 //即满足在 ma1>ma3 and ma3>ma2条件下建仓

{
if( BarsSinceEntry==4 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
SetProfitTarget(1,win2*0.2,False);
}

………

If(myEntryPrice==6)
………
End


[ 本帖最后由 qqboy1978 于 2009-9-22 23:31 编辑 ]

Rank: 10Rank: 10Rank: 10

精华
2
UID
4130
积分
20901
帖子
6519
主题
17
阅读权限
200
注册时间
2009-4-15
最后登录
2019-4-12
2#
发表于 2009-9-23 09:49:33 |只看该作者
看了一下你的代码,修改如下:
if (ma1>ma2 and ma2>ma3)
{
If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
buy(1,close);
If(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
SellShort(1,close);
myEntryPrice=1;//满足条件开仓,赋予相应值
}Else
myEntryPrice=myEntryPrice[1];//需要每个bar传递

删除了:if(currentbar>0)
{
myEntryPrice=myEntryPrice[1];      
}

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
3#
发表于 2009-9-23 11:51:51 |只看该作者
老师,平仓还是出错,根据您的提示我程序这样改,但结果为无论任何均线状态,持仓都为3日


画圈地方应为持仓5日出场

// 建仓条件

if (ma1>ma2 and ma2>ma3)
        {         
        If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
        buy(1,close);
        
        if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
        SellShort(1,close);
                  
        hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
        ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
        Win1=abs(hh-ll);
        myEntryPrice=1;
        //exitBar1=5;
        }
        Else myEntryPrice=myEntryPrice[1];
        
        
        if (ma1>ma3 and ma3>ma2)
        。。。。。

//平仓条件
If(myEntryPrice==1)
{
if( BarsSinceEntry==5 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win*0.3,False);
}
。。。。
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
2
UID
4130
积分
20901
帖子
6519
主题
17
阅读权限
200
注册时间
2009-4-15
最后登录
2019-4-12
4#
发表于 2009-9-23 12:26:51 |只看该作者
检查一下代码的其他地方

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
5#
发表于 2009-9-24 12:39:44 |只看该作者
代码检查过,还是不行,烦请老师再帮检查是否程序写法有误.谢谢!
// 建仓
if (ma1>ma2 and ma2>ma3)
        {         
      
   If(rocvalue<0 and rocvalue>Xb1 and MarketPosition<>1)
        buy(1,close);        
        if(rocvalue>0 and rocvalue<XS1 and MarketPosition<>-1)
        SellShort(1,close);
        
        hh=max(HighestFC(open,(length+1)),HighestFC(close,(length+1)));
        ll=min(LowestFC(open,(length+1)),LowestFC(close,(length+1)));
        Win1=abs(hh-ll);
        myEntryPrice=1;         //满足条件后,将1赋予myentryprice
        
  }
        Else myEntryPrice=myEntryPrice[1];
        
        
        if (ma1>ma3 and ma3>ma2)
      
  {
   ......
  win2=abs(hh-ll);
       myentryprice=2;      //满足条件后,将2赋予myentryprice
       } 
  Else myEntryPrice=myEntryPrice[1];
       ......
  if(......)
       {
       ..........
       win6=abs(hh-ll);
       myentryprice=6;  //满足条件后,将6赋予myentryprice
       }
       Else myEntryPrice=myEntryPrice[1];

//平仓这样写对吗?
If(myEntryPrice==1)  //根据不同建仓条件平仓
{
if( BarsSinceEntry==5 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win1*0.3,False);
}
.....

If(myEntryPrice==6)
{
if( BarsSinceEntry==2 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win6*0.3,False);
}
end

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
20
UID
4
积分
22709
帖子
4802
主题
64
阅读权限
255
注册时间
2007-7-20
最后登录
2024-1-15
6#
发表于 2009-9-24 16:18:39 |只看该作者
在平仓之前加一句
Commentary("myEntryPrice="+Text(myEntryPrice));

然后看看其值是否如你想象的那样。

使用道具 举报

Rank: 4

精华
0
UID
2282
积分
265
帖子
51
主题
17
阅读权限
50
注册时间
2008-9-5
最后登录
2012-2-27
7#
发表于 2009-9-24 20:27:14 |只看该作者
怎么办还是不行
//If(myEntryPrice==1  //只有将此变量关闭才能显示出平仓,且用Commentary注释myEntryPrice始终都=6,程序赋予变量6次
        if (BarsSinceEntry==4 )
        {
        Commentary("myEntryPrice="+Text(myEntryPrice));

        Sell( 0,Close );
        BuyToCover( 0,Close );
        }
...
// If(myEntryPrice==6 )
if (BarsSinceEntry==2 )
        {
        Commentary("myEntryPrice="+Text(myEntryPrice));

        Sell( 0,Close );
        BuyToCover( 0,Close );
        }
end

[ 本帖最后由 qqboy1978 于 2009-9-24 20:53 编辑 ]

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
4250
积分
891
帖子
198
主题
42
阅读权限
60
注册时间
2009-4-28
最后登录
2019-12-1
8#
发表于 2009-11-9 17:51:43 |只看该作者
http://www.tradeblazer.net/forum/thread-5588-1-1.html

我认为错在只用了一个
myEntryPrice记录器  却要记录 6种  可能 同时 发生的事情。

在用 几个 例如

myEntryPrice1
myEntryPrice2
myEntryPrice3



就可以了

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-18 22:17

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部