MT5 EA FileFindFirst() fails to detect .flag file despite correct path and presence

 
I'm developing an MT5 EA that uses FileFindFirst("*.flag", ..., FILE_COMMON) to detect signal files generated by Python. These files are saved in the shared folder:

C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\Common\Files\signals\

The EA is configured like this:

- The SymbolPrefix is "USDJPY"
- The expected file is named: signal_USDJPY.flag
- The file content is a simple JSON: { "_EOF": true }
- The EA scans the folder every second using OnTimer() and logs the scanning path
- The file is confirmed to exist in Windows Explorer at the correct path
- Python uses os.replace() to write the .flag file atomically with encoding="utf-8"
- Yet, MT5’s FileFindFirst("*.flag", ...) returns INVALID_HANDLE
- No "🔍 Found file:" log appears in the EA

**Things I’ve confirmed:**
- The folder is correct (TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\Files\\signals")
- The file name matches exactly: signal_USDJPY.flag
- The file is NOT hidden, NOT readonly (attrib check OK)
- FileIsExist() was also unreliable previously
- FileFindFirst("*.flag") logs absolutely nothing

**Question:**
1. Are there known limitations in MT5’s FileFindFirst() that prevent it from seeing short extensions like `.flag`?
2. Does MT5 treat *.flag as an extensionless file (like a Unix dotfile)?
3. Is there a reliable workaround to force MT5 to detect signal files created externally?
4. Would using a compound extension like `.trigger.json` increase detection reliability?
5. Could the issue relate to NTFS metadata or BOM headers in the file?

Any experience or workaround from the MT5 scripting community or other developers would be greatly appreciated.
 
Haccho1147:

I can only answer questions from an AI in the same way:

Main issue:

FileFindFirst("*.flag", ..., FILE_COMMON) does not detect .flag files created by Python, even though they exist.


🧠 Likely causes:

  1. Uncommon extensions like .flag are sometimes not properly detected by MT5.

  2. The file is created externally (via os.replace() ), and MT5 doesn’t refresh the shared filesystem view reliably.

  3. The FILE_COMMON folder is more sensitive to these timing issues or refresh delays.


Recommended solutions:

  1. Use a more standard extension like .json , .txt , or .trigger.json .

  2. Make sure the file has at least 1 byte of content (not empty).

  3. In Python, add a small delay (e.g., sleep(0.1) ) after os.replace() to let the OS fully register the file.

  4. Use FileIsExist(full_path) in MT5 as an extra check.

  5. As a fallback, try opening the file directly with FileOpen() to see if MT5 can read it.

Behave like a human, and you'll get a human response. 😉

 
Haccho1147:

C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\Common\Files\signals\

Any experience or workaround from the MT5 scripting community or other developers would be greatly appreciated.

#include <fxsaber\ThirdPartyTicks\File.mqh> // https://www.mql5.com/ru/code/20225

void OnStart()
{
  string FileNames[];
  
  if (FILE::GetFileNames(FileNames, "*.flag", FILE_COMMON))
    ArrayPrint(FileNames);
}


Result.

"signals\HelloWorld.flag"
 
Haccho1147: - The folder is correct (TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\Files\\signals") 
It is not correct. You are scanning C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\Common\Files\Files\signals\

common_flag

[in] Flag determining the location of the file. If common_flag = FILE_COMMON, then the file is located in a shared folder for all client terminals \Terminal\Common\Files. Otherwise, the file is located in a local folder.
          FileFindFirst - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5