Download MetaTrader 5

Recognize when an order ticket is in history list (closed order) / HELP

To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
Simo Dodero
135
Simo Dodero 2016.11.21 15:34 

Hello, I'm newbie with mql4 but I have some experience programming in other languages...

 This is not my first EA or code... but I don't understand where I fail, so please I need help.

 In the array  ticketoperacioneslong  I memorize the ticket of the orders i placed.

I want to be advised , informed, when a ticket (that is inside the array) is in the history list, it has been closed, for TP or SL, doesn't care...

 I suppose that when i select with orderselect it should responde with true or false, i set in MOD_HISTORY and TICKET  so if the ticket is in the historical it should return TRUE

 I post the cicle I try to programming, please tell me where is the error  because like this it tell me that all trades are in the history but they are not, they are still opened or pending...

 

         for( int a=0;a<indexlong;a++) {   // va desde cero a max operaciones establecidas igual longitud array tickets
        
         int ticketl=ticketoperacioneslong[a]; //write in "ticketl" the ticket of the array - from 0 to max.lenght of array
         Print("ticket in position array ticket ",a," is ticket  ",ticketl); //print the ticket in the position "a" is "ticketl"
         if (OrderSelect(ticketl,SELECT_BY_TICKET,MODE_HISTORY)==true) //if the selected ticket is in  historical actualize the array true/false in "false"
         {
        
         operacioneslong[a]=false; // actualize the other array in position "a" with false  because it is in historical
         Print ("I set the array true/false in false - array n ",a, " of this ticket that is in historical= ", ticketl); // check to view result that i actualized the array
  
         }
        
                                      }

 The result is that all tickets inside the array result to be in historical !! but they are not !!

Where is the fail?

Thank You !! 

Drazen Penic
2538
Drazen Penic 2016.11.21 15:51  

There is no fail. It works as designed.

Read the note for the OrderSelect()  

It says:

 The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique order identifier.

To find out from what list the order has been selected, its close time must be analyzed. If the order close time equals to 0, the order is open or pending and taken from the terminal open orders list.

 

If you supply correct ticket, OrderSelect() will return true, ignoring the pool parameter.

As second quoted line states, you have to check OrderCloseTime().

OrderSelect - Trade Functions - MQL4 Reference
OrderSelect - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSelect - Trade Functions - MQL4 Reference
Simo Dodero
135
Simo Dodero 2016.11.21 23:07  

I read the note, ok, so I can eliminate MODE__TRADES?

 I don't understand why it doesn't change the variable if it is TRUE and the order is closed in the historical...

 I will read OrderCloseTime but I don't understand how it can help me...

Drazen Penic
2538
Drazen Penic 2016.11.22 09:54  

It works like this because MetaQuotes developers built it this way and we have to live with that. If you want to change something, try writing to the Service Desk.

If you select orders by ticket, then the pool can be omitted.

Read the documentation for the OrderCloseTime() 

It has only two lines of text, and one of them answers your question. If you can't understand it, please copy the text you don't understand here, and we'll go through it.



P.S. 

Why is it so hard for people here to even try to read existing documentation?

OrderCloseTime - Trade Functions - MQL4 Reference
OrderCloseTime - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderCloseTime - Trade Functions - MQL4 Reference
Marco vd Heijden
Moderator
4680
Marco vd Heijden 2016.11.22 10:05  

It's very simple!

if orderclosetime differs zero you are dealing with a closed order and if it is zero the order is still open.

if(OrderCloseTime()!=0)
{
  //Do something with closed order.
}
else
{
  //Order not closed yet.
}
Simo Dodero
135
Simo Dodero 2016.11.22 11:11  

Hello, thank you both...

Yes, yesterday I read OrderCloseTime, I think it's what I need...

 

Thank's for the example, Today I will try and comment !

Simo Dodero
135
Simo Dodero 2016.11.22 12:23  

Thank You really so much !!

I could finish my "EA"  !!!

Great !! 

Alain Verleyen
Moderator
30640
Alain Verleyen 2016.11.22 12:50  
Drazen Penic:
...

Why is it so hard for people here to even try to read existing documentation?

Can you read it for me please ? And provide me a summary...no more than 500 words.

I will be grateful forever.


To add comments, please log in or register