The library prescribes a container class that stores variables and arrays of any other simple types in an array of a given type.
// Example of working with a container#include <TypeToBytes.mqh>
#define PRINT(A) Print(#A + " = " + (string)(A));
voidOnStart()
{
// Arbitrary data for the examplestring Str[] = {"123", "Hello World!"};
double Num = 5;
MqlTick Tick = {0};
Tick.bid = 1.23456;
CONTAINER<long> Container; // Create a container - everything will be stored in an array of a simple type (long is chosen in the example)// Fill the container with different data
Container[0] = Str;
Container[1] = Num;
Container[2] = Tick;
ArrayPrint(Container.Data); // Output the contents of the array in which the container stores all data// Print the types of data stored in the containerfor (int i = 0; i < Container.GetAmount(); i++)
PRINT(Container[i].GetType())
// Let's get the data itself string Str2[];
Container[0].Get(Str2); // Got the array
ArrayPrint(Str2);
PRINT(Container[1].Get<double>()) // We got a number
PRINT(Container[2].Get<MqlTick>().bid) // We got the structure
Container[1] = "Replace"; // Replaced data by index// Verify that the replacement has taken place
PRINT(Container[1].GetType())
PRINT(Container[1].Get<string>())
}
string Str;
REPORT::ToString(Str);
double Balance[];
REPORT::GetBalanceHistory(Balance);
#ifdef __TYPETOBYTES__
CONTAINER<uchar> Container;
Container[0] = Str; // put the report string in the container
Container[1] = Balance; // added a double array of the balance change history to the container as well
::FrameAdd(NULL, 0, ::AccountInfoDouble(ACCOUNT_BALANCE), Container.Data); // Sent a frame with string report and balance array#else // __TYPETOBYTES__
Receive a frame with different data
CONTAINER<uchar> Container;
while (::FrameNext(Pass, Name, ID, Value, Container.Data))
{
string Str;
Container[0].Get(Str); // Get the report string from the framedouble Balance[];
Container[1].Get(Balance); // Get the corresponding double array from the frame// .....
You need to use Frame Mode to write the Agents data into one file.
// Example of recording Agent data (including Cloud Agents) into one fileinputint Range = 0;
voidOnTick()
{
// ....
}
// Open the file only in Single Run or Frame modes.constint handle = ((MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_OPTIMIZATION)) || MQLInfoInteger(MQL_FRAME_MODE)) ?
FileOpen(__FILE__, FILE_WRITE | FILE_TXT) : INVALID_HANDLE;
// Data preparationvoid GetData( string &Str, MqlTick &Ticks[], double &Balance )
{
Str = "Hello World!";
CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 2); // Last two ticks (example)
Balance = AccountInfoDouble(ACCOUNT_BALANCE);
}
// Writing datavoid SaveData( conststring &Str, constMqlTick &Ticks[], constdouble Balance )
{
FileWrite(handle, Str);
for (int i = 0; i < ArraySize(Ticks); i++)
FileWrite(handle, Ticks[i].bid);
FileWrite(handle, Balance);
}
voidOnTesterDeinit()
{
if (handle != INVALID_HANDLE)
FileClose(handle);
ChartClose();
}
#include <TypeToBytes.mqh> // https://www.mql5.com/en/code/16280doubleOnTester()
{
string Str;
MqlTick Ticks[];
double Balance;
GetData(Str, Ticks, Balance); // Preparing data for recordingif (MQLInfoInteger(MQL_OPTIMIZATION)) // Optimisation
{
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); // Sent data from the Agent to the Terminal
}
else// Single run
{
if (handle != INVALID_HANDLE)
SaveData(Str, Ticks, Balance); // The data will be written to the MQL5\Files folder of the Agent (not the Terminal)FileClose(handle);
}
return(0);
}
voidOnTesterPass()
{
if (handle != INVALID_HANDLE)
{
ulong Pass;
string Name;
long ID;
double Value;
CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205while (FrameNext(Pass, Name, ID, Value, Container.Data))
{
string Str;
MqlTick Ticks[];
double Balance;
// Received data from the Agent
Container[0].Get(Str);
Container[1].Get(Ticks);
Container[2].Get(Balance);
// FileWrite(handle, Pass); // If you want to write the number of the passage
SaveData(Str, Ticks, Balance); // The data will be written to the MQL5\Files folder of the Terminal (not the Agent)
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Two lines with the same result
The library contains a container class that stores variables and arrays of any other simple types in an array of a given type.
Example of practical application in Report-bible
Send a frame with different data
Receive a frame with different data
Forum on trading, automated trading systems and testing trading strategies
Questions from MQL5 MT5 MetaTrader 5 beginners
fxsaber, 2017.08.23 14:10
You need to use Frame Mode to write the Agents data into one file.
Forum on trading, automated trading systems and testing trading strategies
New version of MetaTrader 5 build 1640: creating and testing your own financial instruments
fxsaber, 2017.10.10 07:51
Forum on trading, automated trading systems and testing trading strategies
Beta version of MetaTrader 5 build 1995: Economic Calendar, MQL5 programs as services and API for R language
fxsaber, 2019.02.18 16:36
Hi. So it's working.
This is how it works.
I got it from here for MT4
https://www.mql5.com/ru/forum/5905/page11#comment_6134460It's like that.