why the log file expert/logs/xxx.log not updated automatically?

 

Dear All:

In MetaTrader 4 platform, in the terminal tab "expert", all the messages are also automatically saved in expert/logs/20110825.log (suppose today is 2011-08-25). But recently, I found that is not the case any more: the new messages which show up in termianl tab "expert" are not appended to the 20110825.log file automatically.

If I right mouse click those messages in "expert" tab and select "Open", the Windows Explorer will open. Now, 20110825.log content was updated and contains all the newest messages. In another words, each time new message shows up in "expert" tab, I need to right click the mouse and select "Open" to have the new message appended to the log file. If I don't do that, the log file will not automatically have the new message appended. I am very confused.

By the way, I use Cygwin to go to the directory expert/logs and find and read the log file. The Windows Explorer shows logs/ as empty. -- second mystery.

Thank you very much.

 
xsli2:
I am very confused.

The normal complaint is that some lines are missing in the journal. They are all in the file, just skipped in the journal tab when written too fast.

Missing lines in the file is usually because you installed in \program files* on Vista/Win7

 
I have found that the logs are not updated line by line, sometimes the only way I can get the log complete is to exit MT4, it then flushes the rest of the entries and completes the log.
 

Thank you for your reply. I believe it has to do files/folder permission, User Account Control. One way to fix it is to install MT4 not at the default location(C:/Program Files (x86)/), since User Account Control will affects it, instead install MT4 at, e.g. C:/MT4/

I will give a shot today.

This link has several solutions to solve this problem:

http://4xtrader.net/how-to-run-metatrader-on-windows-7-or-vista/

 
 

Hi,

Sorry to bring this old topic up, but I just faced the same problem: the log files are not updated, just like the original poster explained.

My setup:

Win7x64bit.

I have MetaTrader4 installed on a different (non-system) partition, where every user have write rights.

I have UAC completely disabled.

Still, the logfile is only being updated with the 'contents' of the Experts tab, if I right-click and select Open.



Please advice what to do.

 

Hi,

As a workaround I came up with the idea of an EA, that executes a small script during every newbar creation. And this script is opening and closing the Logfiles locations, which action is updating the contents of the logfiles.

All source codes that I have used are from this forum. I hope the original posters doesn't mind if don't include a link to their posts...

//+------------------------------------------------------------------+
//|                                                   LogUpdater.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>
#import "user32.dll"
  int GetAncestor(int hWnd, int gaFlags);
#import
//+------------------------------------------------------------------+

#define MAX 9
//+------------------------------------------------------------------+

int curIndex;
datetime times[MAX];
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
    curIndex = utils.periodToPeriodIndex(Period());
    times[curIndex] = Time[0];
    for(int i=curIndex+1; i<MAX; i++)
        times[i] = times[curIndex]- MathMod(times[curIndex], utils.periodIndexToPeriod(i)*60);

    return(0);
}

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
    return(0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
    if (times[curIndex] != Time[0]) {
        times[curIndex] = Time[0];
        onBar(Period());
        for (int i=curIndex+1; i<MAX; i++) {
            int period = utils.periodIndexToPeriod(i),
            seconds = period*60,
            time0 = times[curIndex] - MathMod(times[curIndex], seconds);
            if (times[i] != time0) {
                times[i] = time0;
                onBar(period);
            }
        }
    }

    onTick();

    return(0);
}
//+------------------------------------------------------------------+

int utils.periodToPeriodIndex(int period) {
    switch(period) {
        case PERIOD_M1  : return(0); break;
        case PERIOD_M5  : return(1); break;
        case PERIOD_M15 : return(2); break;
        case PERIOD_M30 : return(3); break;
        case PERIOD_H1  : return(4); break;
        case PERIOD_H4  : return(5); break;
        case PERIOD_D1  : return(6); break;
        case 20         : return(7); break;
        case 55         : return(8); break;
  }
}
//+------------------------------------------------------------------+

int utils.periodIndexToPeriod(int index) {
    switch(index) {
        case 0: return(PERIOD_M1); break;
        case 1: return(PERIOD_M5); break;
        case 2: return(PERIOD_M15); break;
        case 3: return(PERIOD_M30); break;
        case 4: return(PERIOD_H1); break;
        case 5: return(PERIOD_H4); break;
        case 6: return(PERIOD_D1); break;
        case 7: return(20); break;
        case 8: return(55); break;
  }
}
//+------------------------------------------------------------------+

void onTick() {
//    Print("onTick() is called.");
}
//+------------------------------------------------------------------+

void onBar(int period) {
//    Print("onBar() is called with period: " + period);
    int hwnd = GetAncestor(WindowHandle(Symbol(), Period()), 2); // find the Terminal handle no.

    PostMessageA(hwnd, WM_COMMAND , 33101, 0);                   // open the folder contains the log files
     
    while (FindIfDirOpened() == 0) {                             // check if the folder opened
       Sleep(100);
       FindIfDirOpened();
    }

    PostMessageA(FindIfDirOpened(), WM_CLOSE, 0, 0);             //close the folder
}
//+------------------------------------------------------------------+

int FindIfDirOpened() {
    string log = "logs";
    string i;
    int handle = FindWindowA(i, log);

    return(handle);
}
//+------------------------------------------------------------------+
 

can anyone explain me what this means: PostMessageA(hwnd, WM_COMMAND, 33101, 0); // open the folder contains the log files

with that values, it only opens de Journal log file, what about de experts log? what is the function of 33101 number?

 

Hi Tamas Csabina,




Thank you a lot for share your code, i hope you don't mind I use and change a little bit trying to make it work to MT5, It's my first programming attempt so please keep in mind that I don't know almost nothing about it! However my code doesn't update log file at logs/yyyyMMdd.log. My code is right below, someone have any idea how to solve the update log problem?


Thanks in advance



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


//|                                                   LogUpdater.mq5 |


//|                        Copyright 2017, MetaQuotes Software Corp. |


//|                                             https://www.mql5.com |


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


#property copyright "Copyright 2017, MetaQuotes Software Corp."


#property link      "https://www.mql5.com"


#property version   "1.00"




#include <WinUser32.mqh>


#import "user32.dll"


  int GetAncestor(int hWnd, int gaFlags);


#import


#define MAX 9


int curIndex;


datetime times[MAX];




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


//| expert initialization function                                   |


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


int OnInit() 


{


    curIndex = PeriodToPeriodIndex(Period());    


    times[curIndex] = TimeCurrent(); //times[curIndex] = Time[0];


    


    for(int i = curIndex + 1; i < MAX; i++)


        times[i] = times[curIndex]- MathMod(times[curIndex], PeriodIndexToPeriod(i) * 60);




    return(0);


}




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


//| expert deinitialization function                                 |


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


int OnDeinit() 


{


    return(0);


}






void OnTick() 


{


    //Print("onTick() is called.");


}




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


//| Script program start function                                    |


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


void OnStart()


{  


    if (times[curIndex] != TimeCurrent()) //if (times[curIndex] != Time[0])


    {


        times[curIndex] = TimeCurrent(); //times[curIndex] = Time[0];


        onBar(Period());


        


        for (int i = (curIndex + 1); i < MAX; i++) 


        {


            int period = PeriodIndexToPeriod(i),


            seconds = period*60,


            time0 = times[curIndex] - MathMod(times[curIndex], seconds);


            


            if (times[i] != time0) 


            {


                times[i] = time0;


                onBar(period);


            }


        }


    }


    


    OnTick();  


}


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






int PeriodToPeriodIndex(int period) 


{


    switch(period) 


    {


        case PERIOD_M1  : return(0); break;


        case PERIOD_M5  : return(1); break;


        case PERIOD_M15 : return(2); break;


        case PERIOD_M30 : return(3); break;


        case PERIOD_H1  : return(4); break;


        case PERIOD_H4  : return(5); break;


        case PERIOD_D1  : return(6); break;


        case 20         : return(7); break;


        case 55         : return(8); break; 


        default         : return(-1);break;       


    } 


}




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






int PeriodIndexToPeriod(int index) 


{


    switch(index) 


    {


        case 0: return(PERIOD_M1); break;


        case 1: return(PERIOD_M5); break;


        case 2: return(PERIOD_M15); break;


        case 3: return(PERIOD_M30); break;


        case 4: return(PERIOD_H1); break;


        case 5: return(PERIOD_H4); break;


        case 6: return(PERIOD_D1); break;


        case 7: return(20); break;


        case 8: return(55); break;


        default: return(-1);break;


    }  


}




int  WindowHandle(string symbol, int timeframe){ return 0; };


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






int FindIfDirOpened() 


{


    //string log = "logs";


    char cLog[] = {"l", "o", "g", "s"}; // "logs"


    char i[];


    int handle = FindWindowA(i, cLog);




    return(handle);


}


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






void onBar(int period) 


{


    //Print("onBar() is called with period: " + period);    


    int hwnd = GetAncestor(WindowHandle(Symbol(), Period()), 2); // find the Terminal handle no.


    


    PostMessageA(hwnd, WM_COMMAND , 33101, 0);                   // open the folder contains the log files


     


    while (FindIfDirOpened() == 0) 


    {                             // check if the folder opened


       Sleep(100);


       FindIfDirOpened();


    }




    PostMessageA(FindIfDirOpened(), WM_CLOSE, 0, 0);             //close the folder


}


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

Negociação Automatizada e Análise de Estratégia
Negociação Automatizada e Análise de Estratégia
  • www.mql5.com
Escolha o sinal de seu interesse e assine-o em poucos cliques. Todos os Sinais são fornecidos com uma estatística detalhada e gráficos fáceis de utilizar. Torne-se Fornecedor de sinais de negociação e venda assinaturas a milhares de traders em todo o mundo. Nosso serviço irá permitir-lhe ganhar um bom dinheiro através de uma estratégia...
 
gvillasboas: Thank you a lot for share your code, i hope you don't mind I use and change a little bit trying to make it work to MT5, It's my first programming attempt so please keep in mind that I don't know almost nothing about it! However my code doesn't update log file at logs/yyyyMMdd.log. My code is right below, someone have any idea how to solve the update log problem?
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. There is no "update log problem." You Print, the logs get updated.

  3. You have a OnTick and a OnStart. First is for EAs, latter is for Scripts. Not both. BOGUS
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

  4.  int handle = FindWindowA(i, cLog);
    Strings are Unicode since February 3, 2014 (Build 600) BOGUS

  5. The code you posted as nothing to do with writing files. You don''t write at logs/, that is the terminal's folder. you write files at files/.
Reason: