下载MetaTrader 5
要添加评论,请登录注册
共享您的程序。这将提高您的等级。
yeswan
7
yeswan 2013.07.30 01:05 

I need someone to help me to find the mistake in the code segment below,

the problem is: when the order which is OP_BUY found, there's always some order can not be closed by OrderClose(), shouldn't I use the "OrderSelect(i,SELECT_BY_POS,MODE_TRADES); " statement here ?

void CloseOrder(int closetype)
{
int i;
int count=1;
if(1==closetype)//
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OP_BUY==OrderType())
{
OrderClose(OrderTicket(),OrderLots(),Bid,5,White);
}
}
}

......

Fa Cao
1143
Fa Cao 2014.03.29 03:19  
yeswan:

I need someone to help me to find the mistake in the code segment below,

the problem is: when the order which is OP_BUY found, there's always some order can not be closed by OrderClose(), shouldn't I use the "OrderSelect(i,SELECT_BY_POS,MODE_TRADES); " statement here ?

void CloseOrder(int closetype)
{
int i;
int count=1;
if(1==closetype)//
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OP_BUY==OrderType())
{
OrderClose(OrderTicket(),OrderLots(),Bid,5,White);
}
}
}

......

there is something wrong in the loop "for()", it should be “for(i=OrdersTotal()-1; i>=0;i--)”; then you can select all orders.

if you code "for(i=0;i<OrdersTotal();i++)", only orders 0,2,4,6....will be selected, because "OrdersTotal()" is different for each cycle.

in addition, your other codes are not good enough even there is not big logic disadvantage.

/
要添加评论,请登录注册