cm_DeleteOrders

Author: Copyright � 2012, Vladimir Hlystov
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
cm_DeleteOrders
//+------------------------------------------------------------------+
//|                                         Close pending orders.mq4 |
//|                               Copyright © 2012, Vladimir Hlystov |
//|                                                cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Vladimir Hlystov"
#property link      "http://cmillion.narod.ru"
extern bool comment = true;  //display information on screen
//+------------------------------------------------------------------+
int start()
  {
   int n,Ticket;
   string txt=StringConcatenate("The script removes all pending orders, the start ",TimeToStr(TimeCurrent(),TIME_SECONDS));
   if (comment) Comment(txt);
   for (int j = OrdersTotal(); j >=0 ; j--)
   {
      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType()>1)
         {
            Ticket = OrderTicket();
            while(true)
            {
               if (OrderDelete(Ticket))
               { 
                  txt = StringConcatenate(txt,"\nOrderDelete ",Ticket);
                  break;
               }
               else
               {
                  n++;
                  if (n>10) break;
                  Sleep(1000);
                  RefreshRates();
                  txt = StringConcatenate(txt,"\nOrderDelete error ",GetLastError()," Ticket ",Ticket);
               }
            }
         }
      }
      if (comment) Comment(txt);
   }
   if (comment) Comment(txt,"\nThe script has finished its work ",TimeToStr(TimeCurrent(),TIME_SECONDS));
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---