Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -531,6 +531,16 @@ def detect_chart_scenario(df, df_1m=None, df_5m=None, df_15m=None, df_1h=None):
|
|
| 531 |
vwap = (typical_price * df['volume']).cumsum() / (df['volume'].cumsum() + 1e-9)
|
| 532 |
price_above_vwap = df['close'].iloc[-1] > vwap.iloc[-1]
|
| 533 |
price_below_vwap = df['close'].iloc[-1] < vwap.iloc[-1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
# --- 2. MULTI TIMEFRAME (1m, 5m, 15m, 1h) ---
|
| 536 |
mtf_bull = mtf_bear = 0
|
|
@@ -547,19 +557,46 @@ def detect_chart_scenario(df, df_1m=None, df_5m=None, df_15m=None, df_1h=None):
|
|
| 547 |
mtf_trend_up = mtf_bull >= 3
|
| 548 |
mtf_trend_down = mtf_bear >= 3
|
| 549 |
|
| 550 |
-
#
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
for i in range(len(last_candles) - 3):
|
| 554 |
-
c1
|
| 555 |
-
|
| 556 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
# --- 4. LIQUIDITY SWEEP ---
|
| 559 |
recent_high, prev_high = np.max(h[-10:]), np.max(h[-30:-10])
|
| 560 |
recent_low, prev_low = np.min(l[-10:]), np.min(l[-30:-10])
|
| 561 |
liquidity_sweep_high = recent_high > prev_high and c[-1] < recent_high
|
| 562 |
liquidity_sweep_low = recent_low < prev_low and c[-1] > recent_low
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
# --- 5. STRUCTURE ET RSI ---
|
| 565 |
range_start, range_end = np.mean(h[:20] - l[:20]), np.mean(h[-20:] - l[-20:])
|
|
@@ -582,18 +619,30 @@ def detect_chart_scenario(df, df_1m=None, df_5m=None, df_15m=None, df_1h=None):
|
|
| 582 |
vol_recent, vol_past = np.mean(v[-15:]), np.mean(v[-40:-15])
|
| 583 |
vol_inc = vol_recent > vol_past * 1.2
|
| 584 |
|
| 585 |
-
#
|
| 586 |
-
if squeeze and trend_strength > 0.004 and price_above_vwap and mtf_trend_up
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
if
|
| 591 |
-
|
| 592 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
|
| 594 |
-
if vol_inc:
|
| 595 |
-
|
| 596 |
-
if bos_down and price_below_vwap: return 1
|
| 597 |
|
| 598 |
return 3 # RANGE / CHAOS par défaut
|
| 599 |
except Exception as e:
|
|
|
|
| 531 |
vwap = (typical_price * df['volume']).cumsum() / (df['volume'].cumsum() + 1e-9)
|
| 532 |
price_above_vwap = df['close'].iloc[-1] > vwap.iloc[-1]
|
| 533 |
price_below_vwap = df['close'].iloc[-1] < vwap.iloc[-1]
|
| 534 |
+
# ========================
|
| 535 |
+
# 🔥 VWAP BANDS (Institutional zones)
|
| 536 |
+
# ========================
|
| 537 |
+
vwap_std = df['close'].rolling(20).std()
|
| 538 |
+
vwap_upper = vwap + vwap_std
|
| 539 |
+
vwap_lower = vwap - vwap_std
|
| 540 |
+
|
| 541 |
+
price_extended_high = df['close'].iloc[-1] > vwap_upper.iloc[-1]
|
| 542 |
+
price_extended_low = df['close'].iloc[-1] < vwap_lower.iloc[-1]
|
| 543 |
+
|
| 544 |
|
| 545 |
# --- 2. MULTI TIMEFRAME (1m, 5m, 15m, 1h) ---
|
| 546 |
mtf_bull = mtf_bear = 0
|
|
|
|
| 557 |
mtf_trend_up = mtf_bull >= 3
|
| 558 |
mtf_trend_down = mtf_bear >= 3
|
| 559 |
|
| 560 |
+
# ========================
|
| 561 |
+
# 🔥 ORDER BLOCK STRENGTH
|
| 562 |
+
# ========================
|
| 563 |
+
bullish_ob = False
|
| 564 |
+
bearish_ob = False
|
| 565 |
+
ob_strength = 0
|
| 566 |
+
|
| 567 |
for i in range(len(last_candles) - 3):
|
| 568 |
+
c1 = last_candles.iloc[i]
|
| 569 |
+
c2 = last_candles.iloc[i + 1]
|
| 570 |
+
|
| 571 |
+
body_size = abs(c2['close'] - c2['open'])
|
| 572 |
+
candle_range = c2['high'] - c2['low'] + 1e-9
|
| 573 |
+
|
| 574 |
+
strength = body_size / candle_range
|
| 575 |
+
|
| 576 |
+
if c1['close'] < c1['open'] and c2['close'] > c2['open']:
|
| 577 |
+
bullish_ob = True
|
| 578 |
+
ob_strength = max(ob_strength, strength)
|
| 579 |
+
|
| 580 |
+
if c1['close'] > c1['open'] and c2['close'] < c2['open']:
|
| 581 |
+
bearish_ob = True
|
| 582 |
+
ob_strength = max(ob_strength, strength)
|
| 583 |
|
| 584 |
# --- 4. LIQUIDITY SWEEP ---
|
| 585 |
recent_high, prev_high = np.max(h[-10:]), np.max(h[-30:-10])
|
| 586 |
recent_low, prev_low = np.min(l[-10:]), np.min(l[-30:-10])
|
| 587 |
liquidity_sweep_high = recent_high > prev_high and c[-1] < recent_high
|
| 588 |
liquidity_sweep_low = recent_low < prev_low and c[-1] > recent_low
|
| 589 |
+
liquidity_high_zone = np.mean(h[-50:])
|
| 590 |
+
liquidity_low_zone = np.mean(l[-50:])
|
| 591 |
+
|
| 592 |
+
near_liquidity_high = abs(c[-1] - liquidity_high_zone) / c[-1] < 0.002
|
| 593 |
+
near_liquidity_low = abs(c[-1] - liquidity_low_zone) / c[-1] < 0.002
|
| 594 |
+
|
| 595 |
+
# ========================
|
| 596 |
+
# 🔥 FAKE BREAKOUT FILTER
|
| 597 |
+
# ========================
|
| 598 |
+
fake_breakout_up = bos_up and c[-1] < recent_high
|
| 599 |
+
fake_breakout_down = bos_down and c[-1] > recent_low
|
| 600 |
|
| 601 |
# --- 5. STRUCTURE ET RSI ---
|
| 602 |
range_start, range_end = np.mean(h[:20] - l[:20]), np.mean(h[-20:] - l[-20:])
|
|
|
|
| 619 |
vol_recent, vol_past = np.mean(v[-15:]), np.mean(v[-40:-15])
|
| 620 |
vol_inc = vol_recent > vol_past * 1.2
|
| 621 |
|
| 622 |
+
# 🔥 CONTINUATION PRO MAX
|
| 623 |
+
if squeeze and trend_strength > 0.004 and price_above_vwap and mtf_trend_up and not price_extended_high:
|
| 624 |
+
return 4
|
| 625 |
+
|
| 626 |
+
# 🔴 REVERSAL SMART MONEY
|
| 627 |
+
if (liquidity_sweep_high or bearish_ob or bearish_div or price_extended_high or near_liquidity_high) and trend_up:
|
| 628 |
+
return 5
|
| 629 |
+
|
| 630 |
+
if (liquidity_sweep_low or bullish_ob or bullish_div or price_extended_low or near_liquidity_low) and trend_down:
|
| 631 |
+
return 5
|
| 632 |
+
|
| 633 |
+
# 🟢 TREND INSTITUTIONNEL
|
| 634 |
+
if trend_strength > 0.006 and vol_inc and ob_strength > 0.5:
|
| 635 |
+
if price_above_vwap and mtf_trend_up and not fake_breakout_up:
|
| 636 |
+
return 0
|
| 637 |
+
if price_below_vwap and mtf_trend_down and not fake_breakout_down:
|
| 638 |
+
return 1
|
| 639 |
+
|
| 640 |
+
# 🟡 BREAKOUT PROPRE
|
| 641 |
+
if vol_inc and not fake_breakout_up and bos_up and price_above_vwap:
|
| 642 |
+
return 0
|
| 643 |
|
| 644 |
+
if vol_inc and not fake_breakout_down and bos_down and price_below_vwap:
|
| 645 |
+
return 1
|
|
|
|
| 646 |
|
| 647 |
return 3 # RANGE / CHAOS par défaut
|
| 648 |
except Exception as e:
|