How can i exit a position with a time stop?

 
Hi guys,

I would like to place a time based stop to exit my position, how can i do?

Example :

If the position is open since more than 10 bars, then close the position.
How can i code that?
 
Either set the expiration paramater in the OrderSend() function or go through the Orders, check OrderOpenTime() agains CurTime() or Time[0] and call OrderClose() in your code if the time is more than what you intend.


Markus
 
Does this code, mean that this long position will be close after 2700 seconds?

ticket=OrderSend(Symbol(),OP_BUY,Lots,Open[0],3,Ask-TakeLoss*Point,Ask+TakeProfit*Point, "blabla",16384,CurTime()+2700,Green);

because it seems that it doesn't work :(
 
I just read the OrderSend() docs again. It's an expiration for orders that doesn't get filled. So it won't affect open orders. With that I guess your expert will have to loop through the open orders and check the difference between CurTime() and OrderOpen() time via program and OrderClose() them if their time is up.


Markus