for(int i=OrdersHistoryTotal();i>=0;i--) { OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if ( (OrderSymbol()== Symbol() ) && (OrderCloseTime() <= (TimeCurrent() - 900) ) ) { timeSpace == true; } else if (OrdersHistoryTotal() == 0) //in case there are no closed orders yet { timeSpace == true; } }
- The FOR is wrong. If there is one order history it's position is zero, but you try select position 1 which is wrong.
- Test your return codes What are Function return values ? How do I use them ? - MQL4 forum
- If there is no history orders The IF History == 0 should never execute because the loop should do nothing.
- You set timeSpace to true if there are ANY old orders, no ALL old orders.
- Use self documenting variable names. timeSpace is meaningless.
bool isOKtoOpen = true; // Assume all old orders or none. for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if(OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY) && OrderSymbol()== Symbol() // What about magic number? && OrderType() <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360 // https://forum.mql4.com/30708 // Never select canceled orders. ){ int secondsSinceClose = TimeCurrent() - OrderCloseTime(); if (secondsSinceClose <= 900){ isOKtoOpen = false; break; } } }
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
I am still a beginner in MQL4 and I want to only send one order every 15 minutes. To do this I was thinking of comparing the last closed order time with the current server time.
Here is my present code, which sadly does not fullfill my plan: