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

 
Nerd Trader #:
I didn't know there was an ObjectsDeleteAll.

I use it everywhere

   ObjectsDeleteAll(0,Prefix);
 
MakarFX #:

I use it everywhere

I'm used to having to do everything myself in C, but mql4 has ready-made solutions.
 
Nerd Trader #:
I did not know that there is ObjectsDeleteAll and now I want to get to the bottom of it.

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, help and discussion of algorithms and codes

Artyom Trishkin, 2021.09.30 05:31

You may delete it. If you have already understood the reason, you may better understand it once, so that you don't try to do it again.

When deleting an object from an array, the position of the next one is shifted in the array and the loop index now points to where? Think about it.


 
Artyom Trishkin #:

Got it, thanks.
 
Valeriy Yastremskiy #:

Print the number, ticket and order type before the second if and inside the second if.

Got it. Tried it. It's counting, but it's not quite right. It counts orders by the tick. I need the last but one order at the top of the grid. If the price goes down and another order is opened, the penultimate order is the one with the maximal OrderOpenPrice.

 
ObjectsDeleteAll is fine. But if you need to delete not EVERYTHING, you cannot do it without a loop with conditions! And that's where the golden rule is - you have to start at the end!
 
pribludilsa #:
How to work with a file in an mql5 program without writing the file to disk, but work only in RAM, to speed up. I want to transfer data from an mql5 program to a program on my computer.

Here it is:

https://www.mql5.com/ru/articles/503

Связь с MetaTrader 5 через именованные каналы без применения DLL
Связь с MetaTrader 5 через именованные каналы без применения DLL
  • www.mql5.com
Перед многими разработчиками встает одинаковая проблема - как пробиться в песочницу торгового терминала без применения небезопасных DLL. Одним из простых и безопасных методов является использование стандартных именованных каналов (Named Pipes), которые работают как обычные файловые операции. Они позволяют организовать межпроцессорное клиент-серверное взаимодействие между программами. Посмотрите практические примеры на C++ и MQL5 в виде сервера, клиента, обмен данными между ними и замер производительности.
 
makssub #:

Got there. Tried it. It's counting, but it's not quite right. It counts orders by the tick. I need the last but one order at the top of the grid. If the price goes down and another order is opened, the penultimate order is the one with the maximal OrderOpenPrice.

double FindOpenPrice(int a=-1)// 0 - макс, 1 - мин
{
   double maxopenprice=0;
   double minopenprice=DBL_MAX;
   double openprice=0;
   
   for(int cnt=OrdersTotal()- 1 ; cnt>=0; cnt--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
         {
            if (OrderType() == OP_SELL || OrderType() == OP_BUY)
            {
               if (a==0 && maxopenprice<OrderOpenPrice())
               {
               maxopenprice = OrderOpenPrice(); openprice=maxopenprice ;
               }
               if (a==1 && minopenprice>OrderOpenPrice())
               {
               minopenprice= OrderOpenPrice(); openprice=minopenprice;
               }
            }
         }
      }
   }
   return(openprice);
}
 
makssub #:

Got there. Tried it. It's counting, but it's not quite right. It counts orders by the tick. I need the last but one order at the top of the grid. If the price goes down and another order is opened, the penultimate order is the one with the maximal OrderOpenPrice.

So, do not search by price but by opening time.
 
MakarFX #:

The last one comes out, not the penultimate one(