Nexo-S commited on
Commit
581a042
·
verified ·
1 Parent(s): 0c9a77a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -178,8 +178,6 @@ def init_db():
178
  # On initialise les réglages sur le régime 3 (RANGE/CHAOS) par défaut
179
  defaults = [
180
  # Symbol, TF, Regime, TP, SL, Score, PNL, Prob, Dist, Gen, B_TP, B_SL
181
- ('ALL', '1m', 3, 1.0, 0.8, 0, 0, 0.65, 0.001, 1, 0, 0),
182
- ('ALL', '5m', 3, 1.2, 0.9, 0, 0, 0.62, 0.002, 1, 0, 0),
183
  ('ALL', '15m', 3, 1.5, 1.0, 0, 0, 0.60, 0.003, 1, 0, 0),
184
  ('ALL', '1h', 3, 2.0, 1.5, 0, 0, 0.55, 0.005, 1, 0, 0),
185
  ('ALL', '4h', 3, 3.0, 2.0, 0, 0, 0.50, 0.008, 1, 0, 0)
@@ -363,7 +361,7 @@ def prepare_features_sync(symbol, timeframe='1h', limit_bars=600):
363
 
364
  import numpy as np
365
 
366
- def detect_chart_scenario(df, df_1m=None, df_5m=None, df_15m=None, df_1h=None):
367
  try:
368
  # 🛠️ Fix colonnes KuCoin
369
  if 'vol' in df.columns and 'volume' not in df.columns:
@@ -392,21 +390,18 @@ def detect_chart_scenario(df, df_1m=None, df_5m=None, df_15m=None, df_1h=None):
392
  price_extended_high = df['close'].iloc[-1] > vwap_upper.iloc[-1]
393
  price_extended_low = df['close'].iloc[-1] < vwap_lower.iloc[-1]
394
 
395
- # --- 2. MULTI TIMEFRAME (1m, 5m, 15m, 1h) ---
396
  mtf_bull = mtf_bear = 0
397
  def analyze_tf(tf_df):
398
  if tf_df is None or len(tf_df) < 50 or 'EMA200' not in tf_df.columns: return 0
399
  slope = (tf_df['EMA200'].iloc[-1] / tf_df['EMA200'].iloc[-20]) - 1
400
  return 1 if slope > 0.0001 else (-1 if slope < -0.0001 else 0)
401
 
402
- for tf_data in [df_1m, df_5m, df_15m, df_1h]:
403
  res = analyze_tf(tf_data)
404
  if res == 1: mtf_bull += 1
405
  elif res == -1: mtf_bear += 1
406
 
407
- mtf_trend_up = mtf_bull >= 3
408
- mtf_trend_down = mtf_bear >= 3
409
-
410
  # ========================
411
  # 🔥 ORDER BLOCK STRENGTH
412
  # ========================
@@ -518,18 +513,17 @@ async def predict_signal(symbol, timeframe="1h"):
518
  oi, cvd = futures_data["oi"], futures_data["cvd"]
519
  p_sent = await get_crypto_sentiment(symbol)
520
 
521
- # 🏗️ 1.5 CHARGEMENT MULTI-TIMEFRAME (NOUVEAU)
522
- df_1m = prepare_features_sync(symbol, "1m", limit_bars=150)
523
- df_5m = prepare_features_sync(symbol, "5m", limit_bars=150)
524
  df_15m = prepare_features_sync(symbol, "15m", limit_bars=150)
525
  df_1h = prepare_features_sync(symbol, "1h", limit_bars=150)
 
526
 
527
  # 🧠 2. DÉTECTION DU SCÉNARIO (L'œil + L'IA)
528
  regime_scaled = regime_scaler.transform(last_row[["ATR_pct", "EMA200_slope", "Drawdown", "RSI_Macro"]])
529
  regime_ml = int(regime_model.predict(regime_scaled)[0])
530
 
531
- # On passe les dataframes MTF à ta fonction
532
- pattern_id = detect_chart_scenario(df, df_1m, df_5m, df_15m, df_1h)
533
  final_scenario = pattern_id if pattern_id in [4, 5] else regime_ml
534
 
535
  # 🧠 3. CALCUL DES PROBABILITÉS IA
@@ -789,7 +783,7 @@ def run_judge_api(live_prices_json="{}"):
789
  closed_trades = []
790
  watching_info = [] # 🎯 Contiendra uniquement des dicts pour le Bras
791
  current_time = datetime.now(timezone.utc)
792
- max_age_minutes = {"1m": 5, "5m": 10, "15m": 30, "1h": 60}
793
 
794
  for t in trades:
795
  try:
@@ -971,7 +965,7 @@ def trigger_training(symbol="BTC/USD"):
971
 
972
  # --- 🚀 MOTEURS AUTO-PILOTE ---
973
  AUTO_SYMBOLS = ["BTC/USD", "ETH/USD", "SOL/USD"]
974
- AUTO_TIMEFRAMES = ["1m", "5m", "15m", "1h"]
975
 
976
  def set_bot_mode(mode):
977
  global DREAM_MODE_ACTIVE
@@ -1071,7 +1065,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as iface:
1071
  reset_btn.click(fn=reset_trade_history, inputs=[], outputs=reset_out, api_name="reset_trades")
1072
 
1073
  with gr.Tab("🎯 Prédictions"):
1074
- gr.Button("Predict", variant="primary").click(fn=predict_signal, inputs=[gr.Textbox(label="Symbole", value="BTC/USD"), gr.Dropdown(choices=["1m", "5m", "15m", "1h"], value="1h")], outputs=gr.JSON())
1075
 
1076
  with gr.Tab("⚖️ Système"):
1077
  gr.Button("Judge").click(fn=run_judge_api, inputs=gr.Textbox(value="{}", visible=False), outputs=gr.JSON(), api_name="run_judge_api")
 
178
  # On initialise les réglages sur le régime 3 (RANGE/CHAOS) par défaut
179
  defaults = [
180
  # Symbol, TF, Regime, TP, SL, Score, PNL, Prob, Dist, Gen, B_TP, B_SL
 
 
181
  ('ALL', '15m', 3, 1.5, 1.0, 0, 0, 0.60, 0.003, 1, 0, 0),
182
  ('ALL', '1h', 3, 2.0, 1.5, 0, 0, 0.55, 0.005, 1, 0, 0),
183
  ('ALL', '4h', 3, 3.0, 2.0, 0, 0, 0.50, 0.008, 1, 0, 0)
 
361
 
362
  import numpy as np
363
 
364
+ def detect_chart_scenario(df, df_15m=None, df_1h=None, df_4h=None):
365
  try:
366
  # 🛠️ Fix colonnes KuCoin
367
  if 'vol' in df.columns and 'volume' not in df.columns:
 
390
  price_extended_high = df['close'].iloc[-1] > vwap_upper.iloc[-1]
391
  price_extended_low = df['close'].iloc[-1] < vwap_lower.iloc[-1]
392
 
393
+ # --- 2. MULTI TIMEFRAME MACRO (15m, 1h, 4h) ---
394
  mtf_bull = mtf_bear = 0
395
  def analyze_tf(tf_df):
396
  if tf_df is None or len(tf_df) < 50 or 'EMA200' not in tf_df.columns: return 0
397
  slope = (tf_df['EMA200'].iloc[-1] / tf_df['EMA200'].iloc[-20]) - 1
398
  return 1 if slope > 0.0001 else (-1 if slope < -0.0001 else 0)
399
 
400
+ for tf_data in [df_15m, df_1h, df_4h]:
401
  res = analyze_tf(tf_data)
402
  if res == 1: mtf_bull += 1
403
  elif res == -1: mtf_bear += 1
404
 
 
 
 
405
  # ========================
406
  # 🔥 ORDER BLOCK STRENGTH
407
  # ========================
 
513
  oi, cvd = futures_data["oi"], futures_data["cvd"]
514
  p_sent = await get_crypto_sentiment(symbol)
515
 
516
+ # 🏗️ 1.5 CHARGEMENT MULTI-TIMEFRAME MACRO
 
 
517
  df_15m = prepare_features_sync(symbol, "15m", limit_bars=150)
518
  df_1h = prepare_features_sync(symbol, "1h", limit_bars=150)
519
+ df_4h = prepare_features_sync(symbol, "4h", limit_bars=150)
520
 
521
  # 🧠 2. DÉTECTION DU SCÉNARIO (L'œil + L'IA)
522
  regime_scaled = regime_scaler.transform(last_row[["ATR_pct", "EMA200_slope", "Drawdown", "RSI_Macro"]])
523
  regime_ml = int(regime_model.predict(regime_scaled)[0])
524
 
525
+ # On passe les dataframes MTF à la fonction
526
+ pattern_id = detect_chart_scenario(df, df_15m, df_1h, df_4h)
527
  final_scenario = pattern_id if pattern_id in [4, 5] else regime_ml
528
 
529
  # 🧠 3. CALCUL DES PROBABILITÉS IA
 
783
  closed_trades = []
784
  watching_info = [] # 🎯 Contiendra uniquement des dicts pour le Bras
785
  current_time = datetime.now(timezone.utc)
786
+ max_age_minutes = {"15m": 30, "1h": 60, "4h": 240} # Le 4h expire après 4 heures
787
 
788
  for t in trades:
789
  try:
 
965
 
966
  # --- 🚀 MOTEURS AUTO-PILOTE ---
967
  AUTO_SYMBOLS = ["BTC/USD", "ETH/USD", "SOL/USD"]
968
+ AUTO_TIMEFRAMES = ["15m", "1h", "4h"]
969
 
970
  def set_bot_mode(mode):
971
  global DREAM_MODE_ACTIVE
 
1065
  reset_btn.click(fn=reset_trade_history, inputs=[], outputs=reset_out, api_name="reset_trades")
1066
 
1067
  with gr.Tab("🎯 Prédictions"):
1068
+ gr.Button("Predict", variant="primary").click(fn=predict_signal, inputs=[gr.Textbox(label="Symbole", value="BTC/USD"), gr.Dropdown(choices=["15m", "1h", "4h"], value="1h")], outputs=gr.JSON())
1069
 
1070
  with gr.Tab("⚖️ Système"):
1071
  gr.Button("Judge").click(fn=run_judge_api, inputs=gr.Textbox(value="{}", visible=False), outputs=gr.JSON(), api_name="run_judge_api")