Useful features from KimIV - page 10

 

Thank you KimIV!

 

DeleteOrders() function. Tester version.

Function DeleteOrders() is intended to delete pending orders BuyLimit, BuyStop, SellLimit and SellStop. The DeleteOrders() function is universal, i.e. it can be used to delete all pending orders that exist, as well as specific ones that meet the selection conditions set using the function parameters:

sy - Instrument name. Since only the current symbol can be traded in the tester, this parameter is not relevant for the tester version and is only needed for compatibility with the online version of this function. It is best to use values "" or NULL in the tester. The default value "" means any symbol.
op
- Type of trade operation, type of pending order. One of five values is possible: -1, OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT or OP_SELLSTOP. The default value of -1 indicates any order.
mn
- MagicNumber, identification number of the pending order. Default value -1 - means any magik.

//+----------------------------------------------------------------------------+
//| Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                    |
//+----------------------------------------------------------------------------+
//| Версия   : 13.06.2007                                                      |
//| Описание : Удаление ордеров. Версия функции для тестов на истории.         |
//+----------------------------------------------------------------------------+
//| Параметры:                                                                 |
//| sy - наименование инструмента   (NULL - текущий символ)                    |
//| op - операция                   ( -1  - любой ордер)                       |
//| mn - MagicNumber                ( -1  - любой магик)                       |
//+----------------------------------------------------------------------------+
void DeleteOrders(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), ot;
 
  if (sy=="" || sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ot=OrderType();
      if (ot==OP_BUYLIMIT || ot==OP_BUYSTOP || ot==OP_SELLLIMIT || ot==OP_SELLSTOP) {
        if (OrderSymbol()==sy && (op<0 || ot==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            OrderDelete(OrderTicket(), clDelete);
          }
        }
      }
    }
  }
}
 

DeleteOrders() function. Online version.


//+----------------------------------------------------------------------------+
//| Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                    |
//+----------------------------------------------------------------------------+
//| Версия   : 28.11.2006                                                      |
//| Описание : Удаление ордеров                                                |
//+----------------------------------------------------------------------------+
//| Параметры:                                                                 |
//|   sy - наименование инструмента   ( ""  - любой символ,                    |
//|                                    NULL - текущий символ)                  |
//|   op - операция                   (  -1 - любой ордер)                     |
//|   mn - MagicNumber                (  -1 - любой магик)                     |
//+----------------------------------------------------------------------------+
void DeleteOrders(string sy="", int op=-1, int mn=-1) {
  bool fd;
  int err, i, it, k=OrdersTotal(), ot;
  
  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ot=OrderType();
      if (ot>1 && ot<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ot==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            for (it=1; it<=NumberOfTry; it++) {
              if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
              while (!IsTradeAllowed()) Sleep(5000);
              fd=OrderDelete(OrderTicket(), clDelete);
              if (fd) {
                if (UseSound) PlaySound(NameFileSound); break;
              } else {
                err=GetLastError();
                Print("Error(",err,") delete order ",GetNameOP(ot),
                      ": ",ErrorDescription(err),", try ",it);
                Sleep(1000*5);
              }
            }
          }
        }
      }
    }
  }
}
 

Examples of how to use the DeleteOrders() function.


1. Delete all orders:

DeleteOrders();
2. Remove all BuyStop orders:
DeleteOrders(NULL, OP_BUYSTOP);

3. Delete all orders with magic 123456:

DeleteOrders(NULL, -1, 123456);

ZY. In the trailer is a working script with the same examples.

Files:
 
KimIV:

Examples of how to use the DeleteOrders() function.

At this rate, we'll never get to the library. I'll have to go to the library after all. If you invite me. I don't go without an invitation.
 
Every man has the right to the left... hee... I'm going to have a bit of fun with this

Ilnar, in the topic Pending Fractal Orders, asked, How to make pending orders on fractals?


I assume that Ilnar had some difficulty in detecting price levels of fractals. That's why I suggest using my function:


//+----------------------------------------------------------------------------+
//| Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                    |
//+----------------------------------------------------------------------------+
//| Версия   : 07.10.2006                                                      |
//| Описание : Поиск ближайшего фрактала.                                      |
//+----------------------------------------------------------------------------+
//| Параметры:                                                                 |
//|   sy - наименование инструмента     (NULL - текущий символ)                |
//|   tf - таймфрейм                    (  0  - текущий ТФ)                    |
//|   mode - тип фрактала               (MODE_LOWER|MODE_UPPER)                |
//+----------------------------------------------------------------------------+
double FindNearFractal(string sy="0", int tf=0, int mode=MODE_LOWER) {
  if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;
 
  for (s=2; s<100; s++) {
    f=iFractals(sy, tf, mode, s);
    if (f!=0) return(NormalizeDouble(f, d));
  }
  Print("FindNearFractal(): Фрактал не найден");
  return(0);
}
Function FindNearFractal() searches for the nearest fractal of the specified type at the specified symbol, at the given timeframe, and returns its price level. Knowing the price level of the location of the fractal, it is already easy to set an order at this level.
 
KimIV:
  int d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;
Question... What does d have to do with 0 ???
 
kharko:
KimIV:
  int d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;
Question... What does d have to do with 0 ???
I don't know... I had one case in my practice where it was d=0. I had to perform a check to make it equal to zero. Since then I've been dragging this code everywhere I could. Maybe it's unnecessary, but I think it's better to be too much than too little.
 
Vinin:
KimIV:

Examples of the use of DeleteOrders().

At this rate, we'll never make it to the library. We'll have to go to the library after all. If you invite me. I don't go without an invitation.

Vitek, what's the problem? Sure, come and dig the garden soon... you can help...

 
KimIV:
Vinin:
KimIV:

Examples of the use of DeleteOrders().

At this rate, we'll never make it to the library. We'll have to go to the library after all. If you invite me. I don't go without an invitation.

Vitek, what's the problem? Sure, come and dig the garden soon... you can help...

No problem with the garden, though I'm not the right age. Maybe we could get someone younger for the job. We'll go to the baths and have some kvass (you're allergic, I used to be too). We'll see how young people work. It wouldn't be serious.
Reason: