How to remove the EA once the trade is taken?

 

Hi everyone,


I would that once the EA took the trade, that the EA is removed from the graphic charts.

I tried to use ExpertRemove();

But MT4 has crushed each time I used the EA using the ExpertRemove() function.


Here is the code I am using:

if (condition d'achat)
    {
    while ((buy == -1) && (count < 10)) // pour ré-essayer de prendre le trade au cas où le slippage est trop important, mais pas plus de 10 essais.
            {        
            RefreshRates();
            buy = OrderSend(Symbol(),OP_BUY,lot,MarketInfo(Symbol(), MODE_ASK), slippage, stop, profit, "Ordre Achat Execute", magicNumber, 0, clrGreen);
            count++;
            }       
               
     //on retire l'EA du graphique
     ExpertRemove();              
     }



Does anyone know why? or have a solution for me?


Thanks a lot for your time

Luciole

 
Luciole:

I tried to use ExpertRemove();

But MT4 has crushed each time I used the EA using the ExpertRemove() function.

try this;

if(condition) {
   int ticket = -1;
   ticket = OrderSend(...);
   if(ticket>-1) ExpertRemove();
}
 
Mohamad Zulhairi Baba:

try this;

I tried, but it is still crushing my MT4 platform..

Thanks anyway for your help (and Happy New Year).


I don't see how I can fix this problem at all..

:-(

Luciole

 
Luciole:

I tried, but it is still crushing my MT4 platform..

Thanks anyway for your help (and Happy New Year).


I don't see how I can fix this problem at all..

:-(

Luciole


Try run only ExpertRemove


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Print("ExpertRemove");
   ExpertRemove();    
  }
//+------------------------------------------------------------------+
 
Trinh Dat:


Try run only ExpertRemove



I should have thought of that, and surprisingly (or not) it does work...

I am going to try to fix it again. Thanks for your support

 

Ok it does work now.


My mistake was to consider that as soon as ExpertRemove is called the EA will be removed.

My program was stuck inside a loop and the EA could not called the DeOnInit function.


So, in my case, the solution was to get out of the loop just after calling ExpertRemove.


Thanks to you for your help!! :) :) :)

Luciole

 

Hi Luciole

I'm interested why you would want to "Remove" your EA.... Why don't you just simply tell it to "Stop" trading...?

 

I would only use ExpertRemove() as part of my security check.... ie. if(Demo == false) ExpertRemove();

 

Hello friend,

maybe like this...

   if(IsDemo()) DemoAccount="DEMO ACCOUNT";
   else ExpertRemove();

   Comment("\n Server Time : ",(string)Day()," ",(string)Month()," ",(string)Year()," ",TimeToString(TimeCurrent(),TIME_MINUTES),
           "\n","-----------------------------------",
           "\n ",AccountName(),
           "\n ",(string)DemoAccount," ",(string)AccountNumber(),
           "\n ",TerminalCompany(),
           "\n","-----------------------------------",
           "\n Balance          :  ",DoubleToString(AccountBalance(),2),
           "\n Equity           :  ",DoubleToString(AccountEquity(),2),
           "\n","-----------------------------------",
           "\n Total Memory MB    :   ",DoubleToString(TERMINAL_MEMORY_AVAILABLE+TERMINAL_MEMORY_USED,0),
           "\n Used Memory MB     :   ",DoubleToString(TERMINAL_MEMORY_USED,0),
           "\n Available Memory :  ",DoubleToString(TERMINAL_MEMORY_AVAILABLE,0),
           "\n","-----------------------------------",           
           "\n Total Orders     :  ",DoubleToString(OrdersTotal(),0));

   return(INIT_SUCCEEDED);
 
MikeT:

Hi Luciole

I'm interested why you would want to "Remove" your EA.... Why don't you just simply tell it to "Stop" trading...?


So the reason why I want to remove the EA is because in case my platform is closed (either by me or by windows updates.. it already happens)

then, if the EA is still on my platform, it will open another trade if the conditions are valid.

and I do not want that.


I do not know an other way to tell him to stop trading, do you?

Best,

Luciole

Reason: