Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1715

 
MakarFX #:
PM

check your wallet)

 
Alexey Viktorov #:

I encountered this in a thread

I copied it, looked at it, didn't understand anything, commented it out and forgot about it.

Now I remembered, I found it in my test codes, but I can't find it on the forum. I don't understand how macros work, maybe somebody can explain how it works or find the issue I copied it from...

In general I need to somehow define the macro substitution.........

This all works at compile stage, but not while loading the program

 

Good day to all !!!!

Could you please tell me what is the number of the penultimate ticket?

There is a function to determine the last order:

//+----------------------------------------------------------------------------+
//| Расчет тикета максимального ордера в сетке                                 |
//+----------------------------------------------------------------------------+
int GetTicketMaxOrder()
  {
   max_ticket = 0;
     {
      for(int cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
        {
         if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                  if(OrderTicket() > max_ticket)
                     max_ticket = OrderTicket();
                 }
              }
           }
        }
     }
   return(max_ticket);
  }

A variant to apply this function and suppose -1 from max_ticket does not work because EA trades several instruments and it may happen that between last and penultimate order an order of another instrument will be opened.

I need the order to be selected out of all orders minus the maximal one out of the ones left or the next highest ticket after the maximal one or it can be your decision. Thank you.

 
Vitaly Muzichenko #:

This all works at compile time, but not when the program is loaded

Doesn't the loading of a program depend on how it is compiled?

 
EVGENII SHELIPOV #:

Good day to all !!!!

This function cannot work correctly

int GetTicketMaxOrder()
  {
   max_ticket = 0;
     {
      for(int cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
        {
         if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
           {
 
MakarFX #:

This function can't work properly.

Yes Makar you are right as always it can be fixed but strangely enough this function works like clockwork

 
MakarFX #:

Exactly.

Is it possible to do it through?

The only way out is to write your own parameter panel and use it from OnInit() instead of using the standard input parameter mechanism.
 
Sergey Gridnev #:
The only way out is to write your own parameter panel and use it from OnInit() instead of using the standard input parameter mechanism.

Interesting idea! Thank you.

No, it's not interesting(

Every time you change timeframes again, it's not nice to enter the settings(

 
EVGENII SHELIPOV #:

Yes Makar you're right as always it's fixable but strangely enough this function works like clockwork

It worked like clockwork because you were looking for the last order

you couldn't find another ticket.

 
EVGENII SHELIPOV #:

Good day to all !!!!

Can you please tell me the number of the penultimate ticket?

It is possible to memorise a ticket before opening a new order.