gionuibk commited on
Commit
5cfd565
·
verified ·
1 Parent(s): b021a39

Upload fast_simulate_THE_ONE.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. fast_simulate_THE_ONE.py +84 -0
fast_simulate_THE_ONE.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import time
4
+
5
+ def simulate():
6
+ print("==================================================")
7
+ print(" PYTHON QUANT LAB: FAST SIMULATE 'THE ONE' ")
8
+ print("==================================================")
9
+
10
+ print("[1] Loading 100MB Parquet Tick Data...")
11
+ t0 = time.time()
12
+ df = pd.read_parquet(r"C:\Users\Black\Downloads\MT5EA\tick_data\ticks_100MB.parquet", columns=['time_msc', 'bid'])
13
+
14
+ df['datetime'] = pd.to_datetime(df['time_msc'], unit='ms')
15
+ df.set_index('datetime', inplace=True)
16
+ print(f" -> Loaded {len(df):,} ticks in {time.time()-t0:.2f} seconds.")
17
+
18
+ print("\n[2] Resampling Ticks to M1 Candles...")
19
+ t1 = time.time()
20
+ ohlc = df['bid'].resample('1min').ohlc()
21
+ ohlc.dropna(inplace=True)
22
+ print(f" -> Generated {len(ohlc):,} M1 candles in {time.time()-t1:.2f} seconds.")
23
+
24
+ # Thông số cấu hình
25
+ min_bodies = [30, 50, 100, 150, 200, 300, 400]
26
+ tp_pts = 400
27
+ sl_pts = 1000
28
+
29
+ print("\n[3] Quét Ma Trận (Matrix Sweep) - Chờ MT5 36 tiếng, Python làm trong 5 giây!")
30
+ 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)")
31
+ print("-" * 75)
32
+ 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}")
33
+ print("-" * 75)
34
+
35
+ open_p = ohlc['open'].values
36
+ close_p = ohlc['close'].values
37
+ high_p = ohlc['high'].values
38
+ low_p = ohlc['low'].values
39
+
40
+ for mb in min_bodies:
41
+ # Vàng 2 số thập phân -> 50 points = 0.50
42
+ mb_price = mb * 0.01
43
+ tp_price = tp_pts * 0.01
44
+ sl_price = sl_pts * 0.01
45
+
46
+ # Điều kiện nổ súng (Naked Price Action)
47
+ buy_signals = (close_p - open_p) >= mb_price
48
+ sell_signals = (open_p - close_p) >= mb_price
49
+
50
+ wins = 0
51
+ losses = 0
52
+
53
+ for i in range(len(open_p)-1):
54
+ if buy_signals[i]:
55
+ entry = open_p[i+1] # Vào lệnh ở đầu nến tiếp theo
56
+ # Quét tương lai xem chạm SL hay TP trước
57
+ for j in range(i+1, min(len(open_p), i+120)): # Quét max 2 tiếng
58
+ if low_p[j] <= entry - sl_price:
59
+ losses += 1
60
+ break
61
+ elif high_p[j] >= entry + tp_price:
62
+ wins += 1
63
+ break
64
+
65
+ elif sell_signals[i]:
66
+ entry = open_p[i+1]
67
+ for j in range(i+1, min(len(open_p), i+120)):
68
+ if high_p[j] >= entry + sl_price:
69
+ losses += 1
70
+ break
71
+ elif low_p[j] <= entry - tp_price:
72
+ wins += 1
73
+ break
74
+
75
+ total = wins + losses
76
+ winrate = (wins/total*100) if total > 0 else 0
77
+ pnl = (wins * tp_pts) - (losses * sl_pts)
78
+
79
+ # Color formatting manually
80
+ pnl_str = f"+{pnl}" if pnl > 0 else f"{pnl}"
81
+ print(f"{mb:<10} | {total:<12} | {wins:<10} | {losses:<10} | {winrate:<8.2f}% | {pnl_str:<15}")
82
+
83
+ if __name__ == "__main__":
84
+ simulate()