Questions from Beginners MQL5 MT5 MetaTrader 5 - page 775

 
Vladimir Karputov:

It says: "... Step 1 ...".

On step 2 - now think for yourself, namely, how multiple threads WITHOUT CONFLICT can write to ONE file.


That's the thing, they can't...

I take it that network agents cannot work with dll libraries?


Is there any way to find out the pass number of the tester? To be able to glue the files together...

 
Aleksey Vyazmikin:

How can agents be taught to write to the same file? Right now everyone creates their own file in their own folder, which is not good.

To write Agents' data to the same file you must use Frame mode.

// Пример записи данных Агентов (включая Облачные) в один файл
input int Range = 0;

void OnTick()
{
// ....
}

// Файл открываем только в режимах одиночночного прогона или Фрейма.
const int handle = ((MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_OPTIMIZATION)) || MQLInfoInteger(MQL_FRAME_MODE)) ?
                   FileOpen(__FILE__, FILE_WRITE | FILE_TXT) : INVALID_HANDLE;

// Подготовка данных
void GetData( string &Str, MqlTick &Ticks[], double &Balance )
{
  Str = "Hello World!";
  
  CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 2); // Последние два тика (пример)
  
  Balance = AccountInfoDouble(ACCOUNT_BALANCE);
}

// Запись данных
void SaveData( const string &Str, const MqlTick &Ticks[], const double Balance )
{
  FileWrite(handle, Str);
  
  for (int i = 0; i < ArraySize(Ticks); i++)
    FileWrite(handle, Ticks[i].bid);
    
  FileWrite(handle, Balance);
}

void OnTesterDeinit()
{
  if (handle != INVALID_HANDLE)  
    FileClose(handle);
    
  ChartClose();
}

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

double OnTester()
{
  string Str;
  MqlTick Ticks[];
  double Balance;
  
  GetData(Str, Ticks, Balance); // Подготовка данных для записи

  if (MQLInfoInteger(MQL_OPTIMIZATION)) // Оптимизация
  {
    CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205
    
    Container[0] = Str;
    Container[1] = Ticks;
    Container[2] = Balance;
  
    FrameAdd(NULL, 0, 0, Container.Data); // Отправили данные из Агента на Терминал
  }
  else // Одиночный прогон
  {    
    if (handle != INVALID_HANDLE)
      SaveData(Str, Ticks, Balance); // Данные будут записаны в MQL5\Files-папку Агента (не Терминала)
    
    FileClose(handle);
  }
  
  return(0);
}

void OnTesterPass()
{    
  if (handle != INVALID_HANDLE)
  {
    ulong Pass;
    string Name;
    long ID;
    double Value;
  
    CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205
  
    while (FrameNext(Pass, Name, ID, Value, Container.Data))
    {
      string Str;
      MqlTick Ticks[];
      double Balance;
      
      // Получили данные от Агента
      Container[0].Get(Str);
      Container[1].Get(Ticks);
      Container[2].Get(Balance);
      
//      FileWrite(handle, Pass);     // Если хочется записать номер прохода
      SaveData(Str, Ticks, Balance); // Данные будут записаны в MQL5\Files-папку Терминала (не Агента)
    }
  }
}
 
fxsaber:

You need to use Frame mode to write the Agents data to a single file.


Thank you! I'll have to look into it.

What is "Frame mode"?

 
Aleksey Vyazmikin:

What is 'Frame Mode'?

https://www.mql5.com/ru/docs/optimization_frames

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

Thank you - what is the mode understood.

However, I don't understand, is it possible to pass 100 indicators in a batch in this frame? Why in one frame - since each frame is considered as a separate pass, as I understood from the description, or did I misunderstand?

And where can I find the description of the*.mqd file format?

 
Aleksey Vyazmikin:

However, I don't understand, is it possible to pass 100 indicators in this frame in a batch?

Look at the example above. Any amount of arbitrary data can be transmitted there.

 
fxsaber:

Look at the example above. It transmits arbitrary data in any quantity.


Many questions, let me ask you?

Here is the function in the code

// Подготовка данных
void GetData( string &Str, MqlTick &Ticks[], double &Balance )
{
  Str = "Hello World!";
  
  CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 2); // Последние два тика (пример)
  
  Balance = AccountInfoDouble(ACCOUNT_BALANCE);
}

The meaning is clear - we are collecting data to be written later.

I'm not quite sure why we're declaring variables in brackets and what "&" sign before a variable means?

 
Aleksey Vyazmikin:

Lots of questions, let me ask you?

Here is the function in the code

The meaning is clear - we are collecting data to be written later.

I'm not quite sure why we're declaring variables in brackets and what "&" sign before a variable means?

This is basics. Read in help about formal function parameters and passing parameters by reference.
 
Aleksey Vyazmikin:

Lots of questions, let me ask you?

Here is the function in the code

The meaning is clear - we are collecting data to be written later.

I do not quite understand why we need to declare variables in brackets and what "&" sign before the variable means?

From the documentation


It is possible to pass parameters of simple types by reference. In this case, modification of such parameters within a called function will affect the corresponding variables passed by reference. In order to specify that a parameter is passed by reference, a modifier "&" must be placed after the data type.

Example:

void func(int& x, double& y, double & z[])
  {
   double calculated_tp;
   ...
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(i==ArraySize(z))       break;
      if(OrderSelect(i)==false) break;
      z[i]=OrderOpenPrice();
     }
   x=i;
   y=calculated_tp;
Документация по MQL5: Основы языка / Переменные / Формальные параметры
Документация по MQL5: Основы языка / Переменные / Формальные параметры
  • www.mql5.com
Основы языка / Переменные / Формальные параметры - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin:
It's basics. Read in the help about formal function parameters and passing parameters by reference.

Maybe the basics, no arguments, I just can't get into the code, where it starts, where it ends... hence the questions. Ok it's a reference(?), but to what?

Where did the"Str" variable originally originate here?

    while (FrameNext(Pass, Name, ID, Value, Container.Data))
    {
      string Str;
      MqlTick Ticks[];
      double Balance;
      
      // Получили данные от Агента
      Container[0].Get(Str);
      Container[1].Get(Ticks);
      Container[2].Get(Balance);
      
//      FileWrite(handle, Pass);     // Если хочется записать номер прохода
      SaveData(Str, Ticks, Balance); // Данные будут записаны в MQL5\Files-папку Терминала (не Агента)
    }
Reason: