MT4 should somehow support the recovery after shutdown especially since when it is company "policy" with unpredictable auto-updates and restarts which cannot be disabled.
MT4 should somehow support the recovery after shutdown especially since when it is company "policy" with unpredictable auto-updates and restarts which cannot be disabled.
Thanks.
Now I have this idea, please take a look. Still thinking about the recover part, this is just a beginning :
static datetime EUT,GUT,AUT; // store order(ONLY by this EA) open time for different currency pair bool EAEnabled = true; //-------------------------------------------------------------------- int start() { if (!EAEnabled) // check if this EA disabed { Comment("there is manual open order , can't run EA."); return(0); } datetime EUTL=0,GUTL=0,AUTL=0; // time of latest order (including manual and EA) for each currency pair for(int i=OrdersTotal()-1;i>=0;i--) // if this currency has any order, find out latest order of them. { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol()) continue; //----------------------------------------------------if ordersymbol = symbol, then: switch(Symbol()) { case 'EURUSD': EUTL= MathMax(OrderOpenTime(),EUTL); // here may have data type error - "datetime" vs "mathmax double" ? how to fix? break; case 'GBPUSD': ...... default: } } // ------------------------ check if latest order is made by this EA switch(Symbol()) { case 'EURUSD': if( EUT == EUTL ) break; // made by EA, continue to send EA orders. else{ // not made by EA, will disable EA. EAEnabled = false; Comment("Still has manual open order, can NOT run EA."); return(0); } case 'GBPUSD': ...... default: Print("weird currency pair"); return(0); } ...... //-----------------------------------finally, orders !!! int ticket=OrderSend(......); if(OrderSelect(ticket,SELECT_BY_TICKET)==true { switch(Symbol()) // store EA order 's time { case 'EURUSD': EUT = OrderOpenTime(); break; case 'GBPUSD': ...... default: Print("weird currency pair"); return(0); } } ......
But I'm wondering : what's the difference between disconnect and mt4 restart? Does disconnect also do things written in "deinit()", as well as restarting ?
You should use the Magic Number to track which orders your EA created. https://www.mql5.com/en/forum/106755
The MagicNumber is your own reference number that stays with the order.
Thank you very much for the tip, ydrol.
That's much better than my code above, LOL.
I'll move on to the recovery part.
No. So it's impossible to tell?
joshatt2013.08.19 04:16
So, I'm thinking: what if MT4 re-connect? ----even if I try to keep it running, often there is net problem with MT4. I surely don't want this EA send from the first order again. And I don't want EA just disabled.
Is there any trick for this?
There is no reason to assume an EA would break when the connection to the broker is disconnected. It will just sit there waiting for a new tick to arrive just like it usually does. When the internet is reconnected and a new tick arrives the EA will continue its operation.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm planning an EA, which will send a series of orders if trend develops well. The latter orders depend on former orders. And orders's sizes are not the same. The very first order's size, especially, is quite different.
So, I'm thinking: what if MT4 re-connect? ----even if I try to keep it running, often there is net problem with MT4. I surely don't want this EA send from the first order again. And I don't want EA just disabled.
Is there any trick for this?