Is it possible to turn off the logging option with MT4?
My EAs and indicators log so much garbage data, i would like to turn it off.
I don't know if there is any better way to do it, but I just right click and delete log files and start recording new logs. If there is something I really want to review, just select all, copy and paste in MS Word and save in another folder. It works for me, hope it helps.
I don't know if there is any better way to do it, but I just right click and delete log files and start recording new logs. If there is something I really want to review, just select all, copy and paste in MS Word and save in another folder. It works for me, hope it helps.
Elo. I'm a programmer who is idling. I'm writing MQL4 scripts. Here is my little log mechanism that I hope you find useful. Put it into an include file.
Deleting log files
-------------------
First up, if you start MT4 from the command line you can write a batch file to do that and inside the batch file you can get it to remove all the log files.
I hate using DOS - it is so clumsy. My Cygwin command looks something like "find '/e/program files/metatrader' -iname '*.log' -exec rm -f {} \;".
Reducing the garbage
-------------------------
I call this include file "mcblog.mqh". You have to put it into the "include" directory and "#include" it in your EA.
Then you can log stuff this way, and use the "verbosity" mechanism to limit the garbage that collects in your log file.
...
log(TYP_LOG_INFO, sMyName, Time[g_nBarStart], "nNewStopLoss=" + nNewStopLoss);
...
static int TYP_LOG_FATAL = 1;
static int TYP_LOG_ERROR = 3;
static int TYP_LOG_WARNING = 5;
static int TYP_LOG_INFO = 7;
static int TYP_LOG_DEBUG = 9;
extern int g_nLogVerbosity = 10;
string appendWithSeparator(string sMessage, string sItem, string sSeparator)
{
string result = sMessage;
if (sItem != "")
{
if (result != "")
{
result = result + sSeparator;
}
result = result + sItem;
}
return(result);
}
string toStringTimeStamp(datetime nTimeStamp, datetime nDefault)
{
string result = "";
if (nTimeStamp <= 0)
{
nTimeStamp = nDefault;
}
if (nTimeStamp > 0)
{
result = TimeToStr(nTimeStamp, TIME_DATE | TIME_SECONDS);
}
return(result);
}
void log(int nLogType, string sMyName, datetime nTimeStamp, string p_sMessage)
{
if (nLogType <= g_nLogVerbosity)
{
string sMessage = "";
sMessage = appendWithSeparator(sMessage, toStringTimeStamp(nTimeStamp, TimeCurrent()), " ");
sMessage = appendWithSeparator(sMessage, sMyName, " ");
if (nLogType == TYP_LOG_ERROR)
{
int nError = GetLastError();
string sError = ErrorDescription(nError);
sMessage = appendWithSeparator(sMessage, "ERROR: " + nError + " (" + sError + ")", " ");
}
else if (nLogType == TYP_LOG_WARNING)
{
sMessage = appendWithSeparator(sMessage, "WARNING:", " ");
}
sMessage = appendWithSeparator(sMessage, p_sMessage, " ");
Print(sMessage);
if (nLogType == TYP_LOG_FATAL)
{
Alert(p_sMessage);
}
}
}
void commentLog(string sMessage)
{
static string sMyName = "commentLog";
Comment(sMessage);
log(TYP_LOG_INFO, sMyName, 0, sMessage);
}
First up, if you start MT4 from the command line you can write a batch file to do that and inside the batch file you can get it to remove all the log files.
I hate using DOS - it is so clumsy. My Cygwin command looks something like "find '/e/program files/metatrader' -iname '*.log' -exec rm -f {} \;".
Using the same assumption that each MetaTrader installation within Program Files will have "metatrader" in its folder name, then a simple DOS equivalent to delete all log files from all copies of MetaTrader goes as follows:
for /D %A in ("%ProgramFiles%\*metatrader*") do del %A\*.log /s
Needs modification on 64-bit systems, because it'll otherwise look for MetaTrader in the 64-bit version of Program Files rather than the 32-bit version.
"Clumsiness" is in the eye of the beholder - it isn't too elegant to suggest going to the lengths of installing Cygwin just to delete some files on a batched basis.
jjc: Ye that's a fair comment. I was just too lazy to post the DOS version. You could add "/q" to the "/s" and I think you have to wrap the %A in double quotes like this:
for /d %A in ("u:\program files\*metatrader*") do del /s/q "%A"\*.log
Using the same assumption that each MetaTrader installation within Program Files will have "metatrader" in its folder name, then a simple DOS equivalent to delete all log files from all copies of MetaTrader goes as follows:
for /D %A in ("%ProgramFiles%\*metatrader*") do del %A\*.log /s
Needs modification on 64-bit systems, because it'll otherwise look for MetaTrader in the 64-bit version of Program Files rather than the 32-bit version.
"Clumsiness" is in the eye of the beholder - it isn't too elegant to suggest going to the lengths of installing Cygwin just to delete some files on a batched basis.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is it possible to turn off the logging option with MT4?
My EAs and indicators log so much garbage data, i would like to turn it off.