Pause after a trade

 

I am currently implementing an EA that pauses after it has closed a position, and the code is down below:

if (OrdersTotal() == 0 && TimeCurrent() >= OrderCloseTime() + 1200 ) {

            if (iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0) <= 30 )

                ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Ask - 100 * Point, Ask + 100 * Point, NULL);

            else if (iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0) >= 70) 

                ticket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Ask - 100 * Point, Ask + 100 * Point, NULL);            

            OrderSelect(ticket, SELECT_BY_TICKET);

} 

However, I don't know why but OrderCloseTime() always returns 0 even after provided ticket's position has closed.

Why is that? 

 
griffcho16:

However, I don't know why but OrderCloseTime() always returns 0 even after provided ticket's position has closed.

Why is that? 

Read the documentation for OrderCloseTime() you must select the order first.

Please use the code button (Alt + S) when posting code.

 
Try Sleep()
 
griffcho16:

I am currently implement an EA that pauses after it has closed a position, and the code is down below:

However, I don't know why but OrderCloseTime() always returns 0 even after provided ticket's position has closed.

Why is that? 

TimeCurrent() + 1200 >= OrderCloseTime()
focus on your code above... you need to thinking more about it... fix your code...
remember every tick your code TimeCurrent() above always counting...and always adding  1200 seconds...
thats why your code always return (0).
 
Mister Bond:
focus on your code above... you need to thinking more about it... fix your code...
remember every tick your code TimeCurrent() above always counting...and always adding  1200 seconds...
thats why your code always return (0).

You are wrong.

TimeCurrent() + 1200

will always be > than any closed order so that needs to be corrected.

As I already mentioned the order must be selected first.

 

Keith Watford:

Read the documentation for OrderCloseTime() you must select the order first.

Please use the code button (Alt + S) when posting code.


I do want to select the order first, but if I move the OrderSelect above Ordersend then I don't have any ticket to see the specific order.

Can you maybe give me an example?

Thank you

 
Keith Watford:

You are wrong.

will always be > than any closed order so that needs to be corrected.

As I already mentioned the order must be selected first.


Also you are right, it should be TimeCurrent) >= OrderCloseTime() + 1200 since I want to wait 20min every time I close my position.

 
griffcho16:

I do want to select the order first, but if I move the OrderSelect above Ordersend then I don't have any ticket to see the specific order.

Can you maybe give me an example?

Thank you

If your ticket is declared global, and it takes on a value after OrderSend(), you can use it when you call OrderSelect() in the next ticks. So this should work fine:

if (OrdersTotal() == 0 &&
    (ticket==0 ||
     (OrderSelect(ticket, SELECT_BY_TICKET) && TimeCurrent() >= OrderCloseTime() + 1200 ))) {

            if (iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0) <= 30 )

                ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Ask - 100 * Point, Ask + 100 * Point, NULL);

            else if (iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0) >= 70) 

                ticket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Ask - 100 * Point, Ask + 100 * Point, NULL);            


} 

Instead of using a global variable ticket, consider using Tools->Global Variables instead (i.e. the GlobalVariableSet() suite of functions), so that ticket won't be set to zero when your system restarts within 1200 seconds of the previous close.

Reason: