Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1489

 
Maksim Burov Comment does not affect the speed of optimisation.
 
Maksim Burov #:

The information changes periodically.
For example, I want to see the position with the lowest opening price. Or to know the tick of the last closed position.
You can write everything in the print, but it is not convenient to look, you can miss. And so I can immediately see where I have errors.

The information does not change every tick? Nikolay also suggested that you can simply make the output after some timeout, thus reducing the frequency of this output.
 

Thank you very much for your help.
Now I have another task.

There is a function that counts the profit of all closed orders after a certain tick.
The time of order (position) closing has been added for checking.
Since everything was written in MQL4, and now it is being rewritten in MQL5, the question arose how to correctly and competently play this check.

Simply put, how to rewrite the code in MQL5)

double CalculateProfitHistory() 
{
   double profit = 0;
   int  i, ototal = OrdersHistoryTotal();

   for(i = ototal-1; i >=0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      {
         if(OrderSymbol() == Symbol() && OrderCloseTime() > 0)
         {
            if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
               if(OrderMagicNumber() == Magic )
               {
                  if (LockTicket !=0)
                  {
                     if (OrderTicket() >= LockTicket)
                     {
                        profit += OrderProfit()+OrderCommission()+OrderSwap();
                     }                  
                  }
               }
            }
         }
      }
   }
   return(profit);
}
 
Maksim Burov #:

Thank you all very much for your help.
Now another challenge.

There is a function that counts the profit of all closed orders after a certain tick.
The time of order (position) closing was added for checking.
Since everything was written in MQL4, and now it is being rewritten in MQL5, the question arose how to correctly and competently play this check.

Simply put, how to rewrite the code in MQL5)

// сначала выбираем нужный интервал
HistorySelect(TimeStart,TimeCurrent()+10);

// перебираем ордера в интервале
for(i=HistoryOrdersTotal()-1;i>=0;i--)
         {
          ord=HistoryOrderGetTicket(i);

         // далее получаем (или сразу сравниваем) любые свойства ордера, типа
          o_sym=HistoryOrderGetString(ord, ORDER_SYMBOL);
          o_magic=HistoryOrderGetInteger(ord, ORDER_MAGIC);
          ...
         }

Something like this.

 
Maksim Burov #:

Thank you all very much for your help.
Now another challenge.

There is a function that counts the profit of all closed orders after a certain tick.
The time of order (position) closing was added for checking.
Since everything was written in MQL4, and now it is being rewritten in MQL5, the question arose how to correctly and competently play this check.

Simply put, how to rewrite the code in MQL5)

Since it is not orders (previous post), but deals that will be searched, it is most convenient to use this code

HistoryPosition - неопубликованный функционал MQL5-языка.
HistoryPosition - неопубликованный функционал MQL5-языка.
  • 2023.11.22
  • www.mql5.com
HistoryPositionsTotal Возвращает количество всех закрытых позиций в истории. HistorySelect() не влияет на результат данной функции. int HistoryPositionsTotal(); Возвращаемое значение Значение типа
 
JRandomTrader #:

Something like that.

I failed( Can you elaborate a bit more on the basis of my code.

 
Maksim Burov #:

I failed( Can you elaborate a bit more based on my code.

Perhaps it would be better to look at the variant by Aleksandr Slavskii. I have not worked with MQL4, and with hedging too.

Or pay attention here and, just in case, here.

 
JRandomTrader #:

Perhaps it would be better to look at the variant by Aleksandr Slavskii. I have not worked with MQL4, and I have not worked with hedging either.

Or pay attention here and, just in case, here.

No better. These are usual functions from fxsaber.

Your variant is quite acceptable, only you need to replace orders with transactions. Profit, commission and swap are stored by deals, not orders.

 
Hello, I have a problem with the VPS. I don't get notifications on my phone when the MT4 is off. When the platform is on, notifications work.  Can someone please give me some advice on what could be wrong? Thank you
 

Alexey Viktorov #:

Your variant is quite acceptable, but you need to replace orders with transactions. Profit, commission and swap are stored by deals, not orders.

And take into account that an order can generate several deals.

So, either select deals for each order, or create an array/list (by the number of orders) of structures and fill them by selecting deals.
Reason: