-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatih_final.py
More file actions
82 lines (63 loc) · 2.72 KB
/
latih_final.py
File metadata and controls
82 lines (63 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pandas as pd
import numpy as np
FILENAME = 'bitcoin_15m_lengkap.csv'
def check_sweet_spot(df, target_pct, window_candles):
# target_pct: misal 0.005 (0.5%)
# window_candles: misal 16 (4 jam)
stop_loss = -target_pct # Risk : Reward = 1 : 1
wins = 0
losses = 0
draws = 0 # Gak kena TP, gak kena SL sampai waktu habis
# Kita sampling data biar cepet (gak perlu cek tiap baris, ambil step 5)
# Sampling tiap 5 baris cukup representatif
for i in range(0, len(df) - window_candles, 5):
current_close = df.iloc[i]['close']
future_data = df.iloc[i+1 : i+1+window_candles]['close']
# Hitung % perubahan tertinggi dan terendah dalam periode itu
max_gain = (future_data.max() - current_close) / current_close
max_loss = (future_data.min() - current_close) / current_close
hit_tp = max_gain >= target_pct
hit_sl = max_loss <= stop_loss
if hit_tp and not hit_sl:
wins += 1
elif hit_sl and not hit_tp:
losses += 1
elif hit_tp and hit_sl:
# Kena dua-duanya (Whipsaw/Volatilitas Tinggi) -> Anggap Loss biar aman
losses += 1
else:
draws += 1
total_trades = wins + losses + draws
real_win_rate = (wins / total_trades) * 100
action_rate = ((wins + losses) / total_trades) * 100
return real_win_rate, action_rate
# --- MAIN ---
print("⏳ Sedang Scan Perilaku Market BTC 2023-2025...")
df = pd.read_csv(FILENAME)
targets = [0.003, 0.005, 0.010, 0.015] # 0.3%, 0.5%, 1%, 1.5%
durations = [4, 16, 32, 96] # 1 Jam, 4 Jam, 8 Jam, 24 Jam (Candle 15m)
results = []
print(f"{'TARGET':<8} | {'DURASI':<8} | {'WIN RATE (MURNI)':<18} | {'KEJADIAN (Action)'}")
print("-" * 65)
for t in targets:
for d in durations:
wr, action = check_sweet_spot(df, t, d)
# Format output
dur_str = f"{d/4} Jam"
tar_str = f"{t*100}%"
print(f"{tar_str:<8} | {dur_str:<8} | {wr:.2f}%{' ':<11} | {action:.2f}% Data")
results.append({
'Target': t,
'Duration': d,
'WinRate': wr,
'Action': action
})
print("-" * 65)
# Cari yang Win Rate dasarnya paling tinggi (mendekati 50%)
# Kalau Win Rate dasar udah 45-50%, ditambah AI pasti tembus 60%.
# Kalau Win Rate dasar cuma 10%, AI gak bakal bisa nolong.
best = max(results, key=lambda x: x['WinRate'])
print(f"\n🏆 SWEET SPOT DITEMUKAN:")
print(f"Target Profit: {best['Target']*100}%")
print(f"Hold Time: {best['Duration']/4} Jam")
print(f"Base Win Rate: {best['WinRate']:.2f}% (Peluang menang tanpa mikir)")