Files
mymt5opp/scripts/trade_by_trade.py
2026-06-26 20:50:07 +08:00

45 lines
1.8 KiB
Python

"""Trade-by-trade comparison to locate the PnL gap source.
Both sides now produce 92 trades on the same window. This script dumps the
first ~20 trades from each side side-by-side so we can see WHERE the PnL
diverges (entry price? exit price? lots? swap?).
"""
from __future__ import annotations
import sys
from pathlib import Path
PROJECT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT))
import pandas as pd
from shared.core.engine import SizingInputs
from shared.core.metrics import compute_metrics
from shared.data.loaders import load_bars
from shared.data.mt5_report import parse_mt5_report
from strategies.gold_scalper_pro.instruments import XAUUSD_REAL
from strategies.gold_scalper_pro.scalper_engine import (
ScalperEngine,
engine_kwargs_from_params,
)
from strategies.gold_scalper_pro.search_space import FROZEN_BASELINE
from strategies.gold_scalper_pro.signals import build_signals
def main() -> int:
# ── Python trades ─────────────────────────────────────────────────────
bars = load_bars(PROJECT / "data" / "XAUUSD_M5_2024-06-26_2026-06-26.parquet")
start = pd.Timestamp("2026-04-16 00:00:00")
end = pd.Timestamp("2026-05-08 00:00:00")
window = bars[(bars["timestamp"] >= start) & (bars["timestamp"] < end)].reset_index(drop=True)
pack = build_signals(FROZEN_BASELINE, window, XAUUSD_REAL)
engine = ScalperEngine()
result = engine.run(
window, pack.signals_long, pack.signals_short,
pack.sl_prices, pack.tp_prices,
XAUUSD_REAL, SizingInputs(), 1000.0,
**engine_kwargs_from_params(FROZEN_BASELINE),
)
print("=== Python first 20 trades ===")
print(f"{'#':>3