Set order expiration date?
Um no. At order creation (OrderSend()) just get the TimeLocal() or timecurrent, whichever you prefer. Set orderExpiration to that time + 30*60 (minutes).
If your broker doesn't allow this, just have an array of currently open orders handy, where you put these times in and check on every tick.
You should know that if such EA goes through inti/deinit cycle, you'll lose that info unless you save it to disk promptly and read it at init cycle.
I think this can also be done through GlobalVariables, tbh I don't use them.
Um no. At order creation (OrderSend()) just get the TimeLocal() or timecurrent, whichever you prefer. Set orderExpiration to that time + 30*60 (minutes).
If your broker doesn't allow this, just have an array of currently open orders handy, where you put these times in and check on every tick.
You should know that if such EA goes through inti/deinit cycle, you'll lose that info unless you save it to disk promptly and read it at init cycle.
I think this can also be done through GlobalVariables, tbh I don't use them.
- You MUST use TimeCurrent() as that is ONLY what the broker uses, your local time is irrelevant.
- If your broker doesn't allow expiration time just use:
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderType() > OP_SELL // pending only && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair && TimeCurrent() = OrderOpenTime() > 30*60 // and too old. ){ if (!OrderDelete(OrderTicket()) Alert(..., GetLastError()); }
No need for persistent storage, i.e. disk, no need for arrays. - You can NOT use GlobalVarables for persistent storage. In the event of a power failure/OS or terminal crash, GVs will NOT be written to disk.
Also not sure what the format should be. Like this: D'1980.07.19 12:30:27' ??
WHRoeder
You can NOT use GlobalVarables for persistent storage. In the event of a power failure/OS or terminal crash, GVs will NOT be written to disk.
This is not true. GlobalVariables will survive power failure and crash just fine. GlobalVariableSet() will write to disk immediately. You are confusing this with objects drawn on the chart that will only be saved on clean exit. GlobalVariables will be saved immediately.
1) It doesn't matter what you use, you set your orders at your local time, and the time that you set for expiration is (in this case) irrelevant. So here, the usage of either TimeLocal or TimeCurrent is acceptable. The broker will set your order expiration to what you tell him to set it to.
2) I have the knack for not seeing the simplest solution. :)
3) Hm. If that's the case, I really see no point in using global vars currently.... For what purpose do you guys use them mostly?
Thanks for all the advice guys.
I think I will use WHRoeder's piece of code since it will be accepted by all brokers.
(The discussion around Global Variables are fascinating! I must start to look further into this)
Your assistance in this matter is GREATLY appreciated!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I work with pending orders in my EA.
I want to delete any pending order that has not been activated after 30 minutes.
Can somebody please tell me how I can do this?