4评论

0收藏

菜鸟求教

avatar 撸啊撸 | 3130 人阅读 | 4 人评论 | 2016-05-03

#define Magic 12345
extern int Ma1=10;
extern int Ma2=30;
extern int Slip=3;
extern double lot=1.0;
extern int sun=200;
extern int ying=500;
int HoldingOrderType;
int Ser;
int start()
{
//----
int Cnt=GetHoldingOrderCnt();
if (Cnt<=0)//空仓
{
if (YesOrNo(OP_SELL))//多单入场条件
{
int Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,Slip,Ask-sun*Point,Ask+ying*Point,"",Magic,0,0);//开多头新单
if (Ticket<0)
{
Print(GetLastError());
return(0);
}
}else if (YesOrNo(OP_BUY))// 空单入场条件
{
Ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,Slip,Bid+sun*Point,Bid-ying*Point,"",Magic,0,0);//开空头新单
if (Ticket<0)
{
Print(GetLastError());
return(0);
}
}else return(0);

}else//持仓
{
switch(HoldingOrderType)
{
case OP_BUY:
if (YesOrNo(OP_BUY))
{
if (OrderClose(Ser,OrderLots(),Bid,Slip,CLR_NONE))
{
return(0);
}else
{
Print(GetLastError());
return(0);
}
}
break;
case OP_SELL:
if (YesOrNo(OP_SELL))
{
if (OrderClose(Ser,OrderLots(),Ask,Slip,CLR_NONE))
{
return(0);
}else
{
Print(GetLastError());
return(0);
}
}
break;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
int GetHoldingOrderCnt()
{
int j=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
j=j+1;
HoldingOrderType=OrderType();
Ser=OrderTicket();
}
}
return(j);

}
//========================
bool YesOrNo(int Type)
{
double Ma1Data=iMA(NULL,0,Ma1,0,MODE_SMA,PRICE_CLOSE,1);
double Ma1Data1=iMA(NULL,0,Ma1,0,MODE_SMA,PRICE_CLOSE,2);
double Ma2Data=iMA(NULL,0,Ma2,0,MODE_SMA,PRICE_CLOSE,1);
double Ma2Data1=iMA(NULL,0,Ma2,0,MODE_SMA,PRICE_CLOSE,2);
switch(Type)
{
case OP_BUY:
if (Ma1Data1>Ma2Data1 && Ma1Data<Ma2Data)
{
return(true);
}else return(false);
break;
case OP_SELL:
if (Ma1Data1<Ma2Data1 && Ma1Data>Ma2Data)
{
return(true);
}else return(false);
break;
}

}

这有两个警告return value of 'OrderSelect' should be checked   和not all control paths return a value  
有哪位大神能帮忙修改下



""
还没有人打赏,支持一下

评论|共 4 个

523158240

发表于 2016-5-3 21:59:08 | 显示全部楼层

会的人帮忙指点下啊

leader

发表于 2016-5-4 08:16:26 | 显示全部楼层



OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

→→→→→→

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)); else;

肥小能

发表于 2016-5-4 08:19:03 | 显示全部楼层

三楼的不行的话,改成这个看看if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

圈大哥

发表于 2016-5-4 08:26:04 | 显示全部楼层

第二个问题  你加一行这个看看

if(sells>0) return(true);
   else     return(false);

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

EA之家评论守则