Download MetaTrader 5
To add comments, please log in or register
Learn operation principles of Trading Signals for MetaTrader.
shooter81
19
shooter81 2014.07.22 19:36 

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. 

Keith Watford
Moderator
7899
Keith Watford 2014.07.22 20:02  
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 

/
To add comments, please log in or register