Using MetaTrader Events to run batch files...

 

Hi,

I'm having a few issues when attempting to configure MetaTrader's Events to run batch files. If I go to the Tools->Options->Events screen and configure the "Connect" and "Disconnect" events to run batch files (see accompanying graphic) as per the documentation, the terminal outputs a standard system beep when either of the events are triggered but the contents of the batch files aren't actually executed. Even if I only place the line:

type NUL > "d:\temp\S1000_Connect.txt"

into either of the batch files, the resulting "S1000_Connect.txt" file doesn't get created. If I run this same configuration on a MT4 platform, everything works fine. Any ideas?
Files:
Events.jpg  73 kb
 
cowil:

Hi,

I'm having a few issues when attempting to configure MetaTrader's Events to run batch files. If I go to the Tools->Options->Events screen and configure the "Connect" and "Disconnect" events to run batch files (see accompanying graphic) as per the documentation, the terminal outputs a standard system beep when either of the events are triggered but the contents of the batch files aren't actually executed. Even if I only place the line:

type NUL > "d:\temp\S1000_Connect.txt"

into either of the batch files, the resulting "S1000_Connect.txt" file doesn't get created. If I run this same configuration on a MT4 platform, everything works fine. Any ideas?

I don't remember the last time I use batch file, so I'm totally rusty about this ;D.

After reading your topic here, I thought the problem was UAC issue for Vista/7/8, and so the solution was simply to install MT outside C:\Program Files\...

However i don't think that is the solution, coz when I try to make my MT5 to open its own ME5 (MetaEditor 5), it does not works !, but works on MT4 - in fact my MT4 opens ME 5 !  :(. 

 
phi.nuts:

I don't remember the last time I use batch file, so I'm totally rusty about this ;D.

After reading your topic here, I thought the problem was UAC issue for Vista/7/8, and so the solution was simply to install MT outside C:\Program Files\...

However i don't think that is the solution, coz when I try to make my MT5 to open its own ME5 (MetaEditor 5), it does not works !, but works on MT4 - in fact my MT4 opens ME 5 !  :(. 

Firstly, thanks for looking into this.

 I've had a lot of issues with UAC in the past so now install all apps in a separate apps directory on my machine (i.e. not ...\Program Files or ..\Program Files (x86)). Both MT4 and MT5 are installed in this apps directory so I can't see these batch file problems being related to UAC. I've also tried firing off the commands in the batch files within separate command shells (using cmd /c) but that didn't make any difference either. 

The fact that the standard system beep (or system "bell") sounds when these events are generated, makes me think that some sort of error condition is being triggered within MT5. Unfortunately though, nothing comes up in the logs.. :(

BUT - maybe I'm going about this the wrong way? Basically my goal is for MetaTrader to send me an e-mail when it looses it's connection or reconnects with the trading server. With MT4, I used the "Connect" and "Disconnect" events to call separate connect and disconnect batch files, which in turn, called a sendmail utility to send me an e-mail of these events. I'd looked at the IsConnected() function in MT4 and it's equivalent MT5 version (TerminalInfoInteger(TERMINAL_CONNECTED)) but since an Expert is only called on a tick update (which won't be happening if the connection is lost), these functions aren't of much help to me.

If you have any other ideas, I'd be glad to hear them. :) 

 
cowil:

Firstly, thanks for looking into this.

 I've had a lot of issues with UAC in the past so now install all apps in a separate apps directory on my machine (i.e. not ...\Program Files or ..\Program Files (x86)). Both MT4 and MT5 are installed in this apps directory so I can't see these batch file problems being related to UAC. I've also tried firing off the commands in the batch files within separate command shells (using cmd /c) but that didn't make any difference either. 

The fact that the standard system beep (or system "bell") sounds when these events are generated, makes me think that some sort of error condition is being triggered within MT5. Unfortunately though, nothing comes up in the logs.. :(

BUT - maybe I'm going about this the wrong way? Basically my goal is for MetaTrader to send me an e-mail when it looses it's connection or reconnects with the trading server. With MT4, I used the "Connect" and "Disconnect" events to call separate connect and disconnect batch files, which in turn, called a sendmail utility to send me an e-mail of these events. I'd looked at the IsConnected() function in MT4 and it's equivalent MT5 version (TerminalInfoInteger(TERMINAL_CONNECTED)) but since an Expert is only called on a tick update (which won't be happening if the connection is lost), these functions aren't of much help to me.

If you have any other ideas, I'd be glad to hear them. :) 

Yep I had that beep sound but nothing happened :(.

If this is just for send mail when not connected, use OnTimer then, which also use EventSetTimer() and EventKillTimer().

I write this code (in hurry) using EA, which actually can also work well using CI.

I also add IsInternetConnected() from Connect.dll, to test if we have internet connection. I haven't try this, so you may want to try to disconnect your internet connection to see the result.

//+------------------------------------------------------------------+
//|                                                        Timer.mq5 |
//|                                 Copyright 21 jan 2013 , phi.nuts |
//|                               https://www.mql5.com/en/forum/10166 |
//+------------------------------------------------------------------+
#property copyright "Copyright 21 jan 2013 , phi.nuts"
#property link      "https://www.mql5.com/en/forum/10166"
#property version   "1.00"

#import "Connect.dll"
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366143(v=vs.85).aspx
   int  IsInternetConnected();  // 0 = connected 1 = not connected
#import

bool Set_Timer;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   Set_Timer = EventSetTimer(1); //--- set timer for 1 second
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   if (Set_Timer == true) EventKillTimer(); 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 { 
  return;
 }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   if (Set_Timer == true)
     {
     string txt = NULL;
   
     if (TerminalInfoInteger(TERMINAL_CONNECTED))
       {
       Print("Connected to server");
       }
      else
       {
       Print("Not connected to server");
       } 
     
     if (IsInternetConnected() == 0)
        {
        Print("Connected to Internet");
        }
       else
        {
        Print("Not connected to Internet");
        }
     }
   
  }
//+------------------------------------------------------------------+
 
phi.nuts:

Yep I had that beep sound but nothing happened :(.

If this is just for send mail when not connected, use OnTimer then, which also use EventSetTimer() and EventKillTimer().

I write this code (in hurry) using EA, which actually can also work well using CI.

I also add IsInternetConnected() from Connect.dll, to test if we have internet connection. I haven't try this, so you may want to try to disconnect your internet connection to see the result.

Ah - using a timer - of course! Great idea! I'll implement this and give it a go - it'll save me using the separate sendMail library as well (always a hassle to set up with most e-mail providers using SSL/TLS these days). Thanks again for your help!

Oh, and will you be reporting the Event batch/exe execution problems as a bug with MT5? It does appear to be that as this feature works fine with MT4. It's just that there's a couple of other things I've been thinking of using Event batch/exe execution for so it'd be great if this feature worked as it should.

Thanks again! 

 

 
cowil:

Ah - using a timer - of course! Great idea! I'll implement this and give it a go - it'll save me using the separate sendMail library as well (always a hassle to set up with most e-mail providers using SSL/TLS these days). Thanks again for your help!

Oh, and will you be reporting the Event batch/exe execution problems as a bug with MT5? It does appear to be that as this feature works fine with MT4. It's just that there's a couple of other things I've been thinking of using Event batch/exe execution for so it'd be great if this feature worked as it should.

Thanks again! 

You too can write to Service Desk on your profile page.
 
phi.nuts:
You too can write to Service Desk on your profile page.
I can? Right. I'll do that...
 

I confirm this is now working. Build 794.


Reason: