Download MetaTrader 5
To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
Daminda
51
Daminda 2015.05.29 17:19 

i used following code to close only profit trades. but sometimes it close also loss trades. please some one help to resolve problem

if(OrderProfit()>0 && SellCondition==true)
  {
  int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];
    for (int i = 0; i < orderstotal; i++)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
        {
            continue;
        }
        ordticket[orders][0] = OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
        {
            bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
            if (ret == false)
            Print("OrderClose() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}
Osama Shaban
1348
Osama Shaban 2015.05.29 19:28  

It could be because of Swap !

Try to consider profitable trade is the one like this ...

Profit = OrderProfit() + OrderSwap() + OrderCommission();

 so, in this case, if you have Swap in negative higher than profit itself, then the order will not be considered as a profitable trade.

It could be an other reason, but this for sure will enhance the result a little. 

Daminda
51
Daminda 2015.06.06 09:41  
Osama Shaban:

It could be because of Swap !

Try to consider profitable trade is the one like this ...

 so, in this case, if you have Swap in negative higher than profit itself, then the order will not be considered as a profitable trade.

It could be an other reason, but this for sure will enhance the result a little. 

thanks osama for your comment. 
/
To add comments, please log in or register