Download MetaTrader 5

How to make my EA reset itself and start again

To add comments, please log in or register
Ahmad Abdul Hamid
189
Ahmad Abdul Hamid  

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);   
Ahmad Abdul Hamid
189
Ahmad Abdul Hamid  

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();   
   }
Marco vd Heijden
Moderator
6061
Marco vd Heijden  

Just call

OnInit();


When you want to reboot the expert.

Ahmad Abdul Hamid
189
Ahmad Abdul Hamid  

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

Marco vd Heijden
Moderator
6061
Marco vd Heijden  

well the function needs to be defined ,

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
Carl Schreiber
Moderator
7840
Carl Schreiber  
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()
To add comments, please log in or register