Trade History Stats
Info
The Trade History Stats is a Script for MetaTrader 5 that trade history stats reads your account history and shows how your trading really performed. It works for manual trading and for Expert Advisors, and it can filter 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 Stats
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 reads your account history and shows how your trading really performed.
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 reads your account history and shows how your trading really performed. It works for manual trading and for Expert Advisors, and it can filter by symbol and magic number.
Also recommended: MetaTrader Backtest Data Validation: Broker Bar and Tick History Check - similar script with strong performance on MetaTrader 5.
The script is read-only. It never opens, modifies or closes any trade.
What it reports (per symbol and in total):
- Number of closed trades
- Win rate
- Net result (profit + swap + commission + fees)
- Profit factor
- Average win and average loss
- Longest losing streak (in the order the trades were closed)
How it works:
- Deals are grouped by position ID, so a position that was closed in several parts counts as one trade, with all its costs included.
- Balance, credit and bonus operations are ignored.
- Trades are sorted by close time before the losing streak is counted.
- Break-even trades are counted as losses (they made no profit).
Inputs:
- History period (days): 0 = all history
- Only this symbol: empty = all symbols
- Only this magic number: -1 = all, 0 = manual trades only
- Save CSV: writes MQL5\Files\TradeHistoryStats.csv (opens in Excel)
- Show summary window: shows the total in a message box
How to use:
1. Copy TradeHistoryStats.mq5 to MQL5\Scripts and compile it.
2. Drag the script onto any chart and set the inputs.
3. Read the summary window. The table per symbol is in the Toolbox, Experts tab.
Tip: To check an EA, set its magic number in the input. Compare the result with the Strategy Tester to see if live results match the backtest.
Screenshots to upload (take them yourself):
1. The inputs window
2. The summary message box
3. The Experts tab with the table
4. The CSV opened in Excel (optional)
=====================================================================
2) FORUM (Add new topic)
=====================================================================
Section: General (or "Expert Advisors and Automated Trading")
Title:
Chart panels in MQL5: Comment(), chart objects or CCanvas - what do you use and why?
Text:
Hello everyone,
I build indicators and EAs for gold, forex and synthetic indices, and I spend a lot of time on the on-chart panel, because that is what the user looks at every day.
So far I have used three approaches:
1. Comment() - fastest to write, but one font, one color, fixed position, and only one program per chart can use it.
2. Chart objects (OBJ_RECTANGLE_LABEL + OBJ_LABEL) - full control of colors and layout, easy to update one value, works in visual testing. The downside is managing many objects and cleaning them up.
3. CCanvas - full drawing freedom (rounded corners, small charts inside the panel), but the whole bitmap must be redrawn on every change.
At the moment I use chart objects with a small class: a "cursor" that moves down as rows are added, updates that only write values that changed, and the user's chart colors saved and restored on removal.
A few questions for experienced developers:
- Which approach do you use for panels that update on every tick?
- Have you measured a real performance difference between many OBJ_LABEL objects and one CCanvas bitmap?
- How do you handle high-DPI screens (150% / 200%)? I scale all pixel sizes with TERMINAL_SCREEN_DPI / 96. Is there a better way?
I would like to hear what works for you.
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.