- 精华
- 0
- 在线时间
- 65 小时
- UID
- 2282
- 积分
- 265
- 帖子
- 51
- 阅读权限
- 50
- 注册时间
- 2008-9-5
- 最后登录
- 2012-2-27
- 精华
- 0
- UID
- 2282
- 积分
- 265
- 帖子
- 51
- 主题
- 17
- 阅读权限
- 50
- 注册时间
- 2008-9-5
- 最后登录
- 2012-2-27
|
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 编辑 ] |
|