ExpertRemove() removes expert only after end of OnTick (but shouldn't it immediately?!?)

 

int         num_cycles = 4;
int         index_cycles = 0;

double      close_price = 0.0;     // these are just some simple calculations to make it clear
double      sl_price = 0.0;        // that after fulfilling the condition for expert removal
double      tp_price = 0.0;        // the program still continues the OnTick content and only then it stops

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   DebugBreak();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//---

   if(index_cycles > (num_cycles - 1))
      ExpertRemove();

   close_price = iClose(_Symbol, _Period, 0);
   sl_price = close_price - 100 * _Point;
   tp_price = close_price + 100 * _Point;

   index_cycles++;

  }



//+------------------------------------------------------------------+

Hello everybody, I invite you to run this through the debugger. Maybe I am missing something but look at the code: there is not much left to miss. Maybe I missed it good...

 
Maybe try to read the documentation ?
 

Please refer to the documentation ... Documentation on MQL5: Common Functions / ExpertRemove

Note

The Expert Advisor is not stopped immediately as you call ExpertRemove(); just a flag to stop the EA operation is set. That is, any next event won't be processed, OnDeinit() will be called and the Expert Advisor will be unloaded and removed from the chart.

Documentation on MQL5: Common Functions / ExpertRemove
Documentation on MQL5: Common Functions / ExpertRemove
  • www.mql5.com
ExpertRemove - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Alain Verleyen #:
Maybe try to read the documentation ?
Fernando Carreiro #:

Please refer to the documentation ... Documentation on MQL5: Common Functions / ExpertRemove

Note

The Expert Advisor is not stopped immediately as you call ExpertRemove(); just a flag to stop the EA operation is set. That is, any next event won't be processed, OnDeinit() will be called and the Expert Advisor will be unloaded and removed from the chart.


Oh right, thanks (picard double facepalm)