Good afternoon
How do I write the optimization results to a file when using Local Network Farm or MQL5 Cloud Network ?
There is a procedure in OnTester (void) that uses:
string toWrite = "test";
When using Local agents, the file with the optimization results is created in a shared folder; when using Local Network Farm or MQL5 Cloud Network, there is no file.
fileHandle=FileOpen(fileName,FILE_CSV|FILE_READ|FILE_WRITE|FILE_ANSI|FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_COMMON,",");
FileWrite(fileHandle,toWrite);
FileClose(fileHandle);
fxsaber
Forum on trading, automated trading systems and testing of trading strategies
Questions from beginners MQL5 MT5 MetaTrader 5
fxsaber, 2017.08.23 14:10
To record data of Agents in a single file you need to use Frame mode.
// Example of writing agent data (including Cloud data) to a single file
input int Range = 0;
void OnTick()
{
// ....
}
/ / We open the file only in single-run or Frame modes.
const int handle = ((MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_OPTIMIZATION)) || MQLInfoInteger(MQL_FRAME_MODE)) ?
FileOpen(__FILE__, FILE_WRITE | FILE_TXT) : INVALID_HANDLE;
// Data preparation
void GetData( string &Str, MqlTick &Ticks[], double &Balance )
{
Str = "Hello World!";
CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 2); // The last two ticks (example)
Balance = AccountInfoDouble(ACCOUNT_BALANCE);
}
/ / Writing data
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 //
double OnTester()
{
string Str;
MqlTick Ticks[];
double Balance;
GetData(Str, Ticks, Balance); // Preparing data for recording
if (MQLInfoInteger(MQL_OPTIMIZATION)) // Optimization of
{ CONTAINER
<uchar> Container; //
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); / / Data will be written to the Agent's (not terminal's) MQL5Files folder)
FileClose(handle);
}
return(0);
}
void OnTesterPass()
{
if (handle != INVALID_HANDLE)
{
ulong Pass;
string Name;
long ID;
double Value;
CONTAINER<uchar> Container; //
while (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 record the pass number
SaveData(Str, Ticks, Balance); / / the Data will be written to The mql5files folder of the Terminal (not the Agent)
}
}
}
-aleks-
Uh, sorry for the stupid question, but what is “18 stepnen”? How much is it in numbers – I’m stupid. Or is it about the number of variables?
nexxtor
I refused frames for the reason that when the number of options is more than 18 steps, they did not work.
as a result, I put an entry in the file in the OnTester procedure
@Aleksey Vyazmikin, can you check if the frames will work if the number of options is greater than 18 degrees? maybe they’ve already fixed it…
komposter
Oh, there is no fxsaber, and he would immediately give an answer.
Dig in the direction of frames, all data from agents can be obtained.
alexx_v
no one will give You the opportunity to record anything on someone else’s remote machines, I think You would also be against having something start recording somewhere on your PC, then (probably) download it to your PC, etc.
P. S.: check out this library, maybe it will give you some ideas on how to implement what you want
nexxtor
any ideas?