Trade History Statistics for MT4/MT5
Info
The Trade History Statistics for MT4/MT5 is a Script for MetaTrader 5 that trade history stats analyzes your account history to provide a comprehensive overview of your trading performance. This tool is compatible with both manual trading and Expert Advisors (EAs), and offers filtering by symbol and magic number.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Script works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Scripts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Trade History Statistics for MT4/MT5
1. Installation: Move your script file into the MQL/Scripts directory and restart the platform.
2. Execution: Drag the script onto a chart; it will perform a one-time action, such as closing all open orders or clearing chart objects.
3. Editing: Use MetaEditor (F4) to modify code, click "Compile," and verify no errors appear in the terminal before running.
4. Removing: Scripts stop automatically, but you can remove them manually by right-clicking the chart and choosing "Remove Script."
Frequently Asked Questions
Q: How are scripts different from EAs? A: Scripts execute a single action and then stop; EAs monitor the market and trade continuously.
Q: Can I assign a hotkey to a script? A: Yes, right-click the script in the Navigator, select "Set Hotkey," and define your preferred keyboard shortcut.
Q: Why did my script stop? A: Scripts are designed to stop immediately after finishing their programmed command; this is normal behavior.
What this tool does
Trade History Stats analyzes your account history to provide a comprehensive overview of your trading performance.
Typical Use Case
This Script excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Script works on MetaTrader 5. Place the file in the MQL5/Scripts folder and restart the terminal.
Description & Settings
Related: Export Closed Trades to CSV with Summary by Magic Number - another powerful script for MetaTrader 5 traders.
Trade History Stats analyzes your account history to provide a comprehensive overview of your trading performance.Also recommended: MetaTrader Backtest Data Validation: Broker Bar and Tick History Check - similar script with strong performance on MetaTrader 5.
This tool is compatible with both manual trading and Expert Advisors (EAs), and offers filtering by symbol and magic number.
The script operates in a read-only mode, ensuring that it does not alter, open, or close any trades.
Key Performance Metrics Reported (per symbol and in total):
- Number of closed trades
- Win rate percentage
- Net result (Profit + Swap + Commission + Fees)
- Profit factor
- Average win and average loss amounts
- Longest losing streak (based on trade closing order)
Operational Details:
- Trades are aggregated by position ID. A position closed in multiple parts is treated as a single trade, including all associated costs.
- Balance, credit, and bonus operations are excluded from the analysis.
- Trades are sorted by close time to accurately determine losing streaks.
- Break-even trades are classified as losses as they did not generate profit.
Script Inputs:
- History Period (days): Set to 0 to include all historical data.
- Only This Symbol: Leave empty to analyze all symbols; specify a symbol to filter.
- Only This Magic Number: Use -1 for all trades, or 0 for manual trades only.
- Save CSV: Enables saving data to MQL5\Files\TradeHistoryStats.csv for analysis in Excel.
- Show Summary Window: Displays the overall summary in a message box.
Usage Instructions:
1. Place the TradeHistoryStats.mq5 file into the MQL5\Scripts directory and compile it.
2. Drag the script onto any chart and configure the desired inputs.
3. Review the summary window. Detailed per-symbol tables are available in the Toolbox under the Experts tab.
Tip: To evaluate an EA, input its specific magic number. Compare the results with the Strategy Tester to verify if live performance aligns with backtest data.
=====================================================================
FORUM DISCUSSION (New Topic)
=====================================================================
Section: Expert Advisors and Automated Trading
Title: MQL5 Chart Panel Development: Comment(), Chart Objects, or CCanvas?
Text:
Hello fellow developers,
I specialize in creating indicators and EAs for gold, forex, and synthetic indices. A significant portion of my development effort goes into creating effective on-chart panels, as these are central to the user's daily interaction with the trading platform.
To date, I have explored three primary methods for panel construction:
1. Using Comment(): This is the quickest method for initial development. However, it limits customization to a single font, color, and fixed position. Furthermore, only one program per chart can utilize this function.
2. Employing Chart Objects (OBJ_RECTANGLE_LABEL + OBJ_LABEL): This approach provides comprehensive control over colors and layout. Updating individual values is straightforward, and it functions correctly within visual testing. The primary drawback is the overhead involved in managing a large number of individual objects and ensuring their proper cleanup.
3. Utilizing CCanvas: This method offers the greatest flexibility in drawing, including rounded corners and the ability to embed smaller charts within the panel. The main limitation is that the entire bitmap must be redrawn upon any change, which can impact performance.
Currently, my preferred method involves using chart objects, enhanced by a custom class. This class manages object creation, updates only changed values, and handles the saving and restoring of user chart colors upon panel removal.
I am keen to gather insights from experienced MQL5 developers on the following points:
- For panels requiring tick-by-tick updates, which method do you find most effective?
- Have you conducted performance benchmarking between managing numerous OBJ_LABEL objects versus using a single CCanvas bitmap?
- How do you address high-DPI display scaling (e.g., 150% / 200%)? My current approach involves scaling pixel sizes using TERMINAL_DPI / 96. Are there more efficient or robust methods?
I look forward to learning about your experiences and preferred techniques.
Thank you.
You may also like: Trade History Exporter: Detailed Closed Trade Analysis to CSV - excellent alternative for script users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property script_show_inputs
input int InpDays = 30;
input string InpSymbol = "";
input long InpMagic = -1;
input bool InpSaveCSV = true;
input bool InpShowWindow = true;
.......
⚠ 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.