Download MetaTrader 5
To add comments, please log in or register
Do you want to write a technical indicator? Find solution in MQL5 Reference!
lukinho158
23
lukinho158 2014.05.27 18:50 

Hello guys,

I just wann ask you what is wrong with this piece of code?

void CloseOrders()

   {

      int total = OrdersTotal();

      int i;

    

      for(i = 0; i < total; i++)

         {

            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

               {

                  if(OrderType() == OP_BUY || OrderType() == OP_SELL)

                     {

                        if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0))

                           Alert("Failed! Error: "+DescriptionGetLastError(GetLastError()));

                     }   

               }

            else

               Alert("Order Select Error: "+DescriptionGetLastError(GetLastError()));

         }

   } 

I tried to delete open ordes. It delete two sometime three orders and then it write error message  Invalid function parameter value. How can I solve it? Or knows somebody how to delete opened orders by better way?

Thank for your responses.

Lukas 

whroeder1
13597
whroeder1 2014.05.27 18:59  
lukinho: I tried to delete open ordes.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You can not delete open orders, only pending ones.
  3. You MUST count down. Loops and Closing or Deleting Orders - MQL4 forum
  4. You MUST use RefreshRates between server calls (multiple orders, multiple calls,) so OrderClosePrice is updated.
/
To add comments, please log in or register