To whom it may concern, I stumbled upon strange MQL5VPS behaviour when working with #property tester_file and MQL5VPS.
Here a test code:
//+------------------------------------------------------------------+//| MQL5VPS_strange.mq5 |//| Copyright 2023, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2023, MetaQuotes Ltd."#property link"https://www.mql5.com"#property version"1.00"#property tester_file"VPS1.txt"#property tester_file"VPS2.txt"#property tester_file"VPS3.txt"#property tester_file"VPS4.txt"//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+enum enum_VPS
{
VPS1,//VPS1.txt
VPS2,//VPS2.txt
VPS3,//VPS3.txt
VPS4,//VPS4.txt
};
string lines[];
int countVPS = 0;
int countTerminal = 0;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+input enum_VPS FileUsed;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---//FileDelete(EnumToString(FileUsed)+".txt"); FileCopy(EnumToString(FileUsed)+".txt",FILE_COMMON,EnumToString(FileUsed)+".txt",FILE_REWRITE);
ReadFileToArrayAgent(EnumToString(FileUsed)+".txt",lines);
Comment(EnumToString(FileUsed)+".txt" + " " + (string)ArraySize(lines));
Print("Lines in file " + EnumToString(FileUsed) + " " + (string)ArraySize(lines));
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---if(countVPS==0)
{
if(TerminalInfoInteger(TERMINAL_VPS))
{
SendNotification("Hello from VPS; lines in file " + EnumToString(FileUsed) + " " + (string)ArraySize(lines));
ArrayPrint(lines);
countVPS++;
}
}
if(countTerminal==0)
{
if(!TerminalInfoInteger(TERMINAL_VPS))
{
SendNotification("Hello from Terminal; lines in file " + EnumToString(FileUsed) + " " + (string)ArraySize(lines));
ArrayPrint(lines);
countTerminal++;
}
}
}
//+------------------------------------------------------------------+//| Read file to array |//+------------------------------------------------------------------+bool ReadFileToArrayAgent(string FileName,string & Lines[])
{
ResetLastError();
int h=FileOpen(FileName,FILE_READ|FILE_TXT,"\r\n");
if(h==INVALID_HANDLE){
int ErrNum=GetLastError();
printf("ReadFileToArrayAgent Error opening file %s # %i",FileName,ErrNum);
return(false);
}
int cnt=0; // use the variable to count the number of file lineswhile(!FileIsEnding(h)){
string str=FileReadString(h); // read the next line from the file// remove spaces to the left and to the right to detect and avoid using empty linesStringTrimLeft(str);
StringTrimRight(str);
if(str!="" && str!="0-"){
if(cnt>=ArraySize(Lines)){ // array filled completelyArrayResize(Lines,ArraySize(Lines)+1024); // increase the array size by 1024 elements
}
Lines[cnt]=str; // send the read line to the array
cnt++; // increase the counter of read lines
}
}
ArrayResize(Lines,cnt);
FileClose(h);
return(true);
}
test files belong in Common\Files VPS1.txt contains 1 line, VPS2.txt 2 lines, VPS2.txt 3 lines, VPS2.txt 4 lines.
Here a screenshot of the recieved notification after synchronizing MQL5 VPS with 4 charts, each using one of the vps.txt files:
The last line means that VPS2.txt has 4 lines (although it only contains 2).
Here the printout:
Here you can see the terminal reads out the vps2.txt correctly. But the vps terminal confuses vps2.txt with vps4.txt apperently. With another EA, I face a similar problem, but there most of the time only the file of one chart is read, others claim 0 lines.
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.
I stumbled upon strange MQL5VPS behaviour when working with #property tester_file and MQL5VPS.
Here a test code:
test files belong in Common\Files
VPS1.txt contains 1 line,
VPS2.txt 2 lines,
VPS2.txt 3 lines,
VPS2.txt 4 lines.
Here a screenshot of the recieved notification after synchronizing MQL5 VPS with 4 charts, each using one of the vps.txt files:

The last line means that VPS2.txt has 4 lines (although it only contains 2).

Here the printout:
Here you can see the terminal reads out the vps2.txt correctly. But the vps terminal confuses vps2.txt with vps4.txt apperently.
With another EA, I face a similar problem, but there most of the time only the file of one chart is read, others claim 0 lines.
Thanks for any help in advance.