How could I close my trade 12 hours later?

 

Hi!

I've got a good EA, but If It's open a position, and when this position will go wrong later, I'd like to close it 12 hours later.

How could I do this?

I know, I need a for cycle.

For example:

 for (i=0;i<OrdersTotal();i++)

OrderSelect(__Ticket(0),SELECT_BY_TICKET) 

if (__isExist(0) && OrderMagicNumber()==Ordermagicnumber() &&  OrderOpenTime() + 12 hours > CurrentTime())OrderClose(.................)

    //not essence, essential, ....................................................//

Could you give me the right code???

Thank you so much. 

 
for (i=0;i<OrdersTotal();i++)

If closing orders in a loop, count down. In this case, the loop does basically nothing as the variable i is not used.

 

OrderSelect(__Ticket(0),SELECT_BY_TICKET)

 When looping through orders, use SELECT_BY_POS

 

OrderMagicNumber()==Ordermagicnumber()

 Is Ordermagicnumber() a function?

 

OrderOpenTime() + 12 hours > CurrentTime()

 MQL4 will not recognise hours, use seconds in your calculations

 TimeCurrent() is the built in function. Do you have another function for  CurrentTime() ?

If the code was correct, you would be closing the trade if it is LESS than 12 hours old, not more than 12 hours 

Reason: