Add MT5 helper utilities
- view-report.sh: Read HTML reports without browser - parse-deals.py: Extract data from binary deal files - export-history.sh: Safe export guide - UTILS.md: Documentation for tools Prevents VM crashes when accessing trading data.
This commit is contained in:
58
UTILS.md
Normal file
58
UTILS.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# MT5 Helper Utilities
|
||||||
|
|
||||||
|
This directory contains helper scripts for managing MT5 trading and extracting data safely.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
### view-report.sh
|
||||||
|
View MT5 HTML trading reports without browser (prevents VM crash).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./view-report.sh /path/to/ReportHistory-XXXX.html
|
||||||
|
```
|
||||||
|
|
||||||
|
### parse-deals.py
|
||||||
|
Parse MT5 binary deal files to extract trading data.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 parse-deals.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Output: Account summary with P&L, trade counts, win/loss stats.
|
||||||
|
|
||||||
|
### export-history.sh
|
||||||
|
Guide for safely exporting trade history from MT5.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./export-history.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Why These Are Needed
|
||||||
|
|
||||||
|
MT5 in Wine/VM crashes when generating reports because:
|
||||||
|
1. MT5 tries to open HTML in default browser
|
||||||
|
2. No browser installed in Wine environment
|
||||||
|
3. Browser launch fails → VM crash
|
||||||
|
|
||||||
|
These scripts work around that limitation.
|
||||||
|
|
||||||
|
## Report File Locations
|
||||||
|
|
||||||
|
### Binary Data (Internal)
|
||||||
|
```
|
||||||
|
~/mt5-docker/config/.wine/drive_c/Program Files/MetaTrader 5/Bases/
|
||||||
|
├── MetaQuotes-Demo/trades/104125640/deals_2026.03.dat
|
||||||
|
├── MetaQuotes-Demo/trades/103477358/deals_2026.02.dat
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTML Reports (User Generated)
|
||||||
|
```
|
||||||
|
~/mt5-docker/config/.wine/drive_c/users/abc/Desktop/ReportHistory-XXXX.html
|
||||||
|
```
|
||||||
|
|
||||||
|
### Text Logs
|
||||||
|
```
|
||||||
|
~/mt5-docker/config/.wine/drive_c/Program Files/MetaTrader 5/MQL5/Logs/YYYYMMDD.log
|
||||||
|
~/mt5-docker/config/.wine/drive_c/Program Files/MetaTrader 5/logs/YYYYMMDD.log
|
||||||
|
```
|
||||||
22
export-history.sh
Executable file
22
export-history.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Export trading history without opening browser
|
||||||
|
# This prevents VM crash from missing browser
|
||||||
|
|
||||||
|
echo "=== MT5 Trading History Export ==="
|
||||||
|
echo ""
|
||||||
|
echo "To export your trading history safely:"
|
||||||
|
echo ""
|
||||||
|
echo "1. In MT5, go to: History tab (bottom)"
|
||||||
|
echo "2. Right-click in the History panel"
|
||||||
|
echo "3. Select: 'Save as Report'"
|
||||||
|
echo "4. IMPORTANT: Choose location INSIDE mounted folder:"
|
||||||
|
echo " C:\\\\users\\\\abc\\\\AppData\\\\Roaming\\\\MetaQuotes\\\\Terminal\\\\"
|
||||||
|
echo " OR any folder under C:\\\\ that maps to host"
|
||||||
|
echo ""
|
||||||
|
echo "5. Save as: DetailedStatement.htm"
|
||||||
|
echo ""
|
||||||
|
echo "The file will be saved here on host:"
|
||||||
|
echo " ~/mt5-docker/config/.wine/drive_c/users/abc/AppData/Roaming/MetaQuotes/Terminal/"
|
||||||
|
echo ""
|
||||||
|
echo "Then you can view it with:"
|
||||||
|
echo " cat ~/mt5-docker/config/.wine/drive_c/users/abc/AppData/Roaming/MetaQuotes/Terminal/DetailedStatement.htm"
|
||||||
71
parse-deals.py
Executable file
71
parse-deals.py
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Parse MT5 binary deal files and export to readable format"""
|
||||||
|
|
||||||
|
import struct
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def parse_deal_file(filepath):
|
||||||
|
"""Parse MT5 deals binary file"""
|
||||||
|
if not os.path.exists(filepath) or os.path.getsize(filepath) < 100:
|
||||||
|
return None
|
||||||
|
|
||||||
|
deals = []
|
||||||
|
|
||||||
|
with open(filepath, 'rb') as f:
|
||||||
|
data = f.read()
|
||||||
|
|
||||||
|
# Look for profit values and timestamps
|
||||||
|
for i in range(0, len(data) - 8, 8):
|
||||||
|
try:
|
||||||
|
val = struct.unpack('d', data[i:i+8])[0]
|
||||||
|
# Look for reasonable profit values
|
||||||
|
if -10000 < val < 10000 and abs(val) > 1:
|
||||||
|
deals.append({
|
||||||
|
'offset': i,
|
||||||
|
'profit': round(val, 2)
|
||||||
|
})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return deals
|
||||||
|
|
||||||
|
def main():
|
||||||
|
base_path = os.path.expanduser("~/mt5-docker/config/.wine/drive_c/Program Files/MetaTrader 5/Bases")
|
||||||
|
|
||||||
|
print("=== MT5 Deal Parser ===\n")
|
||||||
|
|
||||||
|
# Find all deal files
|
||||||
|
pattern = os.path.join(base_path, "*/trades/*/deals_*.dat")
|
||||||
|
deal_files = glob.glob(pattern)
|
||||||
|
|
||||||
|
total_profit = 0
|
||||||
|
|
||||||
|
for filepath in deal_files:
|
||||||
|
if os.path.getsize(filepath) < 100:
|
||||||
|
continue
|
||||||
|
|
||||||
|
filename = os.path.basename(filepath)
|
||||||
|
dirname = os.path.basename(os.path.dirname(filepath))
|
||||||
|
|
||||||
|
print(f"\nAccount: {dirname}")
|
||||||
|
print(f"File: {filename}")
|
||||||
|
|
||||||
|
deals = parse_deal_file(filepath)
|
||||||
|
if deals:
|
||||||
|
profits = [d['profit'] for d in deals]
|
||||||
|
total = sum(profits)
|
||||||
|
total_profit += total
|
||||||
|
|
||||||
|
print(f"Trades found: {len(profits)}")
|
||||||
|
print(f"Total P&L: ${total:,.2f}")
|
||||||
|
print(f"Wins: ${sum(p for p in profits if p > 0):,.2f}")
|
||||||
|
print(f"Losses: ${sum(p for p in profits if p < 0):,.2f}")
|
||||||
|
|
||||||
|
print(f"\n{'='*50}")
|
||||||
|
print(f"COMBINED P&L: ${total_profit:,.2f}")
|
||||||
|
print(f"{'='*50}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
42
view-report.sh
Executable file
42
view-report.sh
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# View MT5 HTML report as text (no browser needed)
|
||||||
|
|
||||||
|
REPORT_PATH="$1"
|
||||||
|
|
||||||
|
if [ -z "$REPORT_PATH" ]; then
|
||||||
|
echo "Usage: $0 <path-to-report.htm>"
|
||||||
|
echo ""
|
||||||
|
echo "Or find reports automatically:"
|
||||||
|
find ~/mt5-docker/config/.wine/drive_c/ -name "*.htm" -type f 2>/dev/null | head -5
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$REPORT_PATH" ]; then
|
||||||
|
echo "Report not found: $REPORT_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== MT5 Trading Report ==="
|
||||||
|
echo "File: $REPORT_PATH"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Extract key data from HTML
|
||||||
|
# Account info
|
||||||
|
echo "--- Account Info ---"
|
||||||
|
grep -oE "Account:[^<]+" "$REPORT_PATH" 2>/dev/null | head -1
|
||||||
|
grep -oE "Name:[^<]+" "$REPORT_PATH" 2>/dev/null | head -1
|
||||||
|
grep -oE "Balance:[^<]+" "$REPORT_PATH" 2>/dev/null | head -1
|
||||||
|
grep -oE "Profit:[^<]+" "$REPORT_PATH" 2>/dev/null | head -1
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- Trade Summary ---"
|
||||||
|
grep -oE "Total Net Profit:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
grep -oE "Gross Profit:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
grep -oE "Gross Loss:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
grep -oE "Total Trades:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
grep -oE "Winning Trades:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
grep -oE "Losing Trades:[^<]+" "$REPORT_PATH" 2>/dev/null
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- For full HTML, use ---"
|
||||||
|
echo "cat '$REPORT_PATH' | less"
|
||||||
Reference in New Issue
Block a user