You will need to use a counter and loop through all the orders and test OrderOpenTime(). You may also choose to filter by OrderSymbol() and/or OrderMagicNumber().
There are plenty of code snippets about how to count orders so you should be able to add the OrderOpenTime() test in fairly easily.
OrderOpenTime - Trade Functions - MQL4 Reference
- docs.mql4.com
OrderOpenTime - Trade Functions - MQL4 Reference
- Just remember the count.#define SECONDS uint
#define HR2400 86400
SECONDS time(datetime when=0){
return SECONDS(when == 0 ? TimeCurrent() : when) % HR2400; }
datetime date(datetime when=0){
return datetime( (when == 0 ? TimeCurrent() : when) - time(when) ); }
///////////////////////
static int nOrdersToday = 0; static datetime today = 0;
datetype t = today; today = date(); bool isNewDay = t != today;
if(isNewDay) nOrdersToday = 0;
if(nOrdersToday < 2){
int ticket = OrderSend( ... );
if(ticket < 0) Alert( ... );
else ++nOrdersToday;
}
// else max trades today - EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.If you want to be able to recover you will have to reset nOrdersToday in OnInit, by doing a OrderSelect loop through open orders like honest_knave said and through history in case the order has already closed. See external static variable - MQL4 forum
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hi
I want to only open 2 orders every day. But i don't know how to count only the current day's orders.
to be more clear, I should count today's opened orders before opening a new position. if they were 2 then stop opening a new order for today.
Please help me in this piece of code.
Thanks