Backtest re-run após 2 fixes estruturais

Dois bugs descobertos ao investigar por que 4 strategies ficavam com 0 trades no backtest (legacy_rules, breakout, bollinger_breakout, stochastic).

Bug 1 — breakout.py matematicamente impossível

# Antes: close.iloc[-2] comparado contra rolling max que INCLUI high.iloc[-2]
rh = recent_high(high, BREAKOUT_PERIOD + 1)  # max de 21 bars ending no bar -2
last_close = float(close.iloc[-2])           # close do bar -2
if last_close > hi:  # impossível: close ≤ high sempre

Fix: recent_high(high, BREAKOUT_PERIOD) (20, sem +1) + close.iloc[-1]. Agora compara o just-closed contra max dos 20 bars anteriores. breakout.py saiu de 0/115 para 12/115 sinais em BTC 1d.

Bug 2 — R:R gate estrangula 3 strategies

compute_size rejeita trades quando rr_net < min_rr (1.5). Com TARGET_R=1.5 + stop 2% + fees round-trip 0.15%:

rr_net = (3% - 0.15%) / (2% + 0.15%) = 1.33 < 1.5  ❌

legacy_rules emitia 46 sinais/ano em BTC mas TODOS rejeitados. Mesmo padrão em stochastic.py e bollinger_v2.py.

Fix: bump TARGET_R 1.5 → 1.8 em stochastic/bollinger_v2 + bump fixed_target_r default do engine 1.5 → 1.8. Net RR ≈ 1.55 ≥ 1.5 ✅.

Impacto no matrix

BTCUSDT · 1d · 365d

strategy antes depois
legacy_rules 0 trades 24 trades, +11.5%, wr 46% 🥇
stochastic 0 trades 5 trades, +4.3%, wr 60%
bollinger_breakout 0 trades 9 trades, -2.5%, wr 33%
breakout 0 trades 6 trades, -14.4%, wr 33% (n pequeno)
stormia_full_engine 24t -14.2% 28t -0.8% (melhora)
bollinger_reversion 5t +8.3% 7t +1.0%

Vencedor BTC 1d pós-fix: legacy_rules (do nada para +11.5% com n=24).

ETHUSDT · 1d · 365d

strategy antes depois
breakout 0 trades 3 trades, +20.8%, wr 67% 🥇 (n pequeno)
stochastic 0 trades 7 trades, +5.2%, wr 57%
legacy_rules 0 trades 25 trades, +7.8%, wr 44%
stormia_full_engine 24t +10.6% 24t +6.2% (piorou um pouco, mas estável)
pullback 8t -26.4% 8t -27.4%

XRPUSDT · 1d · 365d

strategy antes depois
stormia_full_engine 18t -5.8% 22 trades, +16.0%, wr 32% 🥇
bollinger_reversion 3t -10.2% 4t +10.8%, wr 25%
bollinger_breakout 0 trades 16 trades, +4.8%, wr 44%
stochastic 0 trades 3 trades, +3.5%, wr 67%
legacy_rules 0 trades 24 trades, +0.9%, wr 38%
ifr2_with_mm200 20t +7.0% 20t +7.0% (estável, ignora TARGET_R)

BTCUSDT · 4h · 180d — novo melhor resultado global

strategy n wr return exp sharpe
stormia_full_engine 108 44% +36.7% +0.340% +1.50 🥇
pullback 21 38% +24.9% +1.184% +0.84
legacy_rules 71 41% +11.8% +0.167% +0.51
stochastic 46 43% +6.7% +0.146% +0.48
bollinger_breakout 55 42% +7.3% +0.133% +0.36

🏆 Vencedores pós-fix

ranking símbolo · TF estratégia return wr n
🥇 BTCUSDT · 4h stormia_full_engine +36.7% 44% 108
🥈 BTCUSDT · 4h pullback +24.9% 38% 21
🥉 XRPUSDT · 4h bollinger_breakout +21.3% 44% 63
4 ETHUSDT · 1d breakout +20.8% 67% 3 ⚠️ n pequeno
5 XRPUSDT · 4h legacy_rules +17.4% 43% 79
6 XRPUSDT · 1d stormia_full_engine +16.0% 32% 22
7 XRPUSDT · 4h bollinger_reversion +14.8% 34% 61
8 ETHUSDT · 4h stochastic +8.1% 43% 46
9 BTCUSDT · 4h bollinger_breakout +7.3% 42% 55
10 XRPUSDT · 4h breakout +7.5% 32% 19

Destaques

  1. Stormia multi-TF em BTC 4h +36.7% com 108 trades e sharpe 1.50. O mais robusto setup do matrix (n alto, wr 44%, R:R 3:1).
  2. Legacy rules renascida — do nada para top-3 em BTC 1d e presente em 5/6 posições positivas no 4h.
  3. Stormia XRP 1d virou de -5.8% para +16.0% — a nova threshold TF-aware destravou o engine, e agora o R:R 1.8 mantém os trades vivos.
  4. TFs 4h continua sendo o sweet spot — return médio por strategy 2-3× maior que 1d.

Cuidados

Próximos experimentos

  1. Walk-forward em BTC 4h stormia_full_engine — a +36.7% é real ou overfit a esse windowseven? Janela rolando 60/30.
  2. Backtest 2 anos em 1d pra validar que edge sobrevive a regimes mais diversos (bull 2024 + crash 2024 + bull 2025).
  3. Filtrar ifr2 por regime — só disparar em ranging.
  4. Adicionar SOL/BNB/ADA — generalização para 6 símbolos.
  5. Combinação: rodar stormia_full_engine em 4h como principal + legacy em 1d como secundário num portfolio multi-strategy.

Fontes

Cross-references

Entities: [[../entities/BTCUSDT]], [[../entities/XRPUSDT]] Strategies: [[../strategy/bollinger_breakout]] Regimes: [[../regimes/ranging]]