Questions from Beginners MQL5 MT5 MetaTrader 5 - page 100

 
ulong  HistoryDealGetTicket(
   int  index      // номер сделки
   );

What is a transaction number?

How do I select the last trade? Index 0?

I have an account with an open position and a history of trades. I want to select the last trade:

#include <Trade\DealInfo.mqh>  

CDealInfo deal;  

   for(int n=20;n>=0;n--)
     {
      deal.SelectByIndex(n);
      Print("Тикет сделки=",deal.Ticket()," n=",n);
     }


All ticks 0...
 
tor4en:
ulong  HistoryDealGetTicket(
   int  index      // номер сделки
   );

What is a transaction number?

See the description of the HistoryDealGetTicket() function. There is also an example of how to work with a list of deals.
 
Yedelkin:
See description of HistoryDealGetTicket() function. There is also an example of how to work with the list of deals.
It is not clear how to work with SelectByIndex() function from the standard library.
 
tor4en It is not clear how to handle the SelectByIndex() function from the standard library.
I tried to suggest an answer to your question "What is a transaction number?". Can we assume that you have dealt with this question?
 
Yedelkin:
I have tried to suggest an answer to your question "What is a transaction number? Can we assume that you have dealt with this question?
You may, thank you. Can you tell me if it is possible to select the last deal on a position without going through the deals and comparing times or their tickets?
 
tor4en: Do you know if it is possible to select the last deal of a position without going through the deals and comparing times or ticks?

1. Unfortunately, I try not to use the Standard Library, so I cannot correctly suggest how to work with the SelectByIndex() method. I can only note that the CDealInfo class itself is positioned as a class for working with transaction properties, i.e. the issues of getting the list of transactions seem to be left out.

2. As you know, the SelectByIndex() method simply uses the HistoryDealGetTicket() function. From the description of thisfunction it follows that before accessing to the deal it is necessary to obtain the list of all deals . In particular,

//--- запросим историр ю сделок в указанном интервале
   HistorySelect(from_date,to_date);
//--- общее количество в списке сделок
   int deals=HistoryDealsTotal();
//--- теперь обработаем каждую сделку
   for(int i=0;i<deals;i++)
     {
      deal_ticket=HistoryDealGetTicket(i);
      ...
     }

About a year ago, I asked on the forum, whether it is possible to consider that the last deal in the list always has an index of HistoryDealsTotal()-1, but I didn't receive an answer (or did not notice, which is unlikely). Using the method of scientific proof, I have not found a refutation of this thesis. So, logically, each new deal, information about which is received in the base terminal, should simply increase the list of deals by one and, respectively, indexes in the list of deals would be assigned to each new deal in ascending order. How it is in reality - do not know.

3. I also suggest to read the articleOrders, Positions and Trades in MetaTrader 5 and (haven't read it myself) - How to use the Standard Library trade classes when writing an Expert Advisor.

That's all :)

 
HistoryDealsTotal()-1
This seems to be a good idea. If we are looking for deals by specific position, it's better to use HistorySelectByPosition(position_ID). Thank you.
Документация по MQL5: Торговые функции / HistorySelectByPosition
Документация по MQL5: Торговые функции / HistorySelectByPosition
  • www.mql5.com
Торговые функции / HistorySelectByPosition - Документация по MQL5
 
tor4en: If we're looking for deals on a specific position, it's better to use HistorySelectByPosition().
Exactly right :)
 
Hello!!!

Experts, help, please. I built two EAs for, so to speak, synergistic effect, the simpler ones seem to connect, but this one doesn't compile, although I've done everything correctly as with the previous one. Here is what it gives out

'Supervisor' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 360 18

'Perceptron' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 418 8

'basicTradingSystem' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 434 6

The function can only be declared in the global scope

I'm really confused where is the global scope

 
chipo: I have connected two EAs for some kind of synergy effect, the simpler ones seem to connect, but this one does not compile, although I have done everything correctly as with the previous one. This is what it gives out

'Supervisor' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 360 18

'Perceptron' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 418 8

'basicTradingSystem' - function can be declared only in the global scope 20_200_pips_MQL5_v1.mq5 434 6

The function can only be declared in the global scope

I'm really confused where is the global scope

Such messages appear, for example, when one function is declared inside another. See if there's anything like this in the code:

func_1()
   {
    void  func_2()...
   }
Reason: