Download MetaTrader 5

Reading from the Log File in Real Time

To add comments, please log in or register
James Parker
951
James Parker 2016.01.11 00:02 

I've written an EA (with help of existing code I have found on the forum and the net) that reads in information from the experts log file.

However, I need the information in real time, and the log file is only updated in intervals throughout the day I think, when the terminal is closed, or when you right click on the log in the terminal and click open.

I've found this piece of code someone has written - https://www.mql5.com/en/forum/131720 - to perform a similar task where it accesses the terminal journal - repeatedly opening and closing the file to update it.

Does anyone know how I can modify this to perform the same task with the experts log file? (rather than the journal)

This is my first time using these dll functions. I'm guessing it's in the  "PostMessageA(hwnd,WM_COMMAND ,33101,0);" part, but I don't understand how it can know where the journal is from this command.

Any help would be massively appreciated! Thanks in advance!

 

( *edit - updated the code below to use PostMessageW and FindWindowW instead of PostMessageA and FindWindowA... though I'm not sure what the difference is between these two and what they actually do!... )

#include <WinUser32.mqh>

#import "user32.dll"
  int GetAncestor(int hWnd, int gaFlags);
#import
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void start()
{
  int hwnd = GetAncestor(WindowHandle(Symbol(),Period()),2); // find the Terminal handle no.
  PostMessageW(hwnd,WM_COMMAND ,33101,0); // open the folder contains the log files
  //-----
  while (FindIfDirOpened() == 0) // check if the folder opened
      {
      Sleep(100);
      FindIfDirOpened();
      }
   PostMessageW(FindIfDirOpened(), WM_CLOSE, 0, 0); //close the folder
}

int FindIfDirOpened()
   {
   string log = "logs";
   string i;
   int handle = FindWindowW(i ,log);
   return(handle);
   }
reading the Journal in real time - MQL4 forum
  • www.mql5.com
reading the Journal in real time - MQL4 forum
Carl Schreiber
6669
Carl Schreiber 2016.01.11 09:49  
James Parker:

I've written an EA (with help of existing code I have found on the forum and the net) that reads in information from the experts log file.

However, I need the information in real time, and the log file is only updated in intervals throughout the day I think, when the terminal is closed, or when you right click on the log in the terminal and click open.

I've found this piece of code someone has written - https://www.mql5.com/en/forum/131720 - to perform a similar task where it accesses the terminal journal - repeatedly opening and closing the file to update it.

Does anyone know how I can modify this to perform the same task with the experts log file? (rather than the journal)

This is my first time using these dll functions. I'm guessing it's in the  "PostMessageA(hwnd,WM_COMMAND ,33101,0);" part, but I don't understand how it can know where the journal is from this command.

Any help would be massively appreciated! Thanks in advance!

 

Try to replace PostMessageA(..) by PostMessageW(..)
James Parker
951
James Parker 2016.01.11 13:28  
calli:
Try to replace PostMessageA(..) by PostMessageW(..)

Just tried this and it's still opening and closing the journal, rather than the experts log. I need to it open and close the experts log file instead.

Forgot to mention I had to amend the code above to change the FindWindowA to FindWindowW in order to get it to work, the FindWindowA was giving an error.

Does anyone know how to tell it to look for the experts log instead? 

Stanislav Korotky
18203
Stanislav Korotky 2016.01.12 14:29  
You can use Spy++ or similar utility to monitor system messages between windows and catch command number you need.
Introducing Spy++
Introducing Spy++
  • msdn.microsoft.com
There are two versions of Spy++. The first version, named Spy++ (spyxx.exe), is designed to display messages sent to a window that is running in a 32-bit process. For example, Visual Studio runs in a 32-bit process. Therefore, you can use Spy++ to display messages sent to Solution Explorer. Because the default configuration for most builds in...
James Parker
951
James Parker 2016.01.12 16:04  
Stanislav Korotky:
You can use Spy++ or similar utility to monitor system messages between windows and catch command number you need.

Hi Stanislav,

Thank you for responding. Unfortunately I don't have any experience with Visual Studio or the programming that would be required for Spy++. I'm having a look into it now though to see if it something that I could pick up easily.

Please could you elaborate on how this would work? What is the catch command number, is that the "33101"? If so, I'll still need to find the command number for the experts log.

Thanks. 

Ex Ovo Omnia
3192
Ex Ovo Omnia 2016.01.13 08:22  
James Parker:

Hi Stanislav,

Thank you for responding. Unfortunately I don't have any experience with Visual Studio or the programming that would be required for Spy++. I'm having a look into it now though to see if it something that I could pick up easily.

Please could you elaborate on how this would work? What is the catch command number, is that the "33101"? If so, I'll still need to find the command number for the experts log.

Thanks. 

Well, you might optionally use trial&error metod and scan surrounding numbers from the last known 33063 - (History to Last Month) to the next known 33134 - (D1 timeframe), to test which one opens the log folder.
To add comments, please log in or register