myeatrade

MQL4 Reference

MQL4 Checkup

A group of functions that allow determining of the current status of the client terminal, including the environment status of the MQL4 program.

 

GetLastError()

int GetLastError()

The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized. So, the next call for GetLastError() will return 0.

Sample:

  int err;
  int handle=FileOpen("somefile.dat", FILE_READ|FILE_BIN);
  if(handle<1)
    {
     err=GetLastError();
     Print("error(",err,"): ",ErrorDescription(err));
     return(0);
    }

IsConnected()

bool IsConnected()

The function returns the status of the main connection between client terminal and server that performs data pumping. It returns TRUE if connection to the server was successfully established, otherwise, it returns FALSE.

Sample:

  if(!IsConnected())
    {
     Print("No connection!");
     return(0);
    }
  // Expert body that needs the connection opened
  // ...

IsDemo()

bool IsDemo()

Returns TRUE if the expert runs on a demo account, otherwise returns FALSE.

Sample:

  if(IsDemo()) Print("I work at a demo account");
  else Print("I work at a real account");

IsDllsAllowed()

bool IsDllsAllowed()

Returns TRUE if the function DLL call is allowed for the expert, otherwise returns FALSE.

See also IsLibrariesAllowed(), IsTradeAllowed().

Sample:

  #import "user32.dll"
     int     MessageBoxA(int hWnd, string szText, string szCaption,int nType);
  ...
  ...
  if(IsDllsAllowed()==false)
    {
     Print("DLL call is not allowed. Experts cannot run.");
     return(0);
    }
  // expert body that calls external DLL functions
  MessageBoxA(0,"an message","Message",MB_OK);

IsExpertEnabled()

bool IsExpertEnabled()

Returns TRUE if expert advisors are enabled for running, otherwise returns FALSE.

Sample:

  while(!IsStopped())
    {
     ...
     if(!IsExpertEnabled()) break;
    }

IsLibrariesAllowed()

bool IsLibrariesAllowed()

Returns TRUE if the expert can call library function, otherwise returns FALSE.

See also IsDllsAllowed(), IsTradeAllowed().

Sample:

  #import "somelibrary.ex4"
     int somefunc();
  ...
  ...
  if(IsLibrariesAllowed()==false)
    {
     Print("Library call is not allowed.");
     return(0);
    }
  // expert body that calls external DLL functions
  somefunc();

IsOptimization()

bool IsOptimization()

Returns TRUE if expert runs in the strategy tester optimization mode, otherwise returns FALSE.

Sample:

  if(IsOptimization()) return(0);

IsStopped()

bool IsStopped()

Returns TRUE if the program (an expert or a script) has been commanded to stop its operation, otherwise returns FALSE. The program can continue operation for 2.5 seconds more before the client terminal stops its performing forcedly.

Sample:

  while(expr!=false)
    {
     if(IsStopped()==true) return(0);
     // a long run-time cycle
     // ...
    }

IsTesting()

bool IsTesting()

Returns TRUE if expert runs in the testing mode, otherwise returns FALSE.

Sample:

  if(IsTesting()) Print("I am testing now");

IsTradeAllowed()

bool IsTradeAllowed()

Returns TRUE if the expert is allowed to trade and a thread for trading is not occupied, otherwise returns FALSE.

See also IsDllsAllowed(), IsLibrariesAllowed(), IsTradeContextBusy().

Sample:

  if(IsTradeAllowed()) Print("Trade allowed");

IsTradeContextBusy()

bool IsTradeContextBusy()

Returns TRUE if a thread for trading is occupied by another expert advisor, otherwise returns FALSE.

See also IsTradeAllowed().

Sample:

  if(IsTradeContextBusy()) Print("Trade context is busy. Please wait");

IsVisualMode()

bool IsVisualMode()

Returns TRUE if the expert is tested with checked "Visual Mode" button, otherwise returns FALSE.

Sample:

  if(IsVisualMode()) Comment("Visual mode turned on");

UninitializeReason()

int UninitializeReason()

Returns the code of the uninitialization reason for the experts, custom indicators, and scripts. The returned values can be ones of Uninitialize reason codes. This function can also be called in function init() to analyze the reasons for deinitialization of the previour launch.

Sample:

  // this is example
  int deinit()
    {
     switch(UninitializeReason())
       {
        case REASON_CHARTCLOSE:
        case REASON_REMOVE:      CleanUp(); break; // cleaning up and deallocation of all resources.
        case REASON_RECOMPILE:
        case REASON_CHARTCHANGE:
        case REASON_PARAMETERS:
        case REASON_ACCOUNT:     StoreData(); break;  // prepare to restart
       }
     //...
    }
This article url: http://www.myeatrade.com/434/

Please login to post comment, if you haven't account you can register free