Persistent MQL5 Compilation Errors: HistoryDeals.mqh Not Found / Ambiguous Calls / Undeclared Identifiers - After Multiple Reinstalls

 

Dear MQL5.community,

I am experiencing extremely frustrating and persistent compilation errors with my Expert Advisor (EA) in MetaEditor, and I've exhausted all standard troubleshooting steps. I'm hoping someone can provide insight into what might be a deeper issue with my MetaTrader 5 installation or compiler environment.

Problem Summary: I have a grid martingale EA (code provided below) that compiles perfectly fine in its very basic version (which only uses Trade.mqh ). However, when I add features that require the HistoryDeals.mqh standard library (like detecting TP hits via OnTradeTransaction and managing pending orders based on deal history), the EA fails to compile with a cascade of errors.

Specific Errors I'm Receiving (examples from my compiler log):

  • file 'C:\Users\...\MQL5\Include\History\HistoryDeals.mqh' not found (This is the root error, even after manual checks.)

  • 'MqlDeal' - undeclared identifier

  • 'HistoryDealGetStruct' - undeclared identifier

  • 'DealGetInteger' - undeclared identifier (and similar for DealGetString , DealGetDouble , DEAL_TICKET , etc.)

  • ambiguous call to overloaded function with the same parameters (e.g., for HistoryDealsTotal() or HistoryDealSelect() )

  • ')' - expression expected (often a cascade from earlier errors)

  • unknown symbol ' ' and unrecognized character escape sequence` (These appeared during attempts to embed the code directly, indicating potential corruption during copy/paste).

EA Version and Features Causing Problems: The EA is version "1.33" (as per the provided code). The features that rely on HistoryDeals.mqh and cause these errors are:

  1. Detecting Take Profit (TP) hits using OnTradeTransaction and MqlDeal to cancel relevant pending orders.

  2. TP synchronization for the entire grid based on the last opened order's price (this part of the logic is in AttachAndSyncTP ).

  3. Drawdown stop functionality (which needs deal history to close positions).

Troubleshooting Steps I Have Already Taken (and their outcomes):

  1. Multiple Clean Reinstallations of MetaTrader 5:

    • Completely uninstalled MT5 via Control Panel.

    • Manually deleted all leftover folders in C:\Program Files , C:\Users\YourUsername\AppData\Roaming\MetaQuotes\Terminal\ , and C:\Users\YourUsername\AppData\Local\MetaQuotes\Terminal\ .

    • Downloaded fresh MT5 installers directly from mql5.com.

    • Ran installers as administrator.

    • Outcome: The errors persist. The HistoryDeals.mqh file is either still missing from MQL5\Include\History after a fresh install, or if I manually place it there, the "ambiguous call" and "undeclared identifier" errors appear, suggesting a conflict or deeper corruption in how MT5 loads its standard library.

  2. Manual Verification and Placement of HistoryDeals.mqh :

    • Checked MQL5\Include\History\ folder. It was often missing or empty.

    • Downloaded HistoryDeals.mqh directly from MetaQuotes GitHub.

    • Manually placed HistoryDeals.mqh into MQL5\Include\History\ .

    • Outcome: When HistoryDeals.mqh is present, I get the "ambiguous call" and "undeclared identifier" errors for DealGetInteger and other core functions, indicating a conflict with built-in definitions.

  3. Trying on Different Computers:

    • Attempted to compile the same code on another computer.

    • Outcome: Experienced similar, though not identical, compilation errors, suggesting the issue might follow the code or my specific MT5 environment setup.

  4. Testing Basic EA:

    • Confirmed that a simple EA (without #include <History\HistoryDeals.mqh> or OnTradeTransaction ) compiles and runs without any issues.

    • Outcome: This confirms the basic MT5 installation can compile simple code, but struggles with standard library includes.

My Request for Help: I am at a loss. It seems my MetaTrader 5 compiler is fundamentally unable to correctly integrate or recognize its own standard library files, particularly those related to deal history.

Could this be:

  • A specific build issue with MT5?

  • A conflict with my operating system or security software (even after temporary disabling)?

  • A deeper corruption in the MT5 installation that even clean uninstalls don't fully remove?

  • Is there a specific version of HistoryDeals.mqh I should be using, or a different way to include it?

Any guidance on diagnosing this persistent environment issue or alternative methods to ensure the compiler correctly recognizes MqlDeal and DealGetInteger would be immensely appreciated.

Thank you for your time and assistance.