Questions from Beginners MQL5 MT5 MetaTrader 5 - page 643

 
Alexey Viktorov:

Not last on the list, but the "youngest" in time.

Although I'm just as inconsiderate. The question is about modification, and I'm writing close... And if you simply modify it, there will be no holes in the list of orders... You just might need to add variables and assign them values, and MUST check parameters to avoid error #1. Well, Mila can do it herself.

Artyom Trishkin:

How can you be sure that there won't be a sorting dependency, and you won't miss the wrong order at all?

Once again, in order to reliably find the last order, it needs to be identified by its opening time, and not by its position on the list.

As far as I know, orders in the list are arranged just from the earliest (OrdersTotal()-1) to the latest (0). If this is not the case (the list is not sorted by time) and you have proof, please provide it.

If you are saying that at the moment when the history was requested using the function OrdersTotal(), another EA placed an order, then it would either be skipped (in any case, it would not have time to be in the orders history), or it would also be the last in the orders list.

Of course, we can strongly reinsure ourselves and compare the time of opening all orders from total-1 to 0, but it would hardly be an optimal solution when we have a large number of orders and traded symbols.

 
Alexey Kozitsyn:

As far as I know, the orders in the list are sorted just from the earliest (OrdersTotal()-1) to the latest (0). If this is not the case (the list is not sorted by time) and you have proof, please provide it.

If you are saying that at the moment when the history was requested using the function OrdersTotal(), another EA placed an order, then it would either be skipped (in any case, it would not have time to be in the orders history), or it would also be the last in the orders list.

Of course, we can strongly reinsure ourselves and compare the time of opening all orders from total-1 to 0, but it would hardly be an optimal solution when we have a large number of orders and traded symbols.

Jesus... Proofs to them...

I guess you don't really remember such situations being discussed on mql4.com for a long time. That is when we came to the conclusion that it would be better to search for an order by time to unambiguously determine its open/close time. I've already got tired of repeating that there was a dependency on sorting. Then we made it stop being dependent on sorting. People relaxed and began to do as you suggest. And then bam... and there was a dependence on sorting again. People howled - the robots went crazy. And then the sorting dependency disappeared again.

If you have a desire for supposed optimality to fall under the crush again someday, then do it the way you're doing it. But don't suggest such solutions to other people. Or, when offering, warn them of the possibility of ever losing money because of failures of searching for the necessary order, which (the search) depends on sorting symbols in the list, which, in turn, does not depend on you and your algorithm. On the contrary - your algorithm depends on someone else...

Don't tell them that the dealer can cheat with the time of opening/closing, that's another question.

Good luck.

 
Artyom Trishkin:

Jesus... Proofs they want...

Apparently, you don't quite remember such situations being discussed on mql4.com a long time ago. That's when you came to the conclusion that it's still better to search by time for an order to unambiguously determine its open/close time. I've already got tired of repeating that there was a dependency on sorting. Then we made it stop being dependent on sorting. People relaxed and began to do as you suggest. And then bam... and there was a dependence on sorting again. People howled - the robots went crazy. And then the sorting dependency disappeared again.

If you have a desire for supposed optimality to fall under the crush again someday, then do it the way you're doing it. But don't suggest such solutions to other people. Or, when offering, warn them of the possibility of ever losing money because of failures of searching for the necessary order, which (the search) depends on sorting symbols in the list, which, in turn, does not depend on you and your algorithm. On the contrary - your algorithm depends on someone else...

Don't tell me that the dealer can cheat with the opening/closing time - that's another issue.

Good luck.

Yeah, I don't remember discussions like that, I don't read the foursome forum often. Perhaps, once upon a time, there was something like that. But if you build on everything that was "once upon a time" no resources will suffice.

If you have a desire for the sake of supposed optimality to fall under the crosshairs again someday, then do as you do. But don't suggest such solutions to other people. Or, when offering, warn them of the possibility of ever losing money because of failures of searching for the necessary order, which (the search) depends on sorting symbols in the list, which in turn does not depend on you and your algorithm. On the contrary - your algorithm depends entirely on someone else...

As you say, it's possible to "get caught in the crosshairs" in a number of other ways. If you need to quickly determine the last order, it is not rational to search through them all in time.

Everyone should decide for himself whether to accept my method or not. The best solution is to open many orders and see how sorting works NOW.

Good luck to you too.

 
Artyom Trishkin:

Are you sure you have shown a reliable way of missing the last position in the list?

If you trade realistically, aren't you worried that sorting might suddenly become addictive?

Still, IMHO, we need two cycles here - in the first we look for the freshest position by opening time, in the second we modify all except the one whose ticket was found in the first cycle.

No, not sure, but logically correct.

Have read below about the insidiousness of MQs - anxiety has arisen. Thanks for the heads up.

 
Alexey Kozitsyn:

Whenever you need to quickly identify the last order, it is not rational to go through them all in time, and I have already said why.

Why should we have to go through them every time? This is exactly the irrationality.

We can search only once per tick for market positions and for closed orders and fill all fields of the structure with all necessary data of the last two orders - open and closed.

And use the data obtained during this tick. After changing them on this tick, you will get new data and new fields of the two structures on the next tick. It seems to me - this is a normal balance between reliability and speed. This is what optimality is all about. And what you call optimality, IMHO, is a hatchet job ;)

 
Artyom Trishkin:

Why go over it every time? This is exactly the point where it is not rational.

You can search once per tick for market positions and for closed orders, and fill all the fields of the structure with all the necessary data of the last two orders - open and closed.

And use the data from that tick. After changing them on this tick, you will get new data and new fields of two structures on the next tick. Seems to me - this is a normal balance between reliability and speed. This is what optimality is all about. And what you call optimality, IMHO, is a hatchet job ;)

You are going into details, no one mentioned anything about every time. I, like you, am in favour of rationality, we just have different views on it.

 
Alexey Kozitsyn:

You're getting into nuances, no one was talking about every time at all. I, like you, am in favour of rationality, it's just that you and I have a different view of it.

Your own words:

Wherever you need to quickly determine the last order, it is not rational to go through all of them in time, imho...

"Everywhere" is not synonymous with "every time" in this context?

That's why I said "go through it once per tick", fill in the fields of the structure with the right data and use it everywhere you need to get data about the last order, instead of going through it everywhere every time.

Maybe I understood you wrong? But your quoted expression, IMHO, excludes ambiguity of understanding.

 
Artyom Trishkin:

Your own words:

"Everywhere" is not synonymous with "every time" in this context?

That's why I answered - it's to go through once per tick, fill the fields of the structure with the right data and use them wherever you need to get data about the last order, rather than going through them every time.

Maybe I've misunderstood? But your quoted expression, IMHO, excludes ambiguity of understanding.

You don't consider that there may be pauses/simply long calculations in the program, after which the trade environment must be updated. Dragging an array of orders around is not always convenient, and a global array is not always a good solution.

Anyway, as I said, no one is discouraging you, but there are cases where your option will be less preferable (multi-currency/multi-order systems). And to be reassured that MQ will change the sorting order again (given that it is the same in mql4, and in mql5), I think, is not necessary.

 
Alexey Kozitsyn:

You are not taking into account that there may be pauses/just long calculations in the program after which you need to update the trading environment. Dragging an array of orders behind you is not always convenient, and a global array is not always a good solution.

Anyway, as I said, no one is discouraging you, but there are cases where your option will be less preferable (multi-currency/multi-order systems). And to be reinsured that MQ will change the sorting order again (given that it is so in mql4, and in mql5), I think there's no need.

A class that allows you to easily and effortlessly have data for any characters and any magicians was made a long time ago. And there's no need to carry anything, especially a whole array, but only TWO orders - the last open and the last closed. Every time, after long calculations or waiting, you have to re-fill structure fields, which, by the way, you also have to do, or you don't update environment?

OK. It's a no-brainer... Do it your way. Don't worry about reliability - forget it...

 
Artyom Trishkin:

A class has long been made that allows you to easily and effortlessly have data on any symbols and any magicians. And there is no need to drag anything, especially the whole array, but only TWO orders - last opened and last closed. Every time, after long calculations or waiting, you have to re-fill structure fields, which, by the way, you have to do, or you do not update environment?

OK. It's a no-brainer... Do it your way. Don't worry about reliability - forget it...

And I do update the environment, it's just that your method of searching will take much longer, that's all, and on the subject of reliability, that's debatable.
Reason: