Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1482

 
Alexey Viktorov #:
In this case, when you start the EA, it does not see open positions yet and the variable is equal to zero ...

I would agree with you, but here is the problem - when I put the pos_total variable on the global level, the EA did not see open positions during the whole testing period, although more than 50 positions were opened during this period. I don't understand! It turns out that this option does not work?

Regards, Vladimir.

 
Alexey Viktorov #:

In your case it is easier to write without a loop

if you need the last position...

I agree, if I didn't have several positions open on a different symbol and in different directions. I mean buy and sell. But thanks for the hint anyway!

Regards, Vladimir.

 
MrBrooklin #:

I agree, if there weren't multiple positions open on a different symbol and in different directions. I mean buy and sell. But thanks for the tip anyway!

Regards, Vladimir.

It doesn't make any difference how many positions are open and whether they go north or north, or to the fuck or in all directions at once... The last one will be PositionsTotal()-1.

 
Alexey Viktorov #:

It doesn't make any difference how many positions are open and whether they are open northwards, northwards or all directions at once... The last one will be PositionsTotal()-1.

Hi, Alexei, I was a bit confused. You are right as always!!! )))

Regards, Vladimir.

 
Alexey Viktorov #:

Actually, yesterday I experimented with position sampling and came to the conclusion that PositionsTotal() is needed only to determine the number of positions. And this number is needed only to limit the loop.

Here is such a loop


works even if you get a list of orders or deals from the history before it. The other day I will check whether the selection of pending orders will interfere.

There is also a subtlety here.

If the list is really large and ordered by some criterion, it may be more profitable to search for the required element not by searching all elements in the loop, but by half division, and here the knowledge of the total number of elements in the list can be very useful.

 
JRandomTrader #:

There's a subtlety here, too.

If the list is really large and ordered by some criterion, it may be more profitable to search for the required element not by looping through all elements, but by half division, and here the knowledge of the total number of elements in the list may be very useful.

I did not say that the function is completely useless. But in some cases you can and must do without it. After all, every function is time. You can type a little bit at a time until you get brakes....

 
MrBrooklin #:

Hi, Alexei! I was dumb. You are right as always!!! )))

Regards, Vladimir.

I am right, but I did not specify that the function as you have written it will not work correctly if several trades are opened on different symbols.

Since you check only the last one, and it (the last one) can be opened on another symbol.

 
Aleksandr Slavskii #:

Right, but I didn't specify that the function as you have written it won't work properly if several trades are opened on different symbols.

Since you check only the last one, and it (the last one) can be opened on another symbol.

Hello Alexander, I have already thought about this topic, but I haven't started to ask the question here yet, because I haven't reached the place in the code where there will be different symbol positions. Thanks for the hint! )) Now I am stumped at one point, but I don't want to bring it here for public review, as there is a relentless desire to "finish" it by my own efforts.

By the way, I noticed that all my so-called "stumbles" lie in such little things that I can't see. Take the specifier that Artem Trishkin told me about. It's such a small thing, and here I've broken my head over why the script doesn't work. Or the same link &. So much time lost on it. In general, still to learn, learn and learn, and in Russian - to read, read and read Documentation.

Regards, Vladimir.

 
Good afternoon!


I have a netting account.

In my Expert Advisor I use the code to control the deals made:

HistorySelect(0,TimeCurrent());
ulong ticket = OrderGetTicket(0);
N_deals = HistoryDealsTotal();

But I also need to estimate the number of closed trades.
I think I need to use the DEAL_ENTRY_OUT modifier.
But how to use it, I can't understand.

Please help me.

Regards, Alexander


 
klycko DEAL_ENTRY_OUT modifier.
But how to use it, I can't understand.

Please help me.

Sincerely, Alexander


You are in the right direction. But not attentive enough


Reason: