- 精华
- 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
|
求助,程序这样写对吗
求助,不同条件下如何平仓!在不同均线排列下,根据条件建仓,建仓后当条件满足平仓所设定条件平仓
程序代码:
Params
Numeric Length(5);
Numeric Xb1(-4);
Numeric Xs1(2);
Numeric Xb2(-1);
Numeric Xs2(1);
Numeric Xb3(-1);
Numeric Xs3(1);
Vars
Numeric ma1;
Numeric ma2;
Numeric ma3;
Numeric hh;
Numeric ll;
Numeric ROCValue;
Numeric win1;
Numeric exitBar1;
Numeric win2;
Numeric exitBar2;
Numeric win3;
Numeric exitBar3;
Numeric myEntryPrice; //记录开仓情况
Begin
ma1=AverageFC(C,8);
ma2=AverageFC(C,13);
ma3=AverageFC(C,21);
ROCValue = (Close - Close[Length])/Close[Length]*100;
//不同均线排列的建仓如下:
if (ma1>ma2 and ma2>ma3)
{
myEntryPrice=1;
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);
exitBar1=5;// 持仓天数
if (ma1>ma3 and ma3>ma2)
{
myEntryPrice=2;
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);
exitBar2=3;
if (ma2>ma1 and ma1>ma3)
{
myEntryPrice=3;
If(rocvalue<0 and rocvalue>Xb3 and MarketPosition<>1)
buy(1,close);
if(rocvalue>0 and rocvalue<XS3 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)));
Win3=abs(hh-ll);
exitBar3=2;
//平仓条件如下:
If(myEntryPrice==1)
{
if( BarsSinceEntry==exitBar1 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win1*0.3,False);
}
If(myEntryPrice==2)
{
if( BarsSinceEntry==exitbar2 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win2*0.2,False);
}
If(myEntryPrice==3)
{
if( BarsSinceEntry==exitbar3 )
{
Sell( 0,Close );
BuyToCover( 0,Close );
}
//SetProfitTarget(1,win3*0.25,False);
}
End
求助,程序这样写对吗,为何平仓无法按指定持仓日期平仓,谢谢! |
|