if (OrderSelect(0, SELECT_BY_POS,MODE_HISTORY)==False)
You select a random entry out of history (position zero.) Could be the oldest trade, could be a deleted pending order, could be a balance adjustment, could be something from another pair.
- You must find the last closed order for your pair and magic number. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
- Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
Thank you for your advice.
Tell me whats wrong now...
int LastTimeforClosed() { int i = OrdersTotal(); datetime lastTime = 0; for(i-1 ; i >= 0 ; i--) { if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==False) return(0); if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==True && OrderMagicNumber() == MAGICMA // my magic number && OrderSymbol() == Symbol() && OrderOpenTime() > lastTime ) { lastTime= OrderOpenTime(); } return(lastTime); } } condition for opening trade is TimeDay(LastTimeforClosed()) != TimeDay(TimeCurrent())
return should be after for-cycle. in your case it is inside that cycle so returns during first run.
corrected, still doesnt work.
int LastTimeforClosed() { int i = OrdersTotal()-1; datetime lastTime = 0; for(i ; i >= 0 ; i--) { if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==False) return(0); if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==True && OrderMagicNumber() == MAGICMA // my magic number && OrderSymbol() == Symbol() && OrderOpenTime() > lastTime ) { lastTime= OrderOpenTime(); } } return(lastTime); }
Brt88: Tell me whats wrong now...
| You select a random newest entry out of history (position zero.) Could be the oldest trade, could be a deleted pending order, could be a balance adjustment, could be something from another pair. |
Brt88: corrected, still doesnt work. | "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here. |
the condition lets open trade more than one per day, while I want to let EA trade once a day.
Brt88: the condition lets open trade more than one per day, while I want to let EA trade once a day.
| The posted code doesn't "lets open tread more than one per day" or prevent it. It returns the last open time. Period. Fix the indicated problems. The show the code that does the test, where you compare to tomorrow. |
I dont understand why should i compare to tomorow.
Also there is no balance adj and pending orders.
And i think that i dont need to check current orders if i check every opened trade, it doesnt matter if it is closed or not.
int LastTimeforClosed() { int i = OrdersHistoryTotal()-1; datetime lastTime = 0; for(i ; i >= 0 ; i--) { if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==False) return(0); if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==True && OrderMagicNumber() == MAGICMA && OrderSymbol() == Symbol() && OrderOpenTime() > lastTime ) { lastTime= OrderOpenTime(); } } return(lastTime); } void OnTick() { if (isnewbar()==True && TimeDay(LastTimeforClosed()) < TimeDay(TimeCurrent()) ) CheckForOpenD1() ; // function opens trades else Isar (); sltobep(); }
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
Plz tell me why doesnt it work.
I mean if there is opened trade in today, dont open any until next day.