import pandas as pd import numpy as np import time def simulate(): print("==================================================") print(" PYTHON QUANT LAB: FAST SIMULATE 'THE ONE' ") print("==================================================") print("[1] Loading 100MB Parquet Tick Data...") t0 = time.time() df = pd.read_parquet(r"C:\Users\Black\Downloads\MT5EA\tick_data\ticks_100MB.parquet", columns=['time_msc', 'bid']) df['datetime'] = pd.to_datetime(df['time_msc'], unit='ms') df.set_index('datetime', inplace=True) print(f" -> Loaded {len(df):,} ticks in {time.time()-t0:.2f} seconds.") print("\n[2] Resampling Ticks to M1 Candles...") t1 = time.time() ohlc = df['bid'].resample('1min').ohlc() ohlc.dropna(inplace=True) print(f" -> Generated {len(ohlc):,} M1 candles in {time.time()-t1:.2f} seconds.") # Thông số cấu hình min_bodies = [30, 50, 100, 150, 200, 300, 400] tp_pts = 400 sl_pts = 1000 print("\n[3] Quét Ma Trận (Matrix Sweep) - Chờ MT5 36 tiếng, Python làm trong 5 giây!") print(f"Cấu hình: TP = {tp_pts} pts | SL = {sl_pts} pts (Lưu ý: Chưa tính Nhồi Lưới - Chỉ test Naked Entry)") print("-" * 75) print(f"{'Min_Body':<10} | {'Tổng Lệnh':<12} | {'Win Lệnh':<10} | {'Lose Lệnh':<10} | {'WinRate':<10} | {'Net P/L (Pts)':<15}") print("-" * 75) open_p = ohlc['open'].values close_p = ohlc['close'].values high_p = ohlc['high'].values low_p = ohlc['low'].values for mb in min_bodies: # Vàng 2 số thập phân -> 50 points = 0.50 mb_price = mb * 0.01 tp_price = tp_pts * 0.01 sl_price = sl_pts * 0.01 # Điều kiện nổ súng (Naked Price Action) buy_signals = (close_p - open_p) >= mb_price sell_signals = (open_p - close_p) >= mb_price wins = 0 losses = 0 for i in range(len(open_p)-1): if buy_signals[i]: entry = open_p[i+1] # Vào lệnh ở đầu nến tiếp theo # Quét tương lai xem chạm SL hay TP trước for j in range(i+1, min(len(open_p), i+120)): # Quét max 2 tiếng if low_p[j] <= entry - sl_price: losses += 1 break elif high_p[j] >= entry + tp_price: wins += 1 break elif sell_signals[i]: entry = open_p[i+1] for j in range(i+1, min(len(open_p), i+120)): if high_p[j] >= entry + sl_price: losses += 1 break elif low_p[j] <= entry - tp_price: wins += 1 break total = wins + losses winrate = (wins/total*100) if total > 0 else 0 pnl = (wins * tp_pts) - (losses * sl_pts) # Color formatting manually pnl_str = f"+{pnl}" if pnl > 0 else f"{pnl}" print(f"{mb:<10} | {total:<12} | {wins:<10} | {losses:<10} | {winrate:<8.2f}% | {pnl_str:<15}") if __name__ == "__main__": simulate()