How to delete a pending order after x seconds... precisely
-
Hello.
I need to close pending orders after x seconds, suppose 10 seconds, but I need to be exactly 10 seconds, not 9, not 11, not anything else...
I wrote these blocksIf a pending order exist, it checks if variable buy_pending_seconds is equal to the given value, if so it sets the variable to 0 and close pending order, else it increments variable buy_pending_seconds by one, and starts again at the next second.
It seemed to work but today I checked it in a very volatile enviroment (EURGBP) and it looked like it is not precise at all.
I put a comment to see if the variable was really incremented once per second, and it wasn't so, it was incremented quite randomly.
I also discovered that there was a lot of pending orders that were not deleted at all... as the counter of the time was stucked.
Can you please suggest any affordable method to do such a thing?
Thanks
-
I would try this: For each Pending Order -> check age -> close
But remember that if you work under "on Tick", then you will not always get a tick coming exactly 10 seconds after the order. They come when they want, they don't care about time. So if you want precise time, you need to work under "on Timer". It's period can be set from the project settings (the bench icon). But note that "on Timer" does not work in the Tester, because the Tester works with it's generated ticks