//+------------------------------------------------------------------+
//|                                                       Errors.mq4 |
//|                                                         SnowBars |
//|                           https://www.mql5.com/ru/users/snowbars |
//+------------------------------------------------------------------+
#property copyright "SnowBars"
#property link      "https://www.mql5.com/ru/users/snowbars"
#property version   "1.00"
#property strict
#property indicator_chart_window
enum BASE_CORNER {Top,Bottom};
input BASE_CORNER CORNER=Bottom; // The position indicator
//---
string StringError,MQL_name;
int G,E;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   MQL_name=MQLInfoString(MQL_PROGRAM_NAME);
   StringError="Everything works, no errors!";
   DrawButton("OK",StringError,0,19,(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0),20,clrBlack,clrWhite,clrWhite,8);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectsDeleteAll(0,MQL_name);
  }
//--------------------------------------------------------------------

void OnChartEvent(const int id,const long &x,const double &y,const string &sparam)
  {
   if(id==9){DrawButton("OK",StringError,0,19,(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0),20,clrBlack,clrWhite,clrWhite,8);}
   if(id==CHARTEVENT_OBJECT_CLICK && sparam==MQL_name+"OK")
     {
      E=0;
      StringError="Everything works, no errors!";
      DrawButton("OK",StringError,0,19,(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0),20,clrBlack,clrWhite,clrWhite,8);
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   GLError(GetLastError());
   if(E!=0){DrawButton("OK",StringError+" - click to mark as read",0,19,(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0),20,clrBlack,clrRed,clrRed,8);}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//--------------------------------------------------------------------
void DrawButton(string name="Button",string text="Text",int x=0,int y=0,int width=20,int height=10,color BGCOLOR=clrGreen,color clrBORDER=clrWhite,color clrTXT=clrWhite,int TxtSize=8,int sub_window=0)
  {
   name=MQL_name+name;
   if(ObjectFind(0,name)<0)
     {
      ObjectCreate(0,name,OBJ_BUTTON,sub_window,0,0);
      ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
      ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,clrBORDER);
      ObjectSetInteger(0,name,OBJPROP_BGCOLOR,BGCOLOR);
      ObjectSetInteger(0,name,OBJPROP_FONTSIZE,TxtSize);
      ObjectSetInteger(0,name,OBJPROP_COLOR,clrTXT);
      ObjectSetString(0,name,OBJPROP_TEXT,text);
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
      if(CORNER==1){ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_LOWER);}
      if(CORNER==0){ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);}
      ObjectSetInteger(0,name,OBJPROP_BACK,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
     }
   else
     {
      ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
      if(CORNER==1)
        {
         ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_LOWER);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
        }
      if(CORNER==0)
        {
         ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,-1);
        }
      ObjectSetInteger(0,name,OBJPROP_COLOR,clrTXT);
      ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,clrBORDER);
      ObjectSetInteger(0,name,OBJPROP_BGCOLOR,BGCOLOR);
      ObjectSetString(0,name,OBJPROP_TEXT,text);
     }
  }
//-------------------------------------------------------------------   
void GLError(int GLE)
  {
   if(GLE!=G)
     {E=GLE;
      G=GLE;
      switch(GLE)
        {
         case 1:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No error returned, but the result is unknown";break;}
         case 2:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Common error";break;}
         case 3:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid trade parameters";break;}
         case 4:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Trade server is busy"; break;}
         case 5:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Old version of the client terminal";break;}
         case 6:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No connection with trade server"; break;}
         case 7:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not enough rights"; break;}
         case 8:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too frequent requests";break;}
         case 9:  { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Malfunctional trade operation";break;}
         case 64: { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Account disabled";break;}
         case 65: { StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid account";break;}
         case 128:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Trade timeout";break;}
         case 129:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid price";break;}
         case 130:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid stops";break;}
         case 131:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid trade volume";break;}
         case 132:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Market is closed";break;}
         case 133:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Trade is disabled";break;}
         case 134:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not enough money";break;}
         case 135:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Price changed";break;}
         case 136:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Off quotes";break;}
         case 137:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Broker is busy";break;}
         case 138:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Requote";break;}
         case 139:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Order is locked";break;}
         case 140:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Buy orders only allowed";break;}
         case 141:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too many requests";break;}
         case 145:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Modification denied because order is too close to market";break;}
         case 146:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Trade context is busy";break;}
         case 147:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Expirations are denied by broker";break;}
         case 148:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", The amount of open and pending orders has reached the limit set by the broker";break;}
         case 149:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", An attempt to open an order opposite to the existing one when hedging is disabled";break;}
         case 150:{ StringError="Îøèáêà #"+DoubleToString(GLE,0)+", An attempt to close an order contravening the FIFO rule";break;}
         case 4001:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong function pointer";break;}
         case 4002:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Array index is out of range";break;}
         case 4003:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No memory for function call stack";break;}
         case 4004:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Recursive stack overflow";break;}
         case 4005:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not enough stack for parameter";break;}
         case 4006:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No memory for parameter string";break;}
         case 4007:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No memory for temp string";break;}
         case 4008:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not initialized string";break;}
         case 4009:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not initialized string in array";break;}
         case 4010:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No memory for array string";break;}
         case 4011:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too long string";break;}
         case 4012:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Remainder from zero divide";break;}
         case 4013:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Zero divide";break;}
         case 4014:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Unknown command";break;}
         case 4015:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong jump (never generated error)";break;}
         case 4016:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not initialized array";break;}
         case 4017:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", DLL calls are not allowed";break;}
         case 4018:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot load library";break;}
         case 4019:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot call function";break;}
         case 4020:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Expert function calls are not allowed";break;}
         case 4021:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not enough memory for temp string returned from function";break;}
         case 4022:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", System is busy (never generated error)";break;}
         case 4023:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", DLL-function call critical error";break;}
         case 4024:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Internal error";break;}
         case 4025:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Out of memory";break;}
         case 4026:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid pointer";break;}
         case 4027:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too many formatters in the format function";break;}
         case 4028:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Parameters count exceeds formatters count";break;}
         case 4029:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid array";break;}
         case 4030:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No reply from chart";break;}
         case 4050:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid function parameters count";break;}
         case 4051:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid function parameter value";break;}
         case 4052:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", String function internal error";break;}
         case 4053:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Some array error";break;}
         case 4054:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Incorrect series array using";break;}
         case 4055:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Custom indicator error";break;}
         case 4056:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Arrays are incompatible";break;}
         case 4057:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Global variables processing error";break;}
         case 4058:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Global variable not found";break;}
         case 4059:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Function is not allowed in testing mode";break;}
         case 4060:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Function is not allowed for call";break;}
         case 4061:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Send mail error";break;}
         case 4062:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", String parameter expected";break;}
         case 4063:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Integer parameter expected";break;}
         case 4064:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Double parameter expected";break;}
         case 4065:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Array as parameter expected";break;}
         case 4066:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Requested history data is in updating state";break;}
         case 4067:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Internal trade error";break;}
         case 4068:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Resource not found";break;}
         case 4069:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Resource not supported";break;}
         case 4070:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Duplicate resource";break;}
         case 4071:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Custom indicator cannot initialize";break;}
         case 4072:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot load custom indicator";break;}
         case 4073:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No history data";break;}
         case 4074:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No memory for history data";break;}
         case 4075:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Not enough memory for indicator calculation";break;}
         case 4099:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", End of file";break;}
         case 4100:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Some file error";break;}
         case 4101:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong file name";break;}
         case 4102:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too many opened files";break;}
         case 4103:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot open file";break;}
         case 4104:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Incompatible access to a file";break;}
         case 4105:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No order selected";break;}
         case 4106:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Unknown symbol";break;}
         case 4107:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid price";break;}
         case 4108:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid ticket";break;}
         case 4109:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Trade is not allowed. Enable checkbox (Allow live trading) in the Expert Advisor properties";break;}
         case 4110:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Longs are not allowed. Check the Expert Advisor properties";break;}
         case 4111:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Shorts are not allowed. Check the Expert Advisor properties";break; }
         case 4112:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Automated trading by Expert Advisors/Scripts disabled by trade server";break;}
         case 4200:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Object already exists";break;}
         case 4201:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Unknown object property";break;}
         case 4202:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Object does not exist";break;}
         case 4203:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Unknown object type";break;}
         case 4204:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No object name";break;}
         case 4205:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Object coordinates error";break;}
         case 4206:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", No specified subwindow";break;}
         case 4207:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Graphical object error";break;}
         case 4210:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Unknown chart property";break;}
         case 4211:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Chart not found";break;}
         case 4212:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Chart subwindow not found";break;}
         case 4213:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Chart indicator not found";break;}
         case 4220:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Symbol select error";break;}
         case 4250:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Notification error";break;}
         case 4251:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Notification parameter error";break;}
         case 4252:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Notifications disabled";break;}
         case 4253:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Notification send too frequent";break;}
         case 4260:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", FTP server is not specified";break;}
         case 4261:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", FTP login is not specified";break;}
         case 4262:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", FTP connection failed";break;}
         case 4263:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", FTP connection closed";break;}
         case 4264:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", FTP path not found on server";break;}
         case 4265:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File not found in the MQL4"+CharToStr(92)+"Files directory to send on FTP server";break;}
         case 4266:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Common error during FTP data transmission";break;}
         case 5001:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too many opened files";break;}
         case 5002:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong file name";break;}
         case 5003:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Too long file name";break;}
         case 5004:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot open file";break;}
         case 5005:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Text file buffer allocation error";break;}
         case 5006:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot delete file";break;}
         case 5007:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid file handle (file closed or was not opened)";break;}
         case 5008:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong file handle (handle index is out of handle table)";break;}
         case 5009:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_WRITE flag";break;}
         case 5010:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_READ flag";break;}
         case 5011:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_BIN flag";break;}
         case 5012:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_TXT flag";break;}
         case 5013:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_TXT or FILE_CSV flag";break;}
         case 5014:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File must be opened with FILE_CSV flag";break;}
         case 5015:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File read error";break;}
         case 5016:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File write error";break;}
         case 5017:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", String size must be specified for binary file";break;}
         case 5018:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Incompatible file (for string arrays-TXT, for others-BIN)";break;}
         case 5019:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File is directory not file";break;}
         case 5020:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File does not exist";break;}
         case 5021:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", File cannot be rewritten";break;}
         case 5022:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Wrong directory name";break;}
         case 5023:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Directory does not exist";break;}
         case 5024:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Specified file is not directory";break;}
         case 5025:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot delete directory";break;}
         case 5026:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Cannot clean directory";break;}
         case 5027:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Array resize error";break;}
         case 5028:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", String resize error";break;}
         case 5029:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Structure contains strings or dynamic arrays";break;}
         case 5200:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Invalid URL";break;}
         case 5201:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Failed to connect to specified URL";break;}
         case 5202:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", Timeout exceeded";break;}
         case 5203:{StringError="Îøèáêà #"+DoubleToString(GLE,0)+", HTTP request failed";break;}
        }
      Print(StringError);
     }
  }
//+------------------------------------------------------------------+
