[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 580

 
Desead:

Damn, that's my problem. I wonder how to bypass it if I only need to delete the whole grid when I unload the robot... I can't even think of anything to do with it :(

A script can be loaded into deinit() via the library to chart:

 // 7.9. Функция загружает на указанный график скрипт по его имени.
 void ServiceLoadScript(int    hwndChart,    // Системный дескриптор окна графика, куда загружается скрипт.
                        string szNameScript, // Имя загружаемого скрипта.
                        int    bOK);         // Подтверждение запуска скрипта, при наличии диалогового окна свойств скрипта. Скрипт может не иметь окна свойств!
                                             // При использовании функции для загрузки скрипта из скрипта на текущем графике параметр не работает из-за
                                             // невозможности одновременной работы двух скриптов на одном графике.
                                             // TRUE - автонажатие на кнопку "OK" разрешено, FALSE - автонажатие на кнопку "OK" запрещено.

with the delete all orders function.

P.S. With some or other cost and energy you can solve ANY exotic desires of a trader, but whether you need this "exotic" sometimes ... :)))

 

eh...why couldn't the condition for checking open orders be written like this:

if OrdersTotal() > 0

everything is clear and understandable... it would be...

I've been trying to figure out HOW to write this condition for an hour...

 
lottamer:

eh...why couldn't the condition for checking open orders be written like this:

if OrdersTotal() > 0

everything is clear and understandable... it would be...

I've been trying to figure out HOW to write this condition for an hour...


Why not? You can, but it will be triggered if there are open or pending orders on any symbol.
 
rigonich:

Why not? you can, but it will be triggered if there are open or pending orders on any instrument.


I wish it would work - I have one position and one tool.

But it doesn't work!

It says there's an error in the code.

to this

---------------------------

int start()

{

//----

if OrdersTotal()> 0

PlaySound ("alert.wav");

//----

return(0);

}

-----------------------------

gives up 8 errors!!!

 

//---------------------------

int start()

  {

//----

   if (OrdersTotal()>0)

PlaySound ("alert.wav");

//----

  }

 return(0);

 
//-----------------------------

How about this?
 
BeerGod:

How about this?


:)))))))))))))))))))

gorgeous! Thank you

 
Desead:


So deinit is called when I delete a robot from a chart - I can't track this condition any other way..... it's probably easier to write a separate script that deletes all the remaining pendants, there is no other way.

By the way, another thought on the subject:

I think I have solved the problem of deleting pending orders. I determine the amount of "necessary" (to be removed) orders in a separate function, called this function and then while with condition (Total>0), then the cycle of removing for(int i=Total-1;i<=0l; i--), again calculating"necessary" and counter of removing attempts with exit fromwhile when the given level is reached. This way everything is deleted.

An infinite loop may occur here in case one of the orders disappears after the moment of counting for any reason


Why it cannot be done? For example, create a global variable at terminal level, assign a value to it and check start and change value of this variable via service -->global variables before it is switched off.
 
BeerGod:

And so ?


And may I ask, what are they trying to pull with this?

for(int i=0; i<OrdersTotal(); i++)

it looks like they're trying to count open positions using brute force method...

 

Good day!!! I can't find a nice solution to the situation. Here is a typical order setting. But if I give zero to my robot in parameters, i.e. no stops and takeprofits, nothing will work.

 if(!srabotka){
           OrderSend (Symbol( ), OP_BUY, lot ,NormalizeDouble(Ask, Digits), 5, NormalizeDouble( Ask- (stop*Point),Digits),   NormalizeDouble( Ask+( 45*Point),Digits), NULL, 450, 0, CLR_NONE);
           int Error=GetLastError();if (Error==0){  
           Sleep(2000); RefreshRates(); 
           OrderSend (Symbol( ), OP_SELL,  lot ,NormalizeDouble(Bid, Digits), 5, NormalizeDouble( Bid+ (stop*Point),Digits), NormalizeDouble( Bid-( 45*Point),Digits), NULL, 450, 0, CLR_NONE); 
           Error=GetLastError();
           if (Error==0){  profit = NormalizeDouble( Ask+( 45*Point),Digits); //tsena=Ask; perenos = false;  
           srabotka= true; }}}
           
           if (Error!=0){ string errorcomment = "Ошибка открытия  ордера OP_BUY"  + " " + Symbol() +  " " + ErrorDescript(Error); 
            Print (errorcomment);}
 

We can also set an if and enter an order with zeros for the second time, but it is a bit cumbersome.

 
lottamer:


And may I ask what they are trying to pull here?

for(int i=0; i<OrdersTotal(); i++)

it feels like it's trying to count open positions...


Well, it selects orders by specified parameters.

e.g. https://www. mql5.com/ru/forum/131859/page3#434221

Function NumberOfPositions().

This function returns the number of open positions at the moment. More accurate selection of counted positions is specified by external parameters:

  • sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
  • mn - position identifier, MagicNumber. The default value of -1 means any identifier.
  • //+----------------------------------------------------------------------------+
    //|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
    //+----------------------------------------------------------------------------+
    //|  Версия   : 19.02.2008                                                     |
    //|  Описание : Возвращает количество позиций.                                 |
    //+----------------------------------------------------------------------------+
    //|  Параметры:                                                                |
    //|    sy - наименование инструмента   (""   - любой символ,                   |
    //|                                     NULL - текущий символ)                 |
    //|    op - операция                   (-1   - любая позиция)                  |
    //|    mn - MagicNumber                (-1   - любой магик)                    |
    //+----------------------------------------------------------------------------+
    int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
      int i, k=OrdersTotal(), kp=0;
    
      if (sy=="0") sy=Symbol();
      for (i=0; i<k; i++) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
          if (OrderSymbol()==sy || sy=="") {
            if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
              if (op<0 || OrderType()==op) {
                if (mn<0 || OrderMagicNumber()==mn) kp++;
              }
            }
          }
        }
      }
      return(kp);
    }