Need help, sine functions in my EA stops working after a fiew hours.

 

Hi,

 I have a strage problem.

I have written a EA that is running two timers and when they are at zero they run a file write function that my Chrome Extenssion reads and preforms the login/logut.

It is working fine , but only for a couple of hours and then after lets say sex-seven hours it stops working.. When it stops working, my EA is still running and i have no error messages, but it doent run the filewrite command. Now, when this happends i have also the filewrite command in a script and when i run it it works.. for the EA to work again i need to reload the EA.

 

this is my include file that my EA and script it calling the filewrite function for

 

 //-bolibs.mqh (include file)--------------------------------------------------------

#define PIPE_NAME "pipe11"

bool login(string url, string username, string password)

{

  string file = "\\\\.\\pipe\\"+PIPE_NAME;

  int file1 = FileOpen(file, FILE_WRITE|FILE_BIN);

  if (file1 == INVALID_HANDLE) {

  return false;

  }

  return FileWriteString(file1, StringFormat("%s,%s,%s,%s\r\n", "login", url, username, password));     

}

bool logout(string url)

{

string file = "\\\\.\\pipe\\"+PIPE_NAME;

int file1 = FileOpen(file, FILE_WRITE|FILE_BIN);

if (file1 == INVALID_HANDLE) {

return false;

}

return FileWriteString(file1, StringFormat("%s,%s,X,X\r\n", "logout", url));    

} 

 //------------------------------------------------------------------

and this is my login timer EA..

//|                                                   logintimer.mqh |

//|                                          Copyright 2015, slicken |

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

#property copyright     "copyright 2015, slicken"

#property version       "2.3"

#property link          "slicken@gmail.com"

#property description   "this ea handles login logout and break idle on my web based binary option brokers\n"

                        "settings are defined in minutes\n" 

                        "\n\n"

                        "coded by Daniel Sic 'slicken' (slicken@gmail.com)\n"

#property indicator_chart_window

#include <bolibs.mqh>

string   note           = "____ BROKER SETTINGS";

string   broker1name    = "24OPTION";                                   // name of broker

string   broker1url     = "https://www.24option.com/";                  // https://adressforbroker

string   broker1log     = "login@email.com";                                // account login

string   broker1pass    = "password";                                 // account password

bool     broker1        = false;                                        // enable/disable this broker

//-----------------------

string   broker2name    = "STOCKPAIR";                                  // name of broker

string   broker2url     = "https://www.stockpair.com/sp#trading/page/"; // https://adressforbroker

string   broker2log     = "login@gmail.com";                          // account login

string   broker2pass    = "password";                                  // account password

bool     broker2        = true;                                         // enable/disable this broker

//-----------------------

string   note_          = "____ TIME SETTINGS";

bool     usetimelocal   = false;                                        // use local time

bool     alwaysonline   = true;                                         // always online

string   online         = "07:00";                                      // login this time

string   offline        = "20:00";                                      // logout this time

int      notrade        = SUNDAY;                                       // dont login this day

int      refresh        = 4;                                            // refresh/break idle every min

int      relog          = 25;                                           // relogin every min

bool     preform_relog  = true;                                         // do relog

//-----------------------

string   note__         = "____ VISUAL SETTINGS";

string   label          = "broker";                                     // name the label

string   textfont       = "Calibri";                                    // text font

color    textcolor      = Gray;                                         // text color

int      textsize       = 7;                                            // text size

int      x              = 5;                                            // text posision x

int      y              = 5;                                            // text posision y

int      yplus          = 12;                                           // gap size for new row

int      textcorner     = 2;                                            // text corner

datetime time1,time2;

string info1,info2;

int timer1,timer2;

int init(){

   time1=(usetimelocal?TimeLocal():TimeCurrent());

   time2=(usetimelocal?TimeLocal():TimeCurrent());

   return(0);

}

int deinit(){

   deleteall();

   return(0);

}

int start(){

   if(preform_relog){

      if(timer1+60>timer2&&timer1-60<timer2)

         time1+=(usetimelocal?TimeLocal():TimeCurrent())-time1;

   }

   if(((usetimelocal?TimeLocal():TimeCurrent())>=StrToTime(online)&&(usetimelocal?TimeLocal():TimeCurrent())<StrToTime(offline)&&

   TimeDay((usetimelocal?TimeLocal():TimeCurrent()))!=(SUNDAY||notrade))||alwaysonline){

      if((usetimelocal?TimeLocal():TimeCurrent())==StrToTime(online))

         if(broker1)login(broker1url,broker1log,broker1pass);

      if((usetimelocal?TimeLocal():TimeCurrent())==StrToTime(online)+10)

         if(broker2)login(broker2url,broker2log,broker2pass);

      timer1=(time1+(refresh*60)-(usetimelocal?TimeLocal():TimeCurrent()));

      timer2=(time2+(relog*60)-(usetimelocal?TimeLocal():TimeCurrent()));

      if(15<timer1)info1="(refresh "+(timer1/60)+" min)";

      if(15>timer1)info1="(REFRESHIN)";

      if(10==timer1)if(broker1)login(broker1url,broker1log,broker1pass);

      if(0>timer1){

         if(broker2)login(broker2url,broker2log,broker2pass);

         time1=(usetimelocal?TimeLocal():TimeCurrent());

      }

      if(preform_relog){

         if(20<timer2)info2="relogin "+(timer2/60)+" min";

         if(20>timer2)info2="RELOGING";

         if(15==timer2)if(broker1)logout(broker1url);

         if(10==timer2)if(broker1)login(broker1url,broker1log,broker1pass);

         if(5==timer2)if(broker2)logout(broker2url);

         if(0>timer2){

            if(broker2)login(broker2url,broker2log,broker2pass);

            time2=(usetimelocal?TimeLocal():TimeCurrent());

         }

      }

   }

   if((usetimelocal?TimeLocal():TimeCurrent())==StrToTime(offline&&

   TimeDay((usetimelocal?TimeLocal():TimeCurrent()))!=(SUNDAY||notrade))&&!alwaysonline){

      if(broker1)logout(broker1url);

      if((usetimelocal?TimeLocal():TimeCurrent())==StrToTime(offline)+10)

         if(broker2)logout(broker2url);

         info1="OFFLINE";

         info2="";

   }

   brokerinfo();

   return(0);

}

void deleteall(){

   string objname;

   int labellen=StringLen(label);

   for(int o=ObjectsTotal()-1;o>=0;o--){

      objname=ObjectName(o);

      if(StringSubstr(objname,0,labellen)==label){

         ObjectDelete(objname);

      }

   }

}

void brokerinfo(){

   ObjectCreate(label+" "+"top",OBJ_LABEL,0,0,0);

   ObjectSet(label+" "+"top",OBJPROP_CORNER,textcorner);

   ObjectSet(label+" "+"top",OBJPROP_XDISTANCE,x);

   ObjectSet(label+" "+"top",OBJPROP_YDISTANCE,y);

   ObjectSetText(label+" "+"top","LOGIN TIMER FOR "+broker1name+" AND "+broker2name,textsize,textsize,textcolor);

   ObjectCreate(label+" "+"line1",OBJ_LABEL,0,0,0);

   ObjectSet(label+" "+"line1",OBJPROP_CORNER,textcorner);

   ObjectSet(label+" "+"line1",OBJPROP_XDISTANCE,x);

   ObjectSet(label+" "+"line1",OBJPROP_YDISTANCE,y+yplus);

   ObjectSetText(label+" "+"line1","_________________________________________",textsize,textsize,textcolor);

   ObjectCreate(label+" "+"online",OBJ_LABEL,0,0,0);

   ObjectSet(label+" "+"online",OBJPROP_CORNER,textcorner);

   ObjectSet(label+" "+"online",OBJPROP_XDISTANCE,x);

   ObjectSet(label+" "+"online",OBJPROP_YDISTANCE,y+yplus);

   ObjectSetText(label+" "+"online",(alwaysonline?"ONLINE":online+" - "+offline),textsize,textsize,textcolor);

   if(preform_relog){

      ObjectCreate(label+" "+"relog",OBJ_LABEL,0,0,0);

      ObjectSet(label+" "+"relog",OBJPROP_CORNER,textcorner);

      ObjectSet(label+" "+"relog",OBJPROP_XDISTANCE,x+80);

      ObjectSet(label+" "+"relog",OBJPROP_YDISTANCE,y+yplus);

      ObjectSetText(label+" "+"relog",info2,textsize,textsize,textcolor);

   }

   ObjectCreate(label+" "+"refresh",OBJ_LABEL,0,0,0);

   ObjectSet(label+" "+"refresh",OBJPROP_CORNER,textcorner);

   ObjectSet(label+" "+"refresh",OBJPROP_XDISTANCE,x+170);

   ObjectSet(label+" "+"refresh",OBJPROP_YDISTANCE,y+yplus);

   ObjectSetText(label+" "+"refresh",info1,textsize,textsize,textcolor);

}

//------------------------------------------------------------- 
 
i might add that i run my other main EA on 7 pairs and its about 2k lines of code, so its prety heavy.. might it be that memory is full or something? computer is running fine and i get no errror messages.. please help, i have tryed to make the login EA run OnTimer event and same problem occours
 
slicken:
i might add that i run my other main EA on 7 pairs and its about 2k lines of code, so its prety heavy.. might it be that memory is full or something? computer is running fine and i get no errror messages.. please help, i have tryed to make the login EA run OnTimer event and same problem occours
in order to make clear run only ONE ea and look what happens.
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 

Failures probably are due to misalignment, asynchronous processes run login and logout.
For work, try the following:
1. Leave at EA only one broker, for a second, you can run another EA.
2. Combine the login and logout in the same function with an exposure time-out in a loop while (LogTime> TimeCurrent ()).
3. Also, the main program block, it is better not to perform ticks, and in an infinite loop, for example while (! IsStopped ()).

Best regards Philipp 

 
negre:

Failures probably are due to misalignment, asynchronous processes run login and logout.
For work, try the following:
1. Leave at EA only one broker, for a second, you can run another EA.
2. Combine the login and logout in the same function with an exposure time-out in a loop while (LogTime> TimeCurrent ()).
3. Also, the main program block, it is better not to perform ticks, and in an infinite loop, for example while (! IsStopped ()).

Best regards Philipp 

thx for the tip, but unfotunelty i dont know what you mean by this..

how do you mean by ut login and logout command on same function? i have tryed with sleep for 5 sec between logoin and logout but i dont get it to work..

the chrome plugin i cant change cause i ddidnt make it and dont have the source. 

could you please give examples with what you mean?

i have tryed my login EA to work with OnTimer event but same happends there, it runs good for 10 hours and then it suddenly wont preform the login commands...

 
slicken:

thx for the tip, but unfotunelty i dont know what you mean by this..

how do you mean by ut login and logout command on same function? i have tryed with sleep for 5 sec between logoin and logout but i dont get it to work..

the chrome plugin i cant change cause i ddidnt make it and dont have the source. 

could you please give examples with what you mean?

i have tryed my login EA to work with OnTimer event but same happends there, it runs good for 10 hours and then it suddenly wont preform the login commands...

bool relogin()
{
  if(!logout(broker1url)) return(false);
  datetime time = (usetimelocal?TimeLocal():TimeCurrent());
  while(((usetimelocal?TimeLocal():TimeCurrent()) - time) < (refresh * 60) &&
  !IsStopped()) Comment("REFRESHING"); Comment("");
  while(!login(broker1url,broker1log,broker1pass) && !IsStopped())
  Comment("Error to login! " + __FUNCTION__); 
  return(true);
}

int start()
{
  datetime time1, time2;
  while(!IsStopped()) {
    time1 = (usetimelocal?TimeLocal():TimeCurrent());
    if(time1 < StrToTime(online) || time1 > StrToTime(offline) || TimeDay(time1) == SUNDAY) continue;
    if(login(broker1url,broker1log,broker1pass)) { 
      time1 = (usetimelocal?TimeLocal():TimeCurrent());
      while(time1 < StrToTime(offline) && !IsStopped()) {
        time2 = (usetimelocal?TimeLocal():TimeCurrent());
        if((time2 - time1) >= (relog * 60)) {
          if(!relogin()) Comment("Error to relogin!"); 
          time1 = (usetimelocal?TimeLocal():TimeCurrent());
        }
      }
      while(!logout(broker1url) && !IsStopped()) Comment("Error to logout!");
    } else Comment("Error to login!");
  }
}
 
negre:
thank you so mutch for your help so far.. i tryed this code but MT4 got caught in infinite loop and freez.. why is this,, sorry for me being so nobish and pretty new as you can see on my code :)
Reason: