How to auto restart MT4 after a crash?

 

I am currently trading with multiple tabs, as many as 12 tabs at a time, and I occasionally faced the issue of the MT4 crashing.


The nature of the crash is such that after I restart MT4, it will work again until the next crash occurs. The frequency of the crash is rather random. At times, the application could stay for many days without crashing.


Now, here's my question:


Does anybody here know how I can auto restart MT4 after the application crash?


Your advice is much appreciated.


Cheers.

 

Try sheduling it in task sheduler. I'm sure there are better ways but they are beyond my paygrade and I never did get a "proper" solution.

V

 

it can be done with an external program. just have to check if mt4 is still running (i you are able to do this trough the process list fine, else you maybe have to use a file and writing with a EA every minute something there)

if it's not running anymore kill the programm an start a new one using shell commands. for somebody coding a "higher" language this should not be a problem.

afaik it can't be done using mql!


//z

 
create a batch file and schedule it to run (once per minute?)
@echo off
set term="%ProgramFiles(x86)%\Interbank FX Trader 4\terminal.exe"
tasklist | findstr "terminal.exe" >nul
if ERRORLEVEL 1  start "terminal" %term%
 
MaXumFX:
I am currently trading with multiple tabs, as many as 12 tabs at a time, and I occasionally faced the issue of the MT4 crashing.

Usually a memory problem. Reduce the max bars in chart to 1000.

Also if your EA puts many objects on the chart, Try reusing old ones

//+------------------------------------------------------------------+
//| Level object creation function                                   |
//+------------------------------------------------------------------+
#define ARROW_NDASH       4                     //#define ARROW_CIRCLEDOT   164
void MakeMarker( string name,   int ticket,     int barNum,
                 double price,  color obColor,  int arrow=ARROW_NDASH ){
    if (!Show.Objects) return;
    #define MAXOBJ 100                  // Prevent Tester memory handler: tester
    string                              // stopped because not enough memory
    objName = StringConcatenate(name, "#",  ticket%MAXOBJ, "-", barNum);        // Limit total
    if (!ObjectMove( objName, 0,        TimeCurrent(), price +Bid.chart)){      // Reuse
        if (!ObjectCreate( objName, OBJ_ARROW, WINDOW_MAIN,
                                    TimeCurrent(), price +Bid.chart)){  Alert(
            "ObjectCreate(", objName, "Arrow) failed: ",    GetLastError());
            return;
        }
        if (!ObjectSet( objName, OBJPROP_ARROWCODE, arrow ))            Alert(
            "ObjectSet(", objName, "Arrow) [2] failed: ",       GetLastError());
        if (!ObjectSet( objName, OBJPROP_COLOR, obColor ))              Alert(
            "ObjectSet(", objName, "Color) [3] failed: ",       GetLastError());
    }
                                                    #define STD_TEXT_SIZE EMPTY
    if (!ObjectSetText( objName, DoubleToStr(price, Digits), STD_TEXT_SIZE
        ))  Alert("ObjectSetText(", objName, ") failed:",       GetLastError());
    return;
}   // MakeMarker
// int barnum = iBarShift(NULL,0, OrderOpenTime());
 

Thank you folks for your kind replies. They were very insightful indeed, and I have learnt a great deal from the masters here.

In any case, the random crash issue has already been resolved, hopefully. Well, at least I have not been experiencing any crash lately since implementation of the solution.

Through some inductive inference, I discovered that the reason for the crash was in fact due to the implementation of a number of While loops which probably consume lots of resources.

I have since removed these loops and replace them by the If loops. While the latter does not hold guarantee to the execution of an action, it is certainly more memory friendly, and this is especially important if we are trading with multiple tabs.

Cheers,

Max

Reason: