Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2011.12.03 12:29 

Re: https://www.mql5.com/en/forum/136275/page3#532562

I got my php working as a Cron job. I created a simple EA to send the file via FTP and set the Cron job (I use cPanel based hosting) to run every 2 mins.

The php . . .

<?php
$to = "your@email.com";
$subject = "EA is silent";
$body = "EA has stopped responding . . . ";
$minutes = 3;               // max allowable age of file in mins
$file = '/home/crum/public_html/ea/cron.txt';
$filetime = filemtime($file);
$max_age = time()-($minutes * 60); // max age of file in seconds since Jan 1970
// print "File: $file  Filetime: $filetime  twomins:  $timetwomins";

if ($filetime < $max_age && ( ( date(w) > 0 && date(w) < 5 ) || ( date(w) == 5 && date(G) < 22 ) || ( date(w) == 0 && date(G) > 22 ) ) ) {
   mail($to, $subject, $body);
}
?>

The EA

//+------------------------------------------------------------------+
//|                                                   TestCron.mq4   |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

extern int FTPFrequency = 2;  //every x minutes send the file via FTP

int init()
  {
   
   return(0);
  }

int deinit()
  {

   return(0);
  }

int start()
   {
   static datetime LastTimeSent = 0;
   
   if (TimeCurrent() > LastTimeSent + (PERIOD_M1 * 60 * FTPFrequency))
      {
      SendFTP("cron.txt");
      LastTimeSent = TimeCurrent();
      }

   return(0);
   }

It's all a little rough round the edges, I will make the php a little more configurable so it's easier to use with different time zones . . . but it works so far.

Tradeing Trader
556
Tradeing Trader 2013.09.21 09:27  
With your Idea its maybe possible to find out that a timeout error have happen, but the MetaTrader must be restart when a timeout error happen, how can i let the MetaTrader to be restart automatic when i am not at home and the timeout error have happen?
Tonny Obare
1047
Tonny Obare 2013.11.03 20:07  
RaptorUK:

Re: https://www.mql5.com/en/forum/136275/page3#532562

I got my php working as a Cron job. I created a simple EA to send the file via FTP and set the Cron job (I use cPanel based hosting) to run every 2 mins.

The php . . .

The EA

It's all a little rough round the edges, I will make the php a little more configurable so it's easier to use with different time zones . . . but it works so far.

I noticed you mentioned php. What is the easiest way for a ea to send data to a php web app like say ea sends data to server then via a php app this data is redistributed or displayed?
Pierre Rougier
386
Pierre Rougier 2013.11.03 21:47  
MetaTrader send a file to your website with the SendFTP bool (string filename, string ftp_path = NULL)
You have to configure your website with a cron that periodically execute the PHP script.

Do a Google search : php cron
Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2013.11.03 22:39  
tonny:
I noticed you mentioned php. What is the easiest way for a ea to send data to a php web app like say ea sends data to server then via a php app this data is redistributed or displayed?
No idea, the only php I know is the bit I researched for this little project . . .
Pierre Rougier
386
Pierre Rougier 2015.01.11 21:21  
RaptorUK:

Re: https://www.mql5.com/en/forum/136275/page3#532562

I got my php working as a Cron job. I created a simple EA to send the file via FTP and set the Cron job (I use cPanel based hosting) to run every 2 mins.

The php . . .

The EA

It's all a little rough round the edges, I will make the php a little more configurable so it's easier to use with different time zones . . . but it works so far.

Hi,

Nothing new since 2011 ?

Can we add to send SMS ?

With my web hosting I can only run a cron one time / hour. 

/
To add comments, please log in or register