need help with simple if statment

 

I've searched the forum and book and couldn't find the answer.


I'm trying to write a code that will do the following:

if (ticket1 || ticket2 || ticket3 || ticket4) closed
{
   ticket5=ordersend(...)
   ...
}

how do i write it correct? which function to use?


Thanks!

 

maybe you want to have not more than 4 open orders. your question is unclear

if there is no predefined function, write your own function.

 
meikel:

maybe you want to have not more than 4 open orders. your question is unclear

if there is no predefined function, write your own function.


Thanks for the quick reply.

I need to check if a specific order is closed or not.

Is there a predefined function for that?

 

Sounds like you wish to maintain 4 orders open at once? Ie. you don't care about WHICH of the orders is closed - just that you've no longer got a full complement of 4 orders.

If I've understood your requirement correctly, then I'd approach it in this way:


0. Create an integer variable and set it to zero

1. Query OrdersTotal() for the total number of current orders in this account

2. Loop through the Order Pool, selecting each one in turn using OrderSelect()

3. Check whether you're interested in each order ( by checking Symbol(), OrderComment(), OrderMagicNumber() etc. as appropriate)

4. If the order is of interest, then add it to your order counter variable

5. Once your loop has completed, your order counter will contain the number of orders that are "yours" - if this number is less than 4, then call a function to open a new order


If I've assumed wrongly, then you can check the Order History Pool (rather than the Order Pool) for specific ticket numbers. Let me know if this is the case.


CB

 
msbusinessil:

Thanks for the quick reply.

I need to check if a specific order is closed or not.

Is there a predefined function for that?


as far as i know not

you should open orders with a unique magicnumber or comment, and check for this in your own function.

its possible, but you as all programmers have to write your own functions and go your own way.

mql4 provides enough to do this

 
cloudbreaker:

Sounds like you wish to maintain 4 orders open at once? Ie. you don't care about WHICH of the orders is closed - just that you've no longer got a full complement of 4 orders.

If I've understood your requirement correctly, then I'd approach it in this way:


0. Create an integer variable and set it to zero

1. Query OrdersTotal() for the total number of current orders in this account

2. Loop through the Order Pool, selecting each one in turn using OrderSelect()

3. Check whether you're interested in each order ( by checking Symbol(), OrderComment(), OrderMagicNumber() etc. as appropriate)

4. If the order is of interest, then add it to your order counter variable

5. Once your loop has completed, your order counter will contain the number of orders that are "yours" - if this number is less than 4, then call a function to open a new order


If I've assumed wrongly, then you can check the Order History Pool (rather than the Order Pool) for specific ticket numbers. Let me know if this is the case.


CB


Hi Cloudbreaker,

Sorry for the unclear question, let me try again.

I need that 4 orders will be open always.

If one of them closed, i need to know which one specific, and open a new order in the same direction(Long\Short).


Thanks again!

 
msbusinessil wrote >>

Thanks for the quick reply.

I need to check if a specific order is closed or not.

Is there a predefined function for that?

Hi

It depends on how the order was closed.

If your ea closed it, you should know if this was done succesfully and you can act accordingly, however, it if was closed by the stoploss or takeprofit levels, it is not so simple.

You can study this article https://www.mql5.com/en/articles/1399 to learn about events and how to track them.

Alternately, if you know the ticket number, you can look for it like this:

if (OrderSelect(ticket,SELECT_BY_TICKET) == true)
{
if (OrderCloseTime != 0)
{
// your order is closed and you can act on that here
}
}

whocares

 
meikel:

as far as i know not

you should open orders with a unique magicnumber or comment, and check for this in your own function.

its possible, but you as all programmers have to write your own functions and go your own way.

mql4 provides enough to do this


I see.. OK, i'll try to figure my own function.

Just thought that this function is something basic in mql4.

 

You'll need to look through the Order History Pool for your specific ticket numbers, see if any of them are present (ie. they are closed).

Check this post - should be of help to you.

You'll need to make some changes as the person I was responding to had slightly different requirements - but that will help you to learn.

https://forum.mql4.com/22737


CB

Reason: