How to check if an order is selected - page 10

 
artmedia70:
I don't see a problem. What's the big deal... You need to select an order in one main function A(), and in another function B(), called from the main function A(), to process the order selected in function A(). And we should know for sure in function B() whether or not the order is still selected... So pass to function B() the ticket of the order selected in function A(). In function B(), we can check from which list the order is selected and then decide where to go and what to return back to function A()...

You've got me all wrong. So do half of the people for some reason. I don't need in function B() to process that order, which is selected in function A(). Function B() works with other orders, no matter which ones, it has nothing to do with function A(); function B() has its own logic. It can count the number of orders, their total profit, look through their comments, TP SL, etc. The task is to return from function B() back to function A() such that no matter what function B() has done with the orders, the logic of function A() at the point of call of function B() from it would not be violated due to the fact that the order selected by function A() before function B() was called is not selected anymore and the selected order is another random order processed by function B() that most probably also searches orders in the loop.

artmedia70:
Now let's imagine what will happen to the last_select variable after restarting the terminal (the lights are turned off by nasty guys)

After restarting last_select variable will be initialized to 0, as required.

 

There's 10 pages of blah, blah, blah. Here is the code that provides for the function to work with another (not highlighted) order:

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Получаем актуальную информацию об ордере                                  |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
bool fGet_OrderDetails (int fi_Ticket)              // OrderTicket()
{
    int lia_cmd[] = {1,-1,-1,1,1,-1};
//----
    //---- На текущий момент может быть выделенным другой ордер
    int li_LastTicket = OrderTicket();
    if (li_LastTicket != fi_Ticket)
    {   
        if (!OrderSelect (fi_Ticket, SELECT_BY_TICKET))
        {fSet_Comment (fi_Ticket, fi_Ticket, 100, "fGet_OrderDetails()", True, GetLastError()); return (false);}
    }
    if (bi_curTicket != fi_Ticket)
    {
        bi_Type = OrderType();
        bd_OpenPrice = NDD (OrderOpenPrice());
        bd_Lots = OrderLots();
        bi_cmd = lia_cmd[bi_Type];
        bi_curTicket = fi_Ticket;
    }
    bd_curSL = NDD (OrderStopLoss());
    bd_curTP = NDD (OrderTakeProfit());
    //---- Выделяем первоначальный ордер
    if (li_LastTicket != fi_Ticket) {if (li_LastTicket > 0) OrderSelect (li_LastTicket, SELECT_BY_TICKET);}
//----
    return (true);
}
this is just an example. A person who understands the point will catch on.
 
TarasBY:

There's 10 pages of blah, blah, blah. Here is the code that provides for the function to work with another (not allocated) order:

this is just an example. A person who understands the point will catch on.

That's not the point. There are variables, local or global, in the EA and there are terminal variables. As far as the program is concerned, these variables are interactive, and their value can change in an absolutely inexplicable way for the EA at any moment. The order selection sign is just such a variable. If Metaquotes allowed access to the "select" attribute of a graphic object, it would be the same as well. This would inevitably lead to the following conclusion: we should select an order whenever we need to know the number of the selected order or remember the selected order if and only if it is required by the logic of the Expert Advisor. So it goes like this...
 
tara:
This is not the point. There are variables, local or global, in the EA and there are variables of the terminal. These variables are interactive from the program's point of view, and their value can change in an inexplicable way for the EA at any moment. The order selection sign is just such a variable. If Metaquotes allowed access to the "select" attribute of a graphic object, it would be the same as well. This would inevitably lead to the following conclusion: we should select an order whenever we need to know the number of the selected order or remember the selected order if and only if it is required by the logic of the Expert Advisor. So it goes like this...

I totally agree with you:

  • First of all, we have to take into account what we have (MQL4 capabilities);
  • Secondly, I myself use the structure of processing ALLtrade orders with open orders in one place: I make an enumeration of orders and make all necessary actions with each order (in order).

P.S. And I do the above check in the code "just in case"... :)

 

:)

Happy Holidays! For me - 20 years, not the worst in my life.

 
TarasBY:

There's 10 pages of blah, blah, blah. Here's the code that provides for the function to work with a different (not highlighted) order:

This is just an example. A person who understands the point will catch on.

Yup. right there:

int li_LastTicket = OrderTicket();

Your code will generate a 4105 execution error if there was no OrderSelect call before it was made. Just put a GetLastError check at the end of each tick and detect this error.

 
tara:

:)

Happy Holidays! For me - 20 years, not the worst in my life.

Congratulations! Have you served Faith and Truth for 20 years?
 
borilunad:
Congratulations! Have you served Faith and Truth for 20 years?
That's right.
 
tara:
Her, my dear.
So, over-enlisted, as they used to call me in my day, or maybe even now, a piece of...? :)
 
borilunad:
So over-enlisted, as they used to call me in my day, or maybe even now, a piece of...? :)
Would it make you feel better if I said so? :)