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

 
EVGENII SHELIPOV #:

Alexei, please enlarge the picture.

Zoomed in. I saw exactly what the arrow shows on the second lowest order price and on the ticket of the order that does not match the penultimate order criterion. Run my code and you will see the ticket of the lowest order. You can finish this function if you want to get not the BUY order from the bottom, but the second one.

 
Alexey Viktorov #:

Zoomed in. What I saw was the arrow pointing to the second lowest order price and to the ticket of the order not meeting the penultimate order criterion. If you run my code, you will see the ticket of the lowest order. You can develop this function to get not the BUY order below, but the second one.

I can only ask where there is an error in the code for the next-to-last order ticket determination.

//+----------------------------------------------------------------------------+
//| Расчет тикета предпоследнего ордера в сетке                                |
//+----------------------------------------------------------------------------+
int GetTicketPenultimateOrder()
  {
   penultimate_ticket = 0;
     {
      for(int cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
        {
         if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                  if(OrderTicket() > penultimate_ticket && penultimate_ticket != GetTicketMaxOrder())
                     penultimate_ticket = OrderTicket();
                 }
              }
           }
        }
     }
   return(penultimate_ticket);
  }
 
EVGENII SHELIPOV #:

I can only as my question where is the error in the code for determining the ticket of the penultimate order???

The error is that the price of the order is not taken into account in any way.

Somewhere in your dialog, there is advice to put the whole thing in an array and sort it to get any ticket by number. But in response, I don't understand how to do it.

Like this

//+------------------------------------------------------------------+
//| Расчет тикета второго снизу ордера BUY в сетке                   |
//+------------------------------------------------------------------+
int GetTicketMaxOrder()
 {
  int total = OrdersTotal(),
      arrSize = 0;
  double arr[][2];
  for(int cnt = 0; cnt < total; cnt++)
   {
    if(OrderSelect(cnt, SELECT_BY_POS) && OrderSymbol() == Symbol())// && OrderMagicNumber() == Magic)
     {
      if(OrderType() == OP_BUY)
       {
        arrSize = ArrayRange(arr, 0);
        ArrayResize(arr, arrSize+1);
        arr[arrSize][0] = OrderOpenPrice();
        arr[arrSize][1] = OrderTicket();
       }
     }
   }
  ArraySort(arr);
  return((int)arr[1][1]);
 }
/*****************************End program****************************/
 
EVGENII SHELIPOV #:

I can only answer as my question, where is the error in the code determining the ticket of the penultimate order???

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

And another gross error is that while you are searching for orders in the loop, you call a function which in turn also searches for orders... And when the code execution returns to the function, another order is already selected... And OrderTicket() returns quite different from what you expected.

 
Alexey Viktorov #:

The error is that the price of the order is not taken into account in any way.

Somewhere in your dialog there is an advice to put the whole thing into an array and sort it to get any ticket by count. But in response, I don't understand how to do it.

Like this

Alexey could you comment on the errors in the log

2021.11.07 12:17:40.791 2020.01.02 06:00:00 eGriD2 EURUSD,M5: incorrect start position 0 for ArraySort function

2021.11.07 12:17:40.791 2020.01.02 06:00:00 eGriD2 EURUSD,M5: array out of range in 'eGriD2.mq4' (664,18)

2021.11.07 12:17:40.792 2020.01.02 06:00:00 Testing pass stopped due to a critical error in the EA


 
EVGENII SHELIPOV # :

Alexey, could you comment on errors in the log

2021.11.07 12:17:40.791 2020.01.02 06:00:00 eGriD2 EURUSD,M5: incorrect start position 0 for ArraySort function

2021.11.07 12:17:40.791 2020.01.02 06:00:00 eGriD2 EURUSD,M5: array out of range in 'eGriD2.mq4' (664,18)

2021.11.07 12:17:40.792 2020.01.02 06:00:00 Testing pass stopped due to a critical error in the EA


These errors are not my code. I am not fluent in aglits language, I am using internal translator of this site. This is how it translates.

incorrect start position 0 for ArraySort function - incorrect start position 0 for ArraySort function

array out of range in 'eGriD2.mq4' (664,18) - array out of range in 'eGriD2.mq4' (664,18)

Testing pass stopped due to a critical error in the EA

So the code in the studio.

ps; Although, if you call this function when there are less than two orders, there will be these errors. I have not protected it against ......... but I guess I should have.

This is exactly the reason why I have absolutely no desire to help anyone... You're counting on a thoughtful application of my tips, but .........

 
Good afternoon. Can you tell me how to implement a minimum/maximum search for n bars?
 
Snajper007 #:
Good afternoon. Can you tell me how to implement a minimum/maximum search for n bars?
iHighest

iLowest

 
MakarFX

Here's another question. There is an indicator that draws a fractal. How do I check if there is a signal in n bars?

 
Snajper007 #:

Here's another question. There is an indicator that draws a fractal. How do I check if there is a signal in n bars?

First of all, it depends on the indicator that draws the fractals