菜鸟求教

楼主  收藏   举报   帖子创建时间:  2019-05-05 05:23 回复:0 关注量:938
#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  
有哪位大神能帮忙修改下



打赏