Write logging data to text file? - page 2

 
WindmillMQL:

To answer my own question: I have a partial solution. This solution works in case the log file already exists. Everywhere in the code where I currently use Alert() can I call this function.

What I don't know yet how to solve is:

(*) how to create a new log file if the log file doesn't exist yet?

(*) how to ensure that writing to file is only being done during paper/live trading, and not during back testing?


Well, printed outputs are saved in the tester log file during testing by default. Live trading log files are found in the terminal log file. File write is not supported in the tester btw. 

You might try conditioning the Print() function with MQLInfoInteger to sort tester and live modes.

 
Nelson Wanyama:

Well, printed outputs are saved in the tester log file during testing by default. Live trading log files are found in the terminal log file. File write is not supported in the tester btw

You might try conditioning the Print() function with MQLInfoInteger to sort tester and live modes.

FileWrite is supported in the tester.

 
Nelson Wanyama: File write is not supported in the tester btw.
Certainly is. Perhaps you should read the manual. File Functions / FileOpen - Reference on algorithmic/automated trading language for MetaTrader 5
 
Nelson Wanyama:

Well, printed outputs are saved in the tester log file during testing by default. Live trading log files are found in the terminal log file. File write is not supported in the tester btw. 

You might try conditioning the Print() function with MQLInfoInteger to sort tester and live modes.

I discovered the same thing. I tried running a short backtest and noticed that no file operation was done. So I don't need code to detect whether I'm doing a backtest or doing paper/live trading.
 
Nelson Wanyama:

Well, printed outputs are saved in the tester log file during testing by default. Live trading log files are found in the terminal log file. File write is not supported in the tester btw. 

You might try conditioning the Print() function with MQLInfoInteger to sort tester and live modes.

WindmillMQL:
I discovered the same thing. I tried running a short backtest and noticed that no file operation was done. So I don't need code to detect whether I'm doing a backtest or doing paper/live trading.

Please do not post false information.

If no file operation was done then it is because of your code, not because  FileWrite doesn't work in the tester.

It is more likely that you couldn't find where the file was stored. Search for the file using File Explorer.

 
Keith Watford:

Please do not post false information.

If no file operation was done then it is because of your code, not because  FileWrite doesn't work in the tester.

It is more likely that you couldn't find where the file was stored. Search for the file using File Explorer.

The tone of your message is rather rash! Please be more careful.


I have done two tests: one is a backtest, and the other is forward testing. During forward testing is text written to the file. And yes, I am able to find the file, open it and read it! I also did a backtest, in Strategy Tester. No text was appended to the file, even though events did occur during the backtest which would normally have been written to file.

 
Keith Watford:

Please do not post false information.

If no file operation was done then it is because of your code, not because  FileWrite doesn't work in the tester.

It is more likely that you couldn't find where the file was stored. Search for the file using File Explorer.

WindmillMQL:

The tone of your message is rather rash! Please be more careful.


I have done two tests: one is a backtest, and the other is forward testing. During forward testing is text written to the file. And yes, I am able to find the file, open it and read it! I also did a backtest, in Strategy Tester. No text was appended to the file, even though events did occur during the backtest which would normally have been written to file.

I see nothing wrong with the tone of my post, whereas I do see something wrong with posting incorrect information.

Text will not be added to an existing file unless it is in the correct folder.

During the backtest, you will find that a new file with the same name was created in the tester file  folder. Search for the file using File Explorer.

 
William Roeder: Certainly is. Perhaps you should read the manual. File Functions / FileOpen - Reference on algorithmic/automated trading language for MetaTrader 5

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing).

 
WindmillMQL:

The tone of your message is rather rash! Please be more careful.


I have done two tests: one is a backtest, and the other is forward testing. During forward testing is text written to the file. And yes, I am able to find the file, open it and read it! I also did a backtest, in Strategy Tester. No text was appended to the file, even though events did occur during the backtest which would normally have been written to file.

You have to understand experienced programmers are reading every day, a lot of assumptions like yours. "It's not possible, it's not working, must be an mql5 bug, or the bug in this library, etc...", all the possible reasons EXCEPT the own responsibility of the coder. And guess what, 99% of the time it IS a coder fault, bug or misunderstanding. The biggest one is NOT READ the documentation (or not correctly). Which is exactly your problem.

When you try to help people, it's a bit irritating to read always similar things and see the same behaviour. A good coder is humble, he knows there is a great chance it is his own work which lead to an issue. Bugs in mql4/mql5 or MT4/MT5 happens, but it's rare compared to the number of times are claiming something is not working or not possible.

Read the documentation again about how mql5 works with files with the Strategy Tester, I am sure you will find the answer and be proud of you

A bit of help :

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
The idea of automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
William Roeder:

Thank you for pointing me in the right direction. I have been able to find the directories (I ran multiple backtests in Strategy Tester) and did find text files there.

The conclusion is that I do need to include code in my EA to avoid creating these text files during backtesting as I don't want to "litter" my computer with these files.

Reason: