Was there a way to kill an Expert ?

 

As a safetymeasure I call this early in the Start function:

//---------------- SaveAccount ------------------------
bool  SaveAccount() {
   if( AccountBalance() < BalanceCutOff ) {
   Alert("In order to protect the account ", WindowExpertName()," has stopped trading.", " Balance: ",AccountBalance(), "   Limit: ", BalanceCutOff);
   string body = TimeToStr(TimeHour(TimeCurrent())) + WindowExpertName() + "werwere" + "234555";
   SendMail(" has stopped trading.", body);
   return (TRUE); }   
return (FALSE);
}
//-----------------------------------------------------


But I would get flooded with mails, one every tick... there are ways around this but I'd like to have the expert remove itself from the chart

Is there a way to do it ?

 

There are at least two well known ways.


The first one is a flag on global scope (or a static one) that prevents the EA from working if the flag is set:

bool Stop;

int init()
{
    Stop = false;
    ...
    return (0);
}


int start()
{
    if (Stop) return (0);
    
    if (SomethingNastyHappened == true)
    {
        Stop = true;
        return (0);
    }

    ...

    return (0);
}


Another approach is to remove the EA from the chart by throwing corresponding message to the chart window. That involves WinApi utilisation.

 

Yeah..well  I don't find it worth the effort to start messing with dll and API calls.

This mod ( the OneShot) makes sure the messages are sent only once, and after that it immediatly returns from Start, and the EA keeps quiet.

EA is still on the chart, but atleast it doesn't do any harm.

//---------------- SaveAccount ------------------------
bool  SaveAccount() {
   if(OneShot) return(TRUE);//!!!!!!!!!!!!!!!!!!
   int Balance = AccountBalance();   
   if( Balance < BalanceCutOff ) {

   Alert("In order to protect the account ", WindowExpertName()," has stopped trading.", " Balance: ", Balance, "   Limit: ", BalanceCutOff);
   string body = TimeToStr(TimeHour(TimeCurrent())) + WindowExpertName() + "werwere" + "234555";
   Alert(body);
   SendMail(" has stopped trading.", body);
   OneShot = TRUE;//!!!!!!!!!!!!!!!!!!!!!!!!
   return (TRUE); }   
return (FALSE);
}
//-----------------------------------------------------
 
DayTrader:

Yeah..well  I don't find it worth the effort to start messing with dll and API calls.

This mod ( the OneShot) makes sure the messages are sent only once, and after that it immediatly returns from Start, and the EA keeps quiet.

EA is still on the chart, but atleast it doesn't do any harm.


That sounds a touch impolite and ungracious to Irtron who kindly offered the help you did ask for!


Personally what I do is to send any emails from other functions, if necessary passing a global into the Start() function. I allow the Start() function to print repeated error messages to the journal for occasions when I have suspended trading - just so there can be no mistake for the onlooker that this is the case.

Reason: