Logging and tester

 

I am trying to log variable values using File Functions but for unknown reason no file is created and nothing is logged :( Below is a simple example. Is it so that these functions are not usable with the tester?

//+------------------------------------------------------------------+
//|                                                      Logging.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
int fileHandle=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int visits;
   if(fileHandle==0||fileHandle==INVALID_HANDLE)
      fileHandle=FileOpen("log.txt",FILE_WRITE|FILE_TXT|FILE_SHARE_READ|FILE_UNICODE);
   if(rates_total>prev_calculated)
     {
      FileWrite(fileHandle,"Bar number: ",rates_total);
      visits++;
     }
   Comment("visits= ",visits);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Candles:

I am trying to log variable values using File Functions but for unknown reason no file is created and nothing is logged :( Below is a simple example. Is it so that these functions are not usable with the tester?

You should check the filehandle after you attempt to open the file,  if it is returned as INVALID_HANDLE  Print("Error opening file, error# ", GetLastError() ) and see what the error is.  If the handle is OK then it might be a UAC issue,  what folder do you have MT5 installed in ? 

Where do you close the file ? 

 
Its hard to tell if the problem is in UAC. This code works just fine when I attach it to the chart. So MetaTrader has correct user privileges. It may well be tha Strategy Tester does not have them. I wonder does that code log data on someone elses computer. I cannot do any changes to UAC on my current system.
Br, Candles
 
Candles:
Its hard to tell if the problem is in UAC. This code works just fine when I attach it to the chart. So MetaTrader has correct user privileges. It may well be tha Strategy Tester does not have them. I wonder does that code log data on someone elses computer. I cannot do any changes to UAC on my current system.
Br, Candles

Ah,  it works but not in the Strategy Tester,  it's probably not a UAC issue then.

 

Where are you looking for the file ?  I ran you code and found log.txt in here:  \tester\Agent-127.0.0.1-3000\MQL5\Files\

 
RaptorUK:

Ah,  it works but not in the Strategy Tester,  it's probably not a UAC issue then.

 

Where are you looking for the file ?  I ran you code and found log.txt in here:  \tester\Agent-127.0.0.1-3000\MQL5\Files\

More info here.
 
RaptorUK:

Ah,  it works but not in the Strategy Tester,  it's probably not a UAC issue then.

 

Where are you looking for the file ?  I ran you code and found log.txt in here:  \tester\Agent-127.0.0.1-3000\MQL5\Files\

Good that solved it. I was looking from \MetaTrader 5\MQL5\Files as per references. It seems that tester uses a different location to save the file. Thank you.

Br, Candles

 
angevoyageur:
More info here.
Thank you,  bookmarked :-)
Reason: