- export-live-report.py: Export from binary deal files - create-live-report.sh: Create report from screenshot/terminal data - Allows creating browser-viewable reports with current live data - Uses ,935 profit from March 21 screenshot
358 lines
12 KiB
Python
Executable File
358 lines
12 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Export current/live MT5 trading data from binary deal files to HTML"""
|
|
|
|
import struct
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
def parse_deal_file(filepath):
|
|
"""Parse MT5 binary deal file and extract trading data"""
|
|
if not os.path.exists(filepath):
|
|
return None
|
|
|
|
with open(filepath, 'rb') as f:
|
|
data = f.read()
|
|
|
|
# Look for floating point numbers (profits)
|
|
profits = []
|
|
for i in range(0, len(data) - 8, 8):
|
|
try:
|
|
val = struct.unpack('d', data[i:i+8])[0]
|
|
# Look for reasonable profit values (-5000 to 15000)
|
|
if -5000 < val < 15000 and abs(val) > 10:
|
|
# Check if it has decimal precision (not a timestamp)
|
|
if abs(val - round(val, 2)) < 0.01:
|
|
profits.append(round(val, 2))
|
|
except:
|
|
pass
|
|
|
|
# Remove duplicates while preserving order
|
|
seen = set()
|
|
unique_profits = []
|
|
for p in profits:
|
|
if p not in seen:
|
|
seen.add(p)
|
|
unique_profits.append(p)
|
|
|
|
return unique_profits
|
|
|
|
def generate_live_report(account_num, profits, output_file):
|
|
"""Generate HTML report from live binary data"""
|
|
|
|
# Calculate statistics
|
|
wins = [p for p in profits if p > 0]
|
|
losses = [p for p in profits if p < 0]
|
|
|
|
total_profit = sum(profits)
|
|
gross_profit = sum(wins)
|
|
gross_loss = sum(losses)
|
|
|
|
total_trades = len(profits)
|
|
win_count = len(wins)
|
|
loss_count = len(losses)
|
|
win_rate = (win_count / total_trades * 100) if total_trades > 0 else 0
|
|
|
|
profit_factor = abs(gross_profit / gross_loss) if gross_loss != 0 else 0
|
|
|
|
largest_win = max(wins) if wins else 0
|
|
largest_loss = min(losses) if losses else 0
|
|
avg_win = sum(wins) / len(wins) if wins else 0
|
|
avg_loss = sum(losses) / len(losses) if losses else 0
|
|
|
|
starting_balance = 100000.00
|
|
current_balance = starting_balance + total_profit
|
|
return_pct = (total_profit / starting_balance) * 100
|
|
|
|
html_content = f'''<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>MT5 Live Trading Report - Account {account_num}</title>
|
|
<style>
|
|
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
body {{
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}}
|
|
.container {{
|
|
max-width: 1000px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
overflow: hidden;
|
|
}}
|
|
.header {{
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
text-align: center;
|
|
}}
|
|
.header h1 {{ font-size: 28px; margin-bottom: 10px; }}
|
|
.live-badge {{
|
|
display: inline-block;
|
|
background: #28a745;
|
|
color: white;
|
|
padding: 5px 15px;
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
font-weight: bold;
|
|
margin-top: 10px;
|
|
}}
|
|
.content {{ padding: 30px; }}
|
|
.section {{ margin-bottom: 30px; }}
|
|
.section-title {{
|
|
font-size: 20px;
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 2px solid #667eea;
|
|
}}
|
|
.metric-box {{
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
border-radius: 12px;
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
}}
|
|
.metric-value {{
|
|
font-size: 48px;
|
|
font-weight: bold;
|
|
margin-bottom: 5px;
|
|
}}
|
|
.metric-label {{ font-size: 14px; opacity: 0.9; }}
|
|
.info-grid {{
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 15px;
|
|
}}
|
|
.info-item {{
|
|
background: #f8f9fa;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #667eea;
|
|
}}
|
|
.info-label {{
|
|
font-size: 12px;
|
|
color: #666;
|
|
text-transform: uppercase;
|
|
margin-bottom: 5px;
|
|
}}
|
|
.info-value {{
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
}}
|
|
.profit {{ color: #28a745; }}
|
|
.loss {{ color: #dc3545; }}
|
|
.stats-grid {{
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
|
|
gap: 15px;
|
|
}}
|
|
.stat-card {{
|
|
background: #f8f9fa;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
text-align: center;
|
|
}}
|
|
.stat-value {{
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
}}
|
|
.stat-label {{
|
|
font-size: 11px;
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}}
|
|
.trade-list {{
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
background: #f8f9fa;
|
|
border-radius: 8px;
|
|
padding: 15px;
|
|
}}
|
|
.trade-item {{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 10px;
|
|
border-bottom: 1px solid #dee2e6;
|
|
}}
|
|
.trade-item:last-child {{ border-bottom: none; }}
|
|
.footer {{
|
|
background: #f8f9fa;
|
|
padding: 20px;
|
|
text-align: center;
|
|
color: #666;
|
|
font-size: 12px;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>📊 MT5 LIVE Trading Report</h1>
|
|
<p>Account {account_num} | Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}</p>
|
|
<div class="live-badge">● LIVE DATA</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<!-- Main Performance -->
|
|
<div class="section">
|
|
<h2 class="section-title">💰 Performance Summary</h2>
|
|
<div class="metric-box">
|
|
<div class="metric-value">{'+' if total_profit > 0 else ''}${total_profit:,.2f}</div>
|
|
<div class="metric-label">Total Net Profit</div>
|
|
</div>
|
|
|
|
<div class="info-grid">
|
|
<div class="info-item">
|
|
<div class="info-label">Starting Balance</div>
|
|
<div class="info-value">${starting_balance:,.2f}</div>
|
|
</div>
|
|
<div class="info-item">
|
|
<div class="info-label">Current Balance</div>
|
|
<div class="info-value {'profit' if total_profit > 0 else 'loss'}">${current_balance:,.2f}</div>
|
|
</div>
|
|
<div class="info-item">
|
|
<div class="info-label">Total Return</div>
|
|
<div class="info-value {'profit' if return_pct > 0 else 'loss'}">{return_pct:.2f}%</div>
|
|
</div>
|
|
<div class="info-item">
|
|
<div class="info-label">Profit Factor</div>
|
|
<div class="info-value">{profit_factor:.2f}</div>
|
|
</div>
|
|
<div class="info-item">
|
|
<div class="info-label">Gross Profit</div>
|
|
<div class="info-value profit">${gross_profit:,.2f}</div>
|
|
</div>
|
|
<div class="info-item">
|
|
<div class="info-label">Gross Loss</div>
|
|
<div class="info-value loss">${gross_loss:,.2f}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Trade Statistics -->
|
|
<div class="section">
|
|
<h2 class="section-title">📈 Trade Statistics</h2>
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<div class="stat-value">{total_trades}</div>
|
|
<div class="stat-label">Total Trades</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #28a745;">{win_count}</div>
|
|
<div class="stat-label">Winning</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #dc3545;">{loss_count}</div>
|
|
<div class="stat-label">Losing</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: {'#28a745' if win_rate > 60 else '#ffc107'}">{win_rate:.1f}%</div>
|
|
<div class="stat-label">Win Rate</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #28a745;">${largest_win:,.2f}</div>
|
|
<div class="stat-label">Largest Win</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #dc3545;">${abs(largest_loss):,.2f}</div>
|
|
<div class="stat-label">Largest Loss</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #28a745;">${avg_win:,.2f}</div>
|
|
<div class="stat-label">Avg Win</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" style="color: #dc3545;">${abs(avg_loss):,.2f}</div>
|
|
<div class="stat-label">Avg Loss</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Recent Trades -->
|
|
<div class="section">
|
|
<h2 class="section-title">📝 Recent Trade P&L</h2>
|
|
<div class="trade-list">
|
|
'''
|
|
|
|
# Add trade list (last 20 trades)
|
|
for i, profit in enumerate(profits[-20:], 1):
|
|
color_class = 'profit' if profit > 0 else 'loss'
|
|
sign = '+' if profit > 0 else ''
|
|
html_content += f''' <div class="trade-item">
|
|
<span>Trade #{i}</span>
|
|
<span class="{color_class}">{sign}${profit:,.2f}</span>
|
|
</div>
|
|
'''
|
|
|
|
html_content += f''' </div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Live data from MT5 binary deal files | Strategy: MultiSignal Confluence EA</p>
|
|
<p>Data source: deals_2026.03.dat (last updated: {datetime.now().strftime('%Y-%m-%d %H:%M')})</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>'''
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
f.write(html_content)
|
|
|
|
return output_file
|
|
|
|
def main():
|
|
account_num = "104125640"
|
|
deal_file = os.path.expanduser(f"~/mt5-docker/config/.wine/drive_c/Program Files/MetaTrader 5/Bases/MetaQuotes-Demo/trades/{account_num}/deals_2026.03.dat")
|
|
|
|
if not os.path.exists(deal_file):
|
|
print(f"❌ Deal file not found: {deal_file}")
|
|
sys.exit(1)
|
|
|
|
print(f"📊 Parsing live data from: {deal_file}")
|
|
print(f" File date: {datetime.fromtimestamp(os.path.getmtime(deal_file))}")
|
|
print("")
|
|
|
|
profits = parse_deal_file(deal_file)
|
|
if not profits:
|
|
print("❌ No profit data found")
|
|
sys.exit(1)
|
|
|
|
print(f"✅ Found {len(profits)} trades")
|
|
|
|
# Generate output
|
|
timestamp = datetime.now().strftime('%Y%m%d-%H%M%S')
|
|
output_file = os.path.expanduser(f"~/mt5-live-report-{account_num}-{timestamp}.html")
|
|
|
|
generate_live_report(account_num, profits, output_file)
|
|
|
|
# Calculate summary
|
|
total = sum(profits)
|
|
wins = len([p for p in profits if p > 0])
|
|
|
|
print(f"")
|
|
print(f"✅ Live report exported to: {output_file}")
|
|
print(f"")
|
|
print(f"📊 SUMMARY:")
|
|
print(f" Account: {account_num}")
|
|
print(f" Total Trades: {len(profits)}")
|
|
print(f" Winning Trades: {wins}")
|
|
print(f" Total P&L: ${total:,.2f}")
|
|
print(f" Balance: ${100000 + total:,.2f}")
|
|
print(f" Return: {(total/100000)*100:.2f}%")
|
|
print(f"")
|
|
print(f"🌐 Open in browser:")
|
|
print(f" file://{output_file}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|