Request Audit: Analyze EA Trade Requests in the Tester
Info
The Request Audit: Analyze EA Trade Requests in the Tester is a Expert Advisor for MetaTrader 5 that what it doesthis tool identifies and reports trade requests from expert advisors (eas) within the metatrader strategy tester that would typically be rejected by the market or brokers. These rejections can occur due to various reasons, such as incorrect volume, stop loss levels violating freeze levels, or lot sizes exceeding free margin.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Request Audit: Analyze EA Trade Requests in the Tester
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
What it doesThis tool identifies and reports trade requests from Expert Advisors (EAs) within the MetaTrader Strategy Tester that would typically be rejected by the market or brokers.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: Trade-Request Matrix: Regression Testing Invalid Order Parameters with OrderCheck() - another powerful expert for MetaTrader 5 traders.
What it doesAlso recommended: Real-Time World Index Quotes via WebRequest - similar expert with strong performance on MetaTrader 5.
This tool identifies and reports trade requests from Expert Advisors (EAs) within the MetaTrader Strategy Tester that would typically be rejected by the market or brokers. These rejections can occur due to various reasons, such as incorrect volume, stop loss levels violating freeze levels, or lot sizes exceeding free margin. In the Strategy Tester, these invalid requests fail with a return code in the log, but the specific line of EA code causing the issue is not always apparent. RequestAudit intercepts each outgoing request, checks it against predefined rules, and records any violations. The EA's trade request remains unchanged and is sent to the server as intended, with the server responding as usual.
The library integrates using three macros. After including "RequestAudit\RequestAudit.mqh" as the very first line of the EA, calls to OrderSend or OrderSendAsync are monitored along with their file and line numbers. Additionally, every CTrade object within the EA is transformed into a CAuditTrade object. This wrapper checks requests made through all CTrade methods, including Buy, Sell, PositionModify, PositionClose, OrderOpen, OrderModify, OrderDelete, and others. A call like trade.OrderSend(request, result) is examined, including its associated file and line. This also applies to EAs generated by the MQL5 Wizard, where CExpertTrade inherits from CTrade. Removing the include line restores the EA to its original compilation state.
Upon completion of the test run, the global object g_request_audit generates a report in the Journal. This report details the total number of requests checked, the number of requests that violated rules, and a summary for each rule and location, including the count, the timestamp of the first violation, and a description of the issue. A CSV file in the common Files folder provides a row-by-row record of each violation.
The test script, RequestAuditTest, examines 28 predefined cases using internally generated requests without sending them. The demo EA, RequestAuditDemo, sends ten specific requests in the Strategy Tester, with eight intentionally designed to be faulty, demonstrating the report's output.
Example report from RequestAudit in the tester journal after running the demo EA: eight faulty requests are listed with their respective rules, locations, and first occurrence timestamps.
Using RequestAudit
Include the RequestAudit library by adding the line #include
Optional settings can be configured within the OnInit function:
#include
#include
CTrade trade; // Your EA's CTrade object; with the above include, it becomes a CAuditTrade
int OnInit(void)
{
g_request_audit.SetCsv(true, "MyExpert_requests.csv"); // Specifies a custom file name in the common Files folder
g_request_audit.SetMaxRows(5000); // Sets the maximum number of violations to store in the CSV file
return INIT_SUCCEEDED;
}
void OnTick(void)
{
}
Run your EA in the Strategy Tester as usual. After the demo EA RequestAuditDemo completes its run (sending ten fixed requests on EURUSD H1, eight of which are intentionally faulty), the tester's journal will display output similar to this:
RequestAudit: 10 requests checked, 8 broke at least one rule, 8 violations
RequestAudit: VOLUME 1x, CTrade (no file and line), first at 2026.11.02 01:00:00: volume 0.015, min 0.01, max 500, step 0.01
RequestAudit: STOPS_LEVEL 1x, OrderSend in RequestAuditDemo.mq5 line 120, first at 2026.11.02 02:00:00: ORDER_TYPE_BUY_LIMIT at 1.11586, bid 1.11565, ask 1.11566, stops level 0
RequestAudit: STOPS_LEVEL 1x, CTrade.OrderSend in RequestAuditDemo.mq5 line 138, first at 2026.11.02 03:00:00: ORDER_TYPE_BUY_STOP at 1.11653, bid 1.11672, ask 1.11673, stops level 0
RequestAudit: NO_CHANGES 1x, CTrade (no file and line), first at 2026.11.02 05:00:00: sl 1.11203 and tp 1.12203 as before
RequestAudit: STOPS_LEVEL 1x, OrderSend in RequestAuditDemo.mq5 line 183, first at 2026.11.02 06:00:00: buy: sl 1.11726, tp 1.12203, bid 1.11706, ask 1.11707, stops level 0
RequestAudit: CLOSE_VOLUME 1x, OrderSend in RequestAuditDemo.mq5 line 201, first at 2026.11.02 07:00:00: close 0.02 of position volume 0.01
RequestAudit: MARGIN 1x, CTrade (no file and line), first at 2026.11.02 08:00:00: 500 lots need margin 559145.00, free margin 9990.01
RequestAudit: UNKNOWN_TICKET 1x, OrderSendAsync in RequestAuditDemo.mq5 line 215, first at 2026.11.02 09:00:00: position 999999 not found
RequestAudit: 8 violations written to RequestAudit_RequestAuditDemo_EURUSDp.csv in the common Files folder
The Rules
Each trade request is validated against the current symbol and account conditions at the time of submission. A specific rule is reported only once per request, although a single request may violate multiple rules. The level-related rules are based on the criteria outlined in the article "The checks a trading robot must pass before publication in the Market".
Rule
Requests
Reported when
UNKNOWN_TICKET
close, SLTP, CLOSE_BY, MODIFY, REMOVE
The specified position, opposite position, or pending order for the request is not open. No other rule is checked for this request.
TRADE_MODE
All
Trading is disabled for the symbol, or the request attempts to open a volume when the symbol is set to close-only, or attempts a sell when long-only is active, or a buy when short-only is active.
VOLUME
Deal, pending order
The requested volume is below the minimum, above the maximum, or not on the specified step for the symbol.
VOLUME_LIMIT
Deal, pending order that opens
The total volume of positions and pending orders in the same direction, including the current request, exceeds the SYMBOL_VOLUME_LIMIT.
CLOSE_VOLUME
Close by ticket, hedging
The volume to be closed exceeds the volume of the open position.
STOPS_LEVEL
Opening deal, pending order, SLTP, MODIFY
The price of a pending order, or the stop loss or take profit level, is too close to the current market price, violating the stops level. This also applies if the stop is on the wrong side of the price, or if a pending order has a price or limit price of 0.
FREEZE_LEVEL
SLTP, MODIFY
The current stop loss or take profit of an open position, or the current price of a pending order, falls within the freeze level range.
NO_CHANGES
SLTP, MODIFY
The request attempts to set stop loss or take profit levels that are identical to the current ones for the position or order.
MARGIN
Opening deal
OrderCalcMargin indicates that the required margin for the opening volume exceeds the available free margin.
ORDER_LIMIT
Pending order
The account has already reached the maximum allowed number of pending orders as defined by ACCOUNT_LIMIT_ORDERS.
Distances are measured in points. For open positions, distances are calculated relative to the closing price (Bid for sells, Ask for buys). A distance equal to the stops level is permissible; a distance equal to the freeze level is not. A stops level of 0 still necessitates that the stop order is placed on the correct side of the market price. The price for a buy limit is referenced from the Ask price, a sell limit from the Bid price. Buy stop and buy stop limit orders use the Ask price, while sell stop and sell stop limit orders use the Bid price. For pending orders, stop loss and take profit levels are measured from their open price or, for stop limit orders, from their limit price. New or modified pending orders require a valid price, and stop limit orders also need a valid limit price. The Strategy Tester rejects a price of 0 with error code 10015 (invalid price), even during modifications that only adjust stop levels. CTrade::OrderModify may send a limit price of 0 if the last argument is omitted. On netting accounts, closing a position partially opens only the volume exceeding the existing position; this excess volume is then checked for margin, volume limit, and levels. If the symbol's data cannot be read or lacks current quotes, the relevant checks are skipped. These skipped checks are counted as neither passing nor failing, but as checks that could not be performed. A single opening deal without a quote, for example, counts two checks: one for levels and one for margin.
The Report
The log entries generated by RequestAudit appear at the end of the Strategy Tester journal, originating from the g_request_audit destructor called after OnDeinit. Requests originating from CTrade methods are typically logged as "CTrade (no file and line)" or "CTrade async" because the CAuditTrade override does not inherently know the line number of the EA that invoked the method. If no trade requests are made, the report consists of a single line: "RequestAudit: no trade request was sent". During optimization runs, only the total summary line is displayed, and no CSV file is generated.
The CSV file, named RequestAudit_<program>_<symbol>.csv, is saved in the common Files folder of the MetaTrader terminal (accessible via File > Open Common Data Folder, then navigating to the Files folder). This file is overwritten after each run that involves at least one trade request, ensuring that only the results of the most recent run are present. The CSV columns include time, rule, source, file, line, action, type, symbol, volume, price, sl, tp, position, order, and detail. The 'Time' column reflects the server or tester time. Prices are formatted according to the symbol's digit settings, and any field containing a separator or quote character is enclosed in quotes.
Method or Macro
What it does
void SetPrint(print)
Controls whether the report is printed to the Journal (true by default) or suppressed.
void SetCsv(write, file_name)
Determines whether to write the CSV file (true by default). An empty file_name uses the default naming convention.
void SetMaxRows(max_rows)
Sets the maximum number of violations to be recorded in the CSV file. Violations exceeding this limit are counted and summarized in the report.
bool Report()
Manually triggers the printing of the report and writing of the CSV file. Returns false if the file could not be written. If called, the destructor will not generate another report.
void Totals(totals), bool GroupAt(index, group), bool RowAt(index, row)
Provides access to counters, journal groups, and CSV rows for EAs that need to evaluate this data programmatically.
RA_MAX_ROWS, RA_CSV_SEPARATOR
These preprocessor directives can be defined before the #include line to customize the maximum row limit (default 100000) or the CSV separator character (default ',').
The Test Script
RequestAuditTest generates simulated trade requests and market snapshots in memory and processes them through the same validation logic as the main audit tool, without actually sending any orders. It features two inputs:
Input
Default
Meaning
InpFileCase
true
If true, writes a test CSV file to the common Files folder, then reads it back and deletes it.
InpLiveCase
true
If true, reads the current chart symbol and account details from the terminal.
Case
What it checks
01
Valid buy and sell orders with stops; should not violate any rules.
02
VOLUME rule: Tests volumes below minimum, above maximum, or not conforming to the step; 0.07 is used as an example that conforms to the step.
03
STOPS_LEVEL for buy orders: Checks a 10-point distance from Bid (passes) and a 9-point distance (fails).
04
STOPS_LEVEL for sell orders: Checks a 10-point distance from Ask (passes) and a 9-point distance (fails).
05
STOPS_LEVEL with 0: Tests a stop placed exactly at the price (fails) versus one point away (passes).
06
MARGIN rule: Tests cases where the required margin exceeds free margin (fails), equals free margin (passes), and skips cases where required margin is unknown.
07
TRADE_MODE rule: Tests disabled trading, close-only mode, long-only mode, and short-only mode.
08
Hedging close: Tests CLOSE_VOLUME exceeding position size and UNKNOWN_TICKET for missing positions.
09
Netting account behavior: Tests how closes affect net positions and how reversals create excess volume.
10
STOPS_LEVEL for pending order prices: Tests limits and stops at 10 and 9 points away from the price.
11
STOPS_LEVEL for pending order stops: Measures stops relative to the order's open price.
12
STOPS_LEVEL for stop limit orders: Checks trigger price from Ask and stop levels from the limit price.
13
ORDER_LIMIT rule: Tests scenarios with 10 pending orders (fails) and 9 pending orders (passes); a limit price of 0 implies no limit.
14
VOLUME_LIMIT rule: Tests buy-side volume where 0.9 of 1.0 is allowed, a buy of 0.2 fails, and a sell of 0.2 passes.
15
SLTP validation: Checks for UNKNOWN_TICKET, NO_CHANGES, STOPS_LEVEL, and FREEZE_LEVEL violations.
16
MODIFY validation: Checks for UNKNOWN_TICKET, NO_CHANGES, STOPS_LEVEL, and FREEZE_LEVEL violations during order modification.
17
CLOSE_BY validation: Tests successful closes for both positions and UNKNOWN_TICKET for missing positions.
18
REMOVE validation: Tests successful removal of orders and checks for failures with missing orders.
19
Multiple rule violations: Ensures each rule violation is reported once and in the order defined.
20
Symbol data or quote issues: Verifies that checks are skipped and counted correctly when symbol data or quotes are unavailable.
21
Invalid symbol data: Tests scenarios where point value is 0 (failing stops level checks) and step value is 0 (failing volume checks).
22
Auditor functionality: Confirms that the auditor correctly counts requests and groups violations by rule and location.
23
Row limit enforcement: Tests that when the row limit is set to 2, only 2 violations are kept, and the 3rd violation is dropped.
24
CSV output: Validates that the CSV includes a header and one quoted row per violation, and that no file is written if no requests are made.
25
Helper functions: Tests the volume text formatting, CSV quoting, file naming, rule name retrieval, and location reporting.
26
Live data reading: Checks if the chart symbol and account details are read correctly; ensures the last error remains clear.
27
Hooking mechanism: Verifies that CTrade objects and pointers are correctly wrapped as CAuditTrade; confirms that no request was sent when expected.
28
STOPS_LEVEL with price 0 and stoplimit 0: Tests new orders and modifications of stop limit orders with zero prices.
The final line of a test script run, "RequestAudit: no trade request was sent", indicates that the script itself includes the audit hook, and its internal checks confirm that no external trade requests were executed. Three specific test cases were validated against the guarded code: case 05 fails when the stop level of 0 is treated as no limit; case 15 fails when a distance equal to the freeze level is allowed; and case 28 fails due to the absence of a check for a missing price.
The Demo EA
RequestAuditDemo is included in the download package and is designed to run exclusively within the Strategy Tester; it will halt execution in OnInit if run on a live chart. This EA has no inputs, signals, or defined strategy. On each new bar, it sends the next request from a predefined list of ten. It then logs whether the request was sent and the server's return code. After sending the tenth request, it sends no further requests. Two days of EURUSD H1 data with "1 minute OHLC" are sufficient for testing. The EA's first line is the include directive for RequestAudit; without this line, the EA functions identically, but the RequestAudit report is omitted.
Step 7's CLOSE_VOLUME check behaves differently on hedging accounts.
In the Strategy Tester
The demo EA was executed in the Strategy Tester of MetaTrader 5 build 6320 on a demo hedging account, using EURUSD H1 data with "1 minute OHLC" aggregation, and featuring a stops level of 0 and a freeze level of 0. The EA sends one request per bar: a 0.015 lot buy order, a buy limit order above the Ask price, a buy stop order below the Ask price, a valid buy order with stops, the same stops repeated, a stop loss order above the Bid price, a close order for double the position volume, a buy order with the maximum allowed volume, a stop order for a non-existent position using OrderSendAsync, and a valid close order. The server rejected the eight faulty requests with codes 10014, 10015, 10015, 10016, 10016, 10014, 10019, and 10013, respectively. RequestAudit logged each of these rejections, indicating the specific violated rule.
When run without the include line, the EA produced the same 36 lines of output in the journal, detailing messages from the EA and server responses. The only difference was the absence of the ten RequestAudit report lines.
How to Use RequestAudit
1. Installation:
- Copy the seven .mqh files into the MQL5\Include\RequestAudit\ directory.
- Place RequestAuditTest.mq5 into the MQL5\Scripts\RequestAudit\ directory.
- Place RequestAuditDemo.mq5 into the MQL5\Experts\RequestAudit\ directory.
- Compile the script and the demo EA.
2. Running the Test Script:
- Attach the RequestAuditTest script to any chart.
- It does not require trading permissions.
- The Experts tab in MetaTrader will display one line per test case, along with a summary.
3. Running the Demo EA:
- Launch RequestAuditDemo in the Strategy Tester. For example, use EURUSD H1 over two days with "1 minute OHLC" data.
- The RequestAudit report will appear at the end of the journal, as demonstrated previously.
4. Integrating with Your EA:
- Add the line #include
- Compile your EA and run it in the Strategy Tester.
- Review the report at the end of the journal and examine the generated CSV file in the common Files folder.
5. Removal:
- Remove the #include line before deploying your EA to a live trading account or any environment other than the tester.
- The audit functionality is intended for testing purposes; on a live chart, it will only report when the EA is removed.
Related Articles
The article "The checks a trading robot must pass before publication in the Market" (Article ID 2555) elaborates on the checks for volume, stops level, freeze level, and margin, providing code examples for each check that should be implemented within an EA before order submission. RequestAudit applies these same rules externally; it identifies the specific locations within an existing EA where a check is missing, reporting the file and line number without altering the EA's code. It does not correct requests; the necessary fixes must be implemented within the EA itself, and the referenced article provides guidance on how to do so.
Limitations
- Platform Support: MetaTrader 5 only.
- Scope of Audit: The audit tool monitors requests processed through OrderSend, OrderSendAsync, and CTrade methods. Requests originating from libraries (.ex5 files) or code compiled before the include line are not captured.
- Declaration Conflicts: EAs that declare their own functions or methods named OrderSend or OrderSendAsync (e.g., through class inheritance from CTrade) will not compile with the RequestAudit include line due to macro redefinitions. The same issue applies to include files that define their own OrderSend functions, such as MT4-style order functions.
- CTrade Method Data: Requests made via CTrade methods do not inherently provide file and line information. Use direct functions or ensure trade.OrderSend is called when precise line tracking is necessary.
- Unchecked Conditions: The audit does not check the tick size grid, the limit price of a stop limit order against its trigger price, or the freeze level when closing a position or removing a pending order. The CLOSE_VOLUME check is specifically applicable to hedging accounts only.
- Pending Order Modification: A MODIFY request for a pending order is checked based on its price, even if only the stop levels are being changed. If the market price has moved closer to the order's price than the stops level since the order was placed, the request will be flagged. The behavior of the server in accepting new stop levels under such conditions was not tested, as the demo account used had a stops level of 0.
- Margin Calculation: The MARGIN check utilizes OrderCalcMargin, which does not account for existing open positions. On an account utilizing hedged margin, a request that is accepted by the server might still be flagged by the audit. The free margin calculation is based on the margin available *before* the request is processed.
- Server-Side Limits: Brokers may enforce limits not reported by the terminal, such as floating stops levels. Consequently, a request that passes all RequestAudit checks might still be rejected by the server; the final server return code in the journal remains the definitive indicator.
- Object Selection and Last Error: The audit tool reads market data for each request and selects corresponding positions and orders. After processing, it re-selects the EA's position and order and attempts to clear the last error code if it was previously clear. MQL5 lacks a direct function to undo other state changes. If the EA had no objects selected initially, a position read by the audit might remain selected, and a last error code that the EA had not reset could be replaced by a different code.
- Optimization Path: The optimization process, which only generates a total summary line without detailed rows or a CSV file, is not covered by the test script.
You may also like: forex news events reaction ea: an mql5 calendar introduction - excellent alternative for expert users on MetaTrader 5.
Source Code
#property version "1.00"
#property script_show_inputs
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include <RequestAudit\AuditTestKit.mqh>
#define TEST_CSV_NAME "RequestAuditTest.csv"
#define TEST_UNKNOWN 5555
#define TEST_TIME D'2026.11.20 10:00'
input bool InpFileCase = true;
input bool InpLiveCase = true;
void Case01ValidDeals(void)
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.