OnDeinit Cancel ?

 

Hey all,

is it possible to cancel a OnDeinit request ? Like i have EA1 and EA2, EA2 has dependencies on EA1. For some reason EA1 is turning into a "OnDeinit" state, now i want to check if he is allowed to exit.

OnDeinit is a void function which will have no return check and this also means the deinit request is already in progress. Is there any way to bypass request ? Or it is possible to start a new instance of EA1 ?


echo "Thanks" && echo "Best Regards" | all

 
Not possible. The EA is exiting, and OnDeinit must exit within 2.5 seconds. Stop thinking about trying to kludge around it, print the reason and fix it.
 
Christian Stern:

Hey all,

is it possible to cancel a OnDeinit request ? Like i have EA1 and EA2, EA2 has dependencies on EA1. For some reason EA1 is turning into a "OnDeinit" state, now i want to check if he is allowed to exit.

OnDeinit is a void function which will have no return check and this also means the deinit request is already in progress. Is there any way to bypass request ? Or it is possible to start a new instance of EA1 ?


echo "Thanks" && echo "Best Regards" | all


Use global variables to set state flags. This is an example of using a single variable to share state using a bitmask.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
string gv = "EA_STATUS";
enum EA_STATES
  {
   EA1_RUNNING = 1,
   EA2_RUNNING = 2
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
//ea 1
//oninit
   if(!SetStatus(EA1_RUNNING,true))
      return; //INIT_FAILED;

//ea2 oninit
   if(!SetStatus(EA2_RUNNING,true))
      return;

   //ea1 deinit()
   if(!SetStatus(EA1_RUNNING,false))
      Alert("EMERGENCY-couldn't set global var!");
      
   //ea2 ontick status update
   if(!GetStatus(EA1_RUNNING))
      if(SetStatus(EA2_RUNNING,false))
         ExpertRemove();
  }
//+------------------------------------------------------------------+

bool GetStatus(EA_STATES state)
  {
   double res=0;
   if(!GlobalVariableCheck(gv))
      return false;
   if(bool((int)res&state))
      return true;
   return false;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool SetStatus(EA_STATES state,bool flag)
  {
   double res=0;
   int set=0;
   if(GlobalVariableCheck(gv) && !GlobalVariableGet(gv,res))
      return false;
   set=(int)res;
   if(flag)
      set|=state;
   else
      set&=~state;
   return (GlobalVariableSet(gv,set)>0);
  }
//+------------------------------------------------------------------+
 
nicholishen:

Use global variables to set state flags. This is an example of using a single variable to share state using a bitmask.

How is that related to the topic about cancelling DeInit event ?

 
Alain Verleyen:

How is that related to the topic about cancelling DeInit event ?


Because OP can't cancel a DeInit so he better be checking up on the state of the dependency. 

 
nicholishen:

Because OP can't cancel a DeInit so he better be checking up on the state of the dependency. 

Ok but it seems to me the EA dependency is secondary, if his EA is running OnDeInit() and he doesn't know why. So @whroeder1 is right, check that firstly.

Your EA status comes after but could help I guess, but accessing a GV from several EAs you will need a mutex to avoid this " Alert("EMERGENCY-couldn't set global var!");"

Reason: