Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 162

 

Hello!

As usual need help, can't figure out how to correctly select pending orders by magic number. Can someone please send me the code to see how to do it by example. Thanks in advance).

 
zaqwsx123:

Hello!

As usual I need help, I can't figure out how to correctly select pending orders by magic number. Can someone please send me the code to see how to do it by example. Thanks in advance).


ALXIMIKS 11.09.2013 21:36 #

void DeletePendingOrders()
{
    int NumberOfTry,
        err,
        ticket;

   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1)
      {
         ticket = OrderTicket();
         NumberOfTry=0;

         while (NumberOfTry < 5)
         {
            while (!IsTradeAllowed()) Sleep(5000);
      
            if (OrderDelete(ticket, Red))
                breake;
            else
                err = GetLastError();
      
            if (err > 0)
            { 
              Print(NumberOfTry," #",ticket," Error modifing order: (", err , ") ");
              Sleep(5000);  NumberOfTry++;
            }
         }
      }
   }
}

someone once asked for help with this code, it's an example of how to remove all pending orders

I do not know if the code will always be adequate in the tester, I'll say nothing about the real one

 
ALXIMIKS:

someone once asked for help with this code, here is an example of how to delete all pending orders

I don't know if the code will always be adequate in the tester.

I don't understand, if you are not sure about the code, why do you show it to a questioner? The answer should always be correct, not "maybe it'll work - I made some mistakes there"...
 
zaqwsx123:

Hello!

As usual I need help, I can't figure out how to correctly select pending orders by magic number. Can someone please send me the code to see how to do it by example. Thanks in advance)

It selects any given order opened last and returns its ticket. If there is no such order, it returns -1 :

//-----------------------------------------------------------------------------+
int GetTicketLastOpenOrder(string sy, int op, int mn) {
   int   i, j=-1, t=0, k=OrdersTotal()-1;
   for (i=k; i>=0; i--) {                       // цикл от конца к началу
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderMagicNumber()!=mn)   continue;// если магик не тот - переходим к следующему
         if (OrderSymbol()!=sy)        continue;// если символ не тот - переходим к следующему
         if (OrderType()!=op)          continue;// если тип не тот - переходим к следующему
         if (t<OrderOpenTime()) {   // выбран нужный, ...
            t=OrderOpenTime();      // ... ищем последний ...
            j=i;                    // ... открытый ордер
            }
         }
      else Print("FUNC GetTicketLastOpenOrder() ошибка выбора ордера "+GetLastError());
      }
   if (OrderSelect(j,SELECT_BY_POS)) return(OrderTicket()); // если найден ордер, вернём его тикет
   return(-1);                                              // иначе - возвращаем -1
}
//-----------------------------------------------------------------------------+
 
artmedia70:
Man, I do not understand, if you are not sure in the code, why do you show it to the person asking the question? The answer should always be correct, not "maybe it will work - I made some mistakes there"...

Well, that's the man's way of asserting himself.

He's already shown his arrogance here.

 
PapaYozh:

Well, that's the man's way of asserting himself.

He's already shown his arrogance here.

Well... some people beat their wives, some people yap on forums, some people make revolutions... People are different. To each his own.
 
artmedia70:
Well ... someone beats his wife, someone yapping on forums, someone makes revolutions .... People are different. To each his own.

If a person asks a question at night, the answer to which is not that complicated, but due to my inexperience, purely on principle, I cannot vouch for the 100% correctness of the code,

he's better off waiting 8 hours for an answer from a professional?

Or they could give quick help in getting my code right (if a developer is not hopeless...).

I chose the second option, and I think it is justified, think what you want and be happy.

 
ALXIMIKS:
artmedia70:
Well... some people beat their wives, some people yapping on forums, some people making revolutions... People are different. To each his own.

If a person asks a question at night, the answer to which is not that complicated, but due to my inexperience, purely on principle, I cannot vouch for the 100% correctness of the code,

he's better off waiting eight hours for an answer from a professional?

Of course a novice would better wait till morning to search for errors in somebody else's code than have a good sleep and get a competent answer.

What I mean is that when you answer a beginner, think about the fact that he might not have much experience at all.

 

There is a library hoz_LoggingToAnywhere@Library.mq4, which is called from the header file hoz_Base@Include.mqh

When compiling the library hoz_LoggingToAnywhere@Library.mq4 I see it in the log:

'StringConcatenate' - incompatible types        D:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\include\hoz_Base@Include.mqh (75, 12)

I go there... And there I see:

   //---- Контролируем возможные ошибки
   fPrint (StringConcatenate ("fInitBase() => ", fErrorToString (bi_Err)));

Calling this fPrint function from other libraries doesn't get blamed anywhere, but from the header file... it does. Why is this so? It's already copied character to character...

 
hoz:

There is a library hoz_LoggingToAnywhere@Library.mq4, which is called from the header file hoz_Base@Include.mqh

When compiling the library hoz_LoggingToAnywhere@Library.mq4 I see it in the log:

I go there... And there I see:

Calling this fPrint function from other libraries doesn't get blamed anywhere, but from the header file... it does. Why is this so? It's already copied right symbol to symbol...


Because this function has (...) as a parameter, and you need the exact composition


link:

https://docs.mql4.com/ru/basis/preprosessor/import

Since the imported functions are outside the module being compiled, the compiler cannot check if the parameters passed are correct. Therefore, in order to avoid run-time errors, the exact composition and order of parameters passed to the imported functions must be specified. Parameters passed to imported functions (both from EX4 and DLL modules) cannot have default values.