How to make my EA reset itself and start again

 

Hello,

i have a custom made EA for my trading style, it is set as when TP of the active trade is hit the ea will stop trading and delete the pending order and show on "Paused"

the part responsible for that is quoted below, i want to change it so when TP is hit the EA will re-start itself from the beginning, is this possible ?


if(Instants == 0 && Pendings == 1)
   {
      if(GetLastTrade()==1) //Profit trade
      {
        DeletePendings();
        Paused = True;
        email_body = "Congratulation! Takeprofit hits on " + Symbol() + "/" + PeriodToText();
        subj = "Congratulation! Takeprofit hits on " + Symbol();                                 
        if(AlertOn) Alert(subj);   
 

the part responsible for opening new orders when i attach the ea  is shown below if this might help


Thanks in advance


 if(Instants + Pendings == 0) //first run
   {
      if(PlaceFirstOrder()) HedgeIt();   
   }
 

Just call

OnInit();


When you want to reboot the expert.

 

i set the line as shown below,

 if(Instants == 0 && Pendings == 1)
   {
      if(GetLastTrade()==1) //Profit trade
      {
         DeletePendings();
         Paused = false;
         OnInit();      
                email_body = "Congratulation! Takeprofit hits on " + Symbol() + "/" + PeriodToText();
        subj = "Congratulation! Takeprofit hits on " + Symbol();                                 
         if(EmailOn) xpEmailSend(subj,email_body);
         if(AlertOn) Alert(subj);   
      }

but when i come i get the error below

'OnInit' - function not defined 
what am i doing wrong ?

i am not a programmer by the way , just trying to figure out how to do it

 

well the function needs to be defined ,

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
 
Marco vd Heijden:

well the function needs to be defined ,


may be it's an 'old' mt4 with init()?

a) try to recall init()

b) or try to replace init() by OnInit()
Reason: