Shut down an Expert Advisor

 
Is there any instruction to completely stop an EA, ie remove it from the graph by a fatal error?.
 

Not sure if you can remove EA from graph. But you can stop it from trading though...

 

Here is an early EA I made so that I can analyse results in a spreadsheet. EA uses one tick to work and then releases the EA from the chart. It gets edited quite a lot.

//+------------------------------------------------------------------+
//|                                                      Barinfo.mq4 |
//|                                                                  |
//|                                                                   |
//+------------------------------------------------------------------+
#include <WinUser32.mqh> //add if using comitsuicide

#property copyright "Shareware"



//---- input parameters
extern string    ToFileName="Bar-info.csv";
extern bool MonthGap=false ;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   int handle ;
   double HiMinusLo=0 ;
   double count=0 ;
   Print("Test 1") ;
   handle=FileOpen(ToFileName,FILE_CSV|FILE_WRITE,",");
   int LineCount = 0 ; 
   if ( handle>0 )
     {
      FileWrite(handle, "Day","Date","Time","OPEN","CLOSE","HIGH","LOW","H-O","Volume",Bars);
      for(int i=0;i<Bars;i++)
       {
        FileWrite(handle, MyDay(Time[i]),Date2String(Time[i]),Date2Time(Time[i]),Open[i],Close[i],High[i], Low[i],High[i]-Low[i],Volume[i]);
        HiMinusLo=+HiMinusLo+High[i]-Low[i] ;
        count=count+1 ;
       }//for
     }//if
     FileWrite(handle,"Average = ",DoubleToStr(HiMinusLo/count,5) );
     FileClose(handle);
     Alert("FileWrite Done") ; 
     commitSuicide() ;  

//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
/////////////////////////    
void commitSuicide() //Don't forget to use #include <WinUser32.mqh> for this function
{
  int h = WindowHandle(Symbol(), Period());
  if (h != 0) PostMessageA(h, WM_COMMAND, 33050, 0);
}
///////////
string MyDay(datetime MyTime )
{
int TheDay = TimeDayOfWeek( MyTime ) ;
  switch (TheDay)
  {
   case 0 : return("Sun") ; 
   case 1 : return("Mon") ;
   case 2 : return("Tue") ;
   case 3 : return("Wed") ;
   case 4 : return("Thr") ;
   case 5 : return("Fri") ;
   case 6 : return("Sat") ; 
  }
}
///////////////
string Date2String( datetime MyTime)
{
int TheDay = TimeDay( MyTime ) ;
int TheMonth = TimeMonth( MyTime ) ;
int TheYear = TimeYear( MyTime ) ;

return( TheDay+"/"+TheMonth+"/"+TheYear ) ;
} 
///////////////
string Date2Time( datetime MyTime)
{
int TheHour = TimeHour( MyTime ) ;
int TheMinute = TimeMinute( MyTime ) ;
int TheSeconds = TimeSeconds( MyTime ) ;

return( TheHour+":"+TheMinute+":"+TheSeconds ) ;
} 
Reason: