- 精华
- 0
- 在线时间
- 12 小时
- UID
- 4583
- 积分
- 90
- 帖子
- 27
- 阅读权限
- 30
- 注册时间
- 2009-6-7
- 最后登录
- 2013-8-19
- 精华
- 0
- UID
- 4583
- 积分
- 90
- 帖子
- 27
- 主题
- 2
- 阅读权限
- 30
- 注册时间
- 2009-6-7
- 最后登录
- 2013-8-19
|
我写了策略,发现只能进行一个方向的开仓,请版主指教!
Params
Numeric lots(1);//每单的手数
Numeric AllowLong(1); //允许多单的数量
Numeric AllowShort(1);//允许空单的数量
Numeric AllowCountLoss(5);//允许亏损的次数
Numeric AllowAmountLoss(5000);//允许亏损的金额
Vars
Numeric preMP; //历史持仓
Numeric curMP;//现在持仓
Numeric max5Close;//最近5根bar收盘价的最大值
Numeric min5Close;//最近5根bar收盘价的最小值
Numeric max2High;//最近2根bar最高价的最大值
Numeric min2Low;//最近2根bar最低价的最小值
Numeric CountLong(0);//多单统计
Numeric CountShort(0);//空单统计
Numeric CountLoss(0);//亏损的次数统计
Numeric AmountLoss(0);//亏损的金额统计
Begin
preMP = MarketPosition;
If(Time > 0.145900 && Time < 0.150030 ) // 收盘平仓
{
If(preMP == 1){
Sell;
return;
}
else if(preMP == -1){
BuyToCover;
return;
}
return;
}
max5Close= Max(Max(Max(Max(Close[1],Close[2]),Close[3]),Close[4]),Close[5]);//前五个周期的最大值
min5Close=Min(Min(Min(Min(Close[1],Close[2]),Close[3]),Close[4]),Close[5]);//前五个周期的最小值
max2High= Max(High[1],High[2]);//前两个周期的最大值
min2Low=Min(Low[1],Low[2]);//前两个周期的最小值
if(preMp==0){
if(CountLong<AllowLong){//允许开多单
If(Close > max5Close){
Buy(lots);
CountLong=CountLong+1;
}
}
if(CountShort<AllowShort){//允许开空单
If(Close < min5Close){
SellShort(lots);
CountShort=CountShort+1;
}
}
}
Else If(preMP == 1) //多单
{
If (Close<min2Low){
Sell(lots);
CountLong=CountLong-1;
//大于预订的亏损次数
CountLoss = NumLosTrades();
if(CountLoss>=AllowCountLoss) {
curMP = MarketPosition;
If(curMP == 1){
Sell;
return;
}else if(curMP == -1){
BuyToCover;
return;
}
return;
}
//大于预订的亏损金额
AmountLoss = GrossLoss();
if(AmountLoss>=AllowAmountLoss) {
curMP = MarketPosition;
If(curMP == 1){
Sell;
return;
}else if(curMP == -1){
BuyToCover;
return;
}
return;
}
}
}
Else If(preMP == -1) //空单
{
If (Close >max2High){
BuyToCover(lots);
CountShort=CountShort-1;
//大于预订的亏损次数
CountLoss = NumLosTrades();
if(CountLoss>=AllowCountLoss) {
curMP = MarketPosition;
If(curMP == 1){
Sell;
return;
}else if(curMP == -1){
BuyToCover;
return;
}
return;
}
//大于预订的亏损金额
AmountLoss = GrossLoss();
if(AmountLoss>=AllowAmountLoss) {
curMP = MarketPosition;
If(curMP == 1){
Sell;
return;
}else if(curMP == -1){
BuyToCover;
return;
}
return;
}
}
}
End |
|