Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1358

 

Hello!

Maybe there's someone "in the know"... I'm looking for a solution to convert a ZIP-file byte-sequence obtained using WebRequest into a ZIP-archive and unpack it to disk using MQL5 tools.

The search for a solution led me to the article "Handling ZIP archives using MQL5 tools without third-party libraries" published in 2015 ( https://www.mql5.com/ru/articles/1971 ). Here the author showed the solution and published CZip class for working with ZIP archives. However, I cannot apply this solution - when compiling, MetaEditor cannot build the executable file, citing errors in the CZip class library.

The essence of my question can be reduced to the following: - How can I separately use methods of CZip class, in particular CreateFromCharArray() and UnpackZipArchive(), by including them directly in the script code?

//+------------------------------------------------------------------+
//|                                                     ZipTask2.mq5 |
//|                                 Copyright 2015, Vasiliy Sokolov. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Vasiliy Sokolov."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Zip\Zip.mqh>

CZip Zip;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string cookie,headers;
   string mql_url="https://www.mql5.com/ru/code/download/9";
   int timeout=5000;
   uchar data[],zip_array[];
   if(!WebRequest("GET",mql_url,cookie,NULL,timeout,data,0,zip_array,headers))
     {
      printf("Unable to download ZIP archive from "+mql_url+". Check request and permissions EA.");
      return;
     }
   if(!Zip.CreateFromCharArray(zip_array))
     {
      printf("Loaded bad ZIP archive. Check results array.");
      return;
     }
   printf("Archive successfully loaded. Total files: "+(string)Zip.TotalElements());
   Zip.UnpackZipArchive("Alligator",FILE_COMMON);
  }
//+------------------------------------------------------------------+
Работаем с ZIP-архивами средствами MQL5 без использования сторонних библиотек
Работаем с ZIP-архивами средствами MQL5 без использования сторонних библиотек
  • www.mql5.com
Язык MQL5 развивается, и в него постоянно добавляются новые функции для работы с данными. С некоторых пор, благодаря нововведениям, стало возможно работать с ZIP-архивами штатными средствами MQL5 без привлечения сторонних библиотек DLL. Данная статья подробно описывает, как это делается, на примере описания класса CZip — универсального инструмента для чтения, создания и модификации ZIP-архивов.
 
Let me repeat my question.
There is a service which periodically creates files (I close everything correctly via FileClose).
After start usually first file is created normally, then FileOpen starts returning error 5001.
But all this is random - then works, then not. At the same time, I never noticed the problem when I run the same code in a script or Expert Advisor.
How to circumvent this ban?
 
Evgeny Dyuka #:
Let me repeat my question.
There is a service that periodically creates files (I close everything correctly via FileClose).
After startup first file is ok, and then FileOpen will give me error 5001.
But it's random - sometimes works, sometimes not. At the same time, I never noticed the problem when I run the same code in a script or Expert Advisor.
How to circumvent this ban?

Do you want someone to write a similar service with the same bugs as yours and tell you what needs to be fixed?

 
Alexey Viktorov #:

Do you want someone to write a similar service with the same bugs as yours and tell you what needs to be fixed?

Started to cut out lishee to post the code and everything worked ))
In the file search function, the search was not closing via FileFindClose().
Anyway, thanks for the reply.
 
Evgeny Dyuka #:
Started to cut out the lishee to post the code and everything worked ))
In the file search function, the search was not closed via FileFindClose().
Anyway, thanks for the reply.

Yes, anything that uses a file opens it (opens access to the file) ))) And closing the file (access) is required.

Closing a file unnecessarily will return -1 with no consequences, but a forgotten open file can cause a lot of problems)

 

Remind me in the input block can the comment not appear in the robot's parameters?

sinput long   MagicNumber=123;      // Магический номер

so that the parameters will still show MagicNumber instead of MagicNumber (this is an example)

 
Fast235 #:

Remind me in the input block can the comment not appear in the robot's parameters?

so that the parameters still show MagicNumber instead of MagicNumber (this is an example)

'sinput' outputs the parameter, but you can't include it in the optimisation.

Variables with sinput modifier#

Variableswith input modifierallow not only setting external parameters values when launching programs but are also necessary when optimizing trading strategies in the tester. Every input variable declared in the Expert Advisor, except for the string type, can take part in optimization.

Sometimes, it is necessary to exclude some external program parameters from the area of all passes in the tester. There is a memory modifiersinputspecifically for such cases. sinput is a shortened form of declaration of a static external variable: sinput = static input. That is, such a declaration in the EA code

sinput       int layers=6;   // Количество слоев

will be equivalent to a full declaration

static input int layers=6;   // Количество слоев

A variable declared with sinput modifier is an input parameter of an MQL5 program. The value of this parameter can be changed when launching the program. But this variable doesn't take part in the process of optimization of input parameters, i.e. its values are not searched when searching for the best set of parameters by the given criterion.

sinput

The picture shows that the Expert Advisor has 5 external parameters of which the "Number of Layers" parameter has been declared assinputand is equal to 6. This parameter cannot be changed in the trade strategy optimization procedure but the required value can be set for it to be used. Start, Step and Stop fields are not available for setting values for such a variable.

Thus, by setting the sinput modifier for a variable, we prohibit a user from optimizing this parameter. It means that in the strategy tester, a user of the terminal cannot set start and stop values for it for the automatic enumeration within the specified range during the optimization process.

However, there is one exception to this rule - sinput variables can be varied in optimization tasks usingParameterSetRange() function. This function has been developed specifically to programmatically control the range of available values for anyinput variable includingthe ones declared asstatic input(sinput). Another function,ParameterGetRange(), allows to receive input variables values when optimization is launched (inOnTesterInit() handler) and, if necessary, redefine a change step and a range within which an optimized parameter values will be enumerated.

Thus, the combination of the sinput modifier and two functions for handling input variables allows to create flexible rules for defining optimization intervals of some input variables depending on values of other input variables.

Документация по MQL5: Основы языка / Переменные / Input переменные
Документация по MQL5: Основы языка / Переменные / Input переменные
  • www.mql5.com
Input переменные - Переменные - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

sinput I remember, the question is about displaying a comment, is it possible to display the variable name instead of a comment, in EA parameters?

ps the string with sinput was just an example)

 
Fast235 #:

sinput I remember, the question is in the comment display, can the variable name be displayed instead of the comment, in the EA parameters?

ps sinput line just happened to be an example)

Just do not write anything after ';'

Example - there is a description:

input group    "Buy Saucer"
input uchar       InpBuySaucerCode     = 174;   // Buy Saucer: Arrow code (font Wingdings)

and now remove the description:

input group    "Buy Saucer"
input uchar       InpBuySaucerCode     = 174;    


and we'll see the name of the variable

 

Just don't write anything after ';'

That was the question, the comment is there, but the variable name needs to be output in the parameters,

maybe there's a trick to it....

Reason: