Questions from Beginners MQL5 MT5 MetaTrader 5 - page 979

 
Kolya32:
Hello. Do you know if there is a set of ready-to-use functions for MQL5? For example, the MQL4 library by Igor Kim aka KimIV https://www.mql5.com/ru/forum/131859

All these functions can be cross-platform (work the same in MT4 and MT5 without changing the code) if you use the MT4Orders library.

 
fxsaber:

All these functions can be cross-platform (without changing the code to work the same in MT4 and MT5) if you use the MT4Orders library.

Thank you. I have created an EA in mql5, copied everything from mql4 EA and added the library. At the beginning there were 104 errors without the library and 74 with the library. That is quite understandable, because the description of the library says that the library coversonly the order system!And I have lots and lots more things in my EA...
 
Kolya32:
I have created an EA in mql5 and copied everything from it. I have created an EA in mql5, copied into it everything from mql4 and attached the library. At the beginning there were 104 errors without the library and 74 with the library. That is quite understandable, because the description of the library says that the library coversonly the order system!And I have lots and lots more things in my EA...

There are plenty of examples of EA conversions using this method. Initially I was not talking about your EA, but about Kim's functions.

 
fxsaber:

There are plenty of examples of EA conversions using this method. Originally, this was not about your EA, but about Kim's functions.

I understand, thank you. I will keep in mind that such a library exists, but I still need to learn MQL5. I have seen very few examples of ready-made MQL5 functions that could be remade in MQL5.
 
Kolya32:
I got it, thank you. I will keep in mind that such a library exists, but I still need to learn MQL5. There are few examples of ready-made MQL5 functions that could be remade in MQL5.
You need to write for yourself. The approach: one function for all occasions is wrong.
What function do you want to make in MQL5?
 
Vladimir Karputov:
You need to write for yourself. The approach: one function for all occasions is wrong.
What function do you want to make in MQL5?

A universal one, which could cut quid while the computer is off. And preferably in large denominations. You can write it in eurynotes. ))))

 
Vladimir Karputov:
You have to write it for yourself. The approach: one function for all occasions is wrong.
What function would you like to make in MQL5?

I really need a MQL5 FUNCTION TO CHECK IF A TODAY'S SALE WAS ENDED. If yes, then true, if no, then false (with Magic of course). I use this function on MT4.

bool isTradeToDay(string sy="", int op=-1) {
  int i, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (Magic<0 || OrderMagicNumber()==Magic) {
              if (TimeDay  (OrderOpenTime())==Day()
              &&  TimeMonth(OrderOpenTime())==Month()
              &&  TimeYear (OrderOpenTime())==Year()) return(True);
            }
          }
        }
      }
    }
  }
  k=OrdersTotal();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (Magic<0 || OrderMagicNumber()==Magic) {
              if (TimeDay  (OrderOpenTime())==Day()
              &&  TimeMonth(OrderOpenTime())==Month()
              &&  TimeYear (OrderOpenTime())==Year()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
}
 
Kolya32:

I really need a FUNCTION in MQL5 that would check if a trade was made today. If yes, then true, if no, then false (with Magic set, of course). I use this function on MT4.

Please try to insert the code correctly first. I don't want to look at your sheet of plain text.
 
Vladimir Karputov:
Please try to insert the code correctly first. No desire to look at your sheet of plain text.
Corrected)
 
Kolya32:

I really need a FUNCTION in MQL5 that would check if a trade was made today. If yes, then true, if no, then false (with Magic set, of course). I use this function in MT4.

It is in MQL5

bool  HistorySelect(
   datetime  from_date,     // с даты
   datetime  to_date        // по дату
   );

Returned value

Returns true if successful, otherwise false.

Документация по MQL5: Торговые функции / HistorySelect
Документация по MQL5: Торговые функции / HistorySelect
  • www.mql5.com
Функция HistorySelect() создает в mql5-программе список ордеров и список сделок для дальнейшего обращения к элементам списка посредством соответствующих функций. Размер списка сделок можно узнать с помощью функции HistoryDealsTotal(), размер списка ордеров в истории можно получить с HistoryOrdersTotal(). Перебор элементов списка ордеров лучше...
Reason: