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 2016.01.08 13:56 

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 2016.01.08 13:58  

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
4728
Marco vd Heijden 2016.01.08 15:18  

Just call

OnInit();


When you want to reboot the expert.

Ahmad Abdul Hamid
189
Ahmad Abdul Hamid 2016.01.11 20:32  

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
4728
Marco vd Heijden 2016.01.11 22:02  

well the function needs to be defined ,

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
Carl Schreiber
6669
Carl Schreiber 2016.01.12 08:46  
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