Experts: Examples from the book "Neural networks for algorithmic trading with MQL5" - page 2

 
bobozel1 #:

Forum on trading, automated trading systems and testing trading strategies

Any questions of beginners on MQL4 and MQL5, help and discussion on algorithms and codes

Aleksey Vyazmikin, 2024.06.18 06:28 pm

#define FileName  "correlation.csv"
//+------------------------------------------------------------------+
//| Внешние параметры                                                |
//+------------------------------------------------------------------+
input datetime Start = D'2015.01.01 00:00:00';  // Начало периода
input datetime End = D'2020.12.31 23:59:00';    // Конец периода
//--- Открываем файл для записи данных
   int handle = FileOpen(FileName, FILE_WRITE | FILE_CSV | FILE_ANSI, "\t", CP_UTF8);
   if(handle == INVALID_HANDLE)
     {
      PrintFormat("Error of open file %s: %d", FileName, GetLastError());
      return;
     }
FileOpen

Parameters

open_flags

[in] combination of flags defining the mode of working with the file. The flags are defined as follows:
FILE_READ file opens for reading
FILE_WRITEfile opens for writing
FILE_BINbinary read-write mode (no conversion from and to string)
FILE_CSVfile of type csv (all written elements are converted to strings of the appropriate type, unicode or ansi, and separated by a delimiter)
FILE_TXTplain text file (same csv, but separator is not taken into account)
FILE_ANSIstrings of ANSI type (single-byte characters)
FILE_UNICODEstrings of UNICODE type (double-byte characters)
FILE_SHARE_READshared read access by several programs
FILE_SHARE_WRITEshared write access by several programs
FILE_COMMONfile location in the common folder of all client terminals \Terminal\Common\Files.

FileOpen

Note

For security reasons, work with files is strictly controlled in MQL5 language. Files, which are used for file operations using MQL5 language tools, cannot be located outside the file "sandbox".

If a file needs to be read in a certain encoding (the codepage parameter with the codepage value is specified), the FILE_ANSI flag must be set. Without specifying the FILE_ANSI flag, the text file will be read in Unicode without any conversion.

Thefile is opened in the folder of the client terminal in the MQL5\Files subfolder (or the testing agent_agent\MQL5\Files directory in case of testing). If FILE_COMMON is specified among the flags, the file is opened in the common folder of all client terminals \Terminal\Common\Files.

You can open "named channels" according to the following rules:

  • The channel name is a string that must be of the form: "\\servername\pipe\pipename", where servername is the name of the server on the network and pipename is the name of the channel. If the channels are used on the same computer, the servername can be omitted, but a dot should be used instead: "\\.\pipe\pipename". The client that is trying to connect to the channel must know the name of the channel.
  • FileFlush() and FileSeek() must be called at the beginning of the file between successive operations of reading from the channel and writing to the channel.

In the above lines, the special backslash character '\' is used, so when writing the name in an MQL5 programme, '\' should be doubled, i.e. the above example should be written in the code as "\\\\servername\\pipe\\\pipename".

For more details on working with named channels, please read the article "Communication with MetaTrader 5 via Named Channels without DLL"


 
Aleksey Vyazmikin #

Honestly, I didn't understand anything from the answer, as if a robot was writing. I know where the file to be created is written to, but it is not created.

I have a specific question, how to take data from .hcc and .hc files to write to .csv?

Running the initial_data.mq5 script from the book as a result:

CopyClose is always -1. How to fix this?

I have a suspicion that it just doesn't see these files because the path to the data files is not spelled correctly.

How do I spell the path to the data files correctly?

In my case, the data files are in the terminal_directory\bases\MetaQuotes-Demo\history\EURUSD\ folder inside the sandbox.

I've been struggling with this for a week, I've read everything, but I haven't found a solution. Please help me.

 
bobozel1 #:

Honestly, I didn't understand anything from the answer, as if a robot was writing. I know where the file to be created is written, but it is not created.

I have a specific question, how to take data from .hcc and .hc files to write to .csv?

Running the initial_data.mq5 script from the book as a result:

CopyClose is always -1. How to fix this?

I have a suspicion that it just doesn't see these files, because the path to the data files is not spelled correctly.

How to correctly specify the path to the data files?

In my case, the data files are located in the terminal_terminal_directory\bases\MetaQuotes-Demo\history\EURUSD\ folder inside the sandbox.

I've been struggling with this for a week, I've read everything, but I haven't found a solution. Please help me.

All data are taken from the platform, the user does not care where the terminal gets them from - from what file.

The script works with the data that are reflected on the chart.

Check if there are dates on the chart for which you are requesting quotes.

 
Aleksey Vyazmikin #:

All data is taken from the platform, the user does not care where the terminal gets it from - from what file.

The script works with the data reflected on the chart.

Check if there are dates on the chart for which you are requesting quotes.

Please explain what it means.

In the script there is a range

input datetime Start = D'2015.01.01.01 00:00:00'; // Period beginning

input datetime End = D'2020.12.31 23:59:00'; // Period end

on M5

Should I take the EURUSD chart on M5, scroll to 2015.01.01 and then run the script on it?

Or can I run the script on MN ? And with new ticks it goes back to the beginning?
 
bobozel1 #:

Can you please explain what that means?

In the script there is a range

input datetime Start = D'2015.01.01.01 00:00:00'; // Period beginning

input datetime End = D'2020.12.31 23:59:00'; // Period end

on M5

Should I take the EURUSD chart on M5, scroll to 2015.01.01 and then run the script on it?

Or can I run the script on MN ? And with new ticks it goes back to the beginning?

Read the help on the terminal. And here's another thing.

You will find out that there is a setting of history depth through the maximum number of bars in the window. You need to reload the terminal for the changes to take effect.

Thus, it is necessary to set the maximum depth of history for all TFs at once by the smallest TF that is required for work.

It is clear that 100 bars for days and 100 bars for minutes will give the same depth in bars, but not in dates.

When you set the required value or "Unlimited" and reload the terminal, if the history is available for the required period, you can run the script on the monthly TF.


 
Aleksey Vyazmikin #:

Read the terminal help. And here's another.

You will learn that there is a setting of history depth through the maximum number of bars in the window. For changes to take effect, you need to reload the terminal.

Thus, it is necessary to set the maximum depth of history for all TFs at once by the smallest TF, which is required for work.

It is clear that 100 bars for days and 100 bars for minutes will give the same depth in bars, but not in dates.

When you set the required value or "Unlimited" and reload the terminal, if the history is available for the required period, you can run the script on the monthly TF.


Thank you! Everything worked.
 
bobozel1 #:
Thank you! It worked.

You're welcome.

 

Thank you  Dmitry for all your efforts in this book. It is really useful. 

In neuronbase.mqh you implement the ElasticNet Regularization method as below without explanation in your book. 

m_cWeights.m_mMatrix -= m_cWeights.m_mMatrix * Lambda[1] + Lambda[0]

But it is different from the basic formula (+) or from the Keras source code (+) for example.  

Please explain about your implementation method. Why you just use lambdas instead of the complete formula and why you multiply weights with one of them and sum with another one. 

Dmitriy Gizlyk
Dmitriy Gizlyk
  • 2024.07.15
  • www.mql5.com
Trader's profile
 

From which script do I generate this study_data_not_norm.csv ? I tried create_initial data´s script but it didn´t work. I got range out of bounds when running the gpt_test_not_norm.mq5 script.



 

Dear Administrators,

Thank you so much for the opportunity to learn in such a unique field!

I would like to come back to the previous posts regarding error 5008.


I also failed to load the strategy tester for the trained model gpt_not_norm.net with error 5008, the model file is not loaded.

At the same time, when running on a chart, the robot behaves correctly, the model file picks up adequate values after a direct pass, I displayed them on the chart, all is well.

The model file, as it should be, is located in the directory according to the True flag for Common \Terminal\Common\Files .

Moreover, when I ran the same thing on another comp, on my laptop, the strategy tester started without error.

Could it be some system settings that prevent the Strategy Tester from working?

1.Strategy Tester does not work on a computer with

Intel Core i5-9400F 2.90GHz processor , 16295 MB

Windows 10 home.

2.Strategy Tester works on a laptop with

Intel Core i7-2760QM 2 .40GHz processor , 12238 MB

Windows 10 Pro.

Please help me to solve this problem.

I really need to engage the comp, it has a video card on it and is faster for sure.