MidasBot: bot trading crypto IA + stratégies Ichimoku validées

- Infra: Freqtrade (futures dry-run) + Redis + dashboard + Docker Compose
- Couche IA: ai_analyzer (Claude via abonnement, MCP TradingView, backfill biais)
- Stratégies: SampleStrategy, AiBiasStrategy, IchimokuLS (long/short, validée
  train/test + données vierges + walk-forward), MTFIchimoku, variantes hyperopt
- Arbitrage CEX (dry-run), backtesting, walk-forward, volatility targeting
- IchimokuLS en dry-run live (config_live.json)

Claude-Session: https://claude.ai/code/session_01VHETcFacdnDhQzthLpdYFR
This commit is contained in:
jerem
2026-06-23 19:25:49 +02:00
commit 633b033f4d
59 changed files with 3868 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
# pragma pylint: disable=missing-docstring, invalid-name, too-few-public-methods
"""
IchimokuHyperVol — IchimokuHyper + VOLATILITY TARGETING (sizing dynamique).
Même logique d'entrée/sortie qu'IchimokuHyper. Seule différence : la TAILLE de
position s'ajuste à l'inverse de la volatilité récente (ATR%) :
vol haute → position réduite → pertes bornées (notamment dans le chop volatil)
vol normale→ pleine taille → gains préservés en tendance
Contrôle de risque DYNAMIQUE et non-prédictif (pas de filtre de régime overfit).
Référence de vol = médiane glissante de l'ATR% (trailing → pas de fuite du futur).
"""
from __future__ import annotations
import numpy as np
import talib.abstract as ta
from pandas import DataFrame
from freqtrade.strategy import (
IStrategy,
IntParameter,
DecimalParameter,
BooleanParameter,
)
class IchimokuHyperVol(IStrategy):
INTERFACE_VERSION = 3
timeframe = "1h"
can_short = True
minimal_roi = {"0": 0.08, "240": 0.04, "720": 0.02, "1440": 0}
stoploss = -0.08
trailing_stop = True
trailing_stop_positive = 0.02
trailing_stop_positive_offset = 0.03
trailing_only_offset_is_reached = True
startup_candle_count: int = 520 # médiane ATR% sur 500 + Ichimoku
process_only_new_candles = True
use_exit_signal = True
buy_adx_min = IntParameter(15, 40, default=25, space="buy", optimize=True)
buy_cloud_min_pct = DecimalParameter(0.0, 2.0, default=0.3, decimals=2, space="buy", optimize=True)
require_tk_cross = BooleanParameter(default=False, space="buy", optimize=True)
# Bornes du facteur de sizing (réduit jusqu'à 0.4x, augmente jusqu'à 1.4x)
VOL_FACTOR_MIN = 0.4
VOL_FACTOR_MAX = 1.4
def leverage(self, pair, current_time, current_rate, proposed_leverage,
max_leverage, entry_tag, side, **kwargs) -> float:
return 1.0
def custom_stake_amount(self, pair, current_time, current_rate, proposed_stake,
min_stake, max_stake, leverage, entry_tag, side, **kwargs):
df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if df is None or len(df) == 0:
return proposed_stake
factor = df["vol_factor"].iat[-1]
if factor is None or not np.isfinite(factor):
return proposed_stake
stake = proposed_stake * float(factor)
if min_stake is not None:
stake = max(stake, min_stake)
return min(stake, max_stake)
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
high, low, close = dataframe["high"], dataframe["low"], dataframe["close"]
tenkan = (high.rolling(9).max() + low.rolling(9).min()) / 2
kijun = (high.rolling(26).max() + low.rolling(26).min()) / 2
dataframe["tenkan"] = tenkan
dataframe["kijun"] = kijun
dataframe["senkou_a"] = ((tenkan + kijun) / 2).shift(26)
dataframe["senkou_b"] = ((high.rolling(52).max() + low.rolling(52).min()) / 2).shift(26)
dataframe["cloud_top"] = dataframe[["senkou_a", "senkou_b"]].max(axis=1)
dataframe["cloud_bot"] = dataframe[["senkou_a", "senkou_b"]].min(axis=1)
dataframe["cloud_width_pct"] = (dataframe["cloud_top"] - dataframe["cloud_bot"]) / close * 100
dataframe["close_prev26"] = close.shift(26)
dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
# --- Volatility targeting ---
atr_pct = ta.ATR(dataframe, timeperiod=14) / close * 100
atr_ref = atr_pct.rolling(500).median() # vol "normale" (trailing)
factor = (atr_ref / atr_pct).clip(self.VOL_FACTOR_MIN, self.VOL_FACTOR_MAX)
dataframe["vol_factor"] = factor.fillna(1.0)
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
adx_min = self.buy_adx_min.value
cloud_min = self.buy_cloud_min_pct.value
long_cond = (
(dataframe["close"] > dataframe["cloud_top"])
& (dataframe["tenkan"] > dataframe["kijun"])
& (dataframe["close"] > dataframe["close_prev26"])
& (dataframe["adx"] > adx_min)
& (dataframe["cloud_width_pct"] > cloud_min)
& (dataframe["volume"] > 0)
)
short_cond = (
(dataframe["close"] < dataframe["cloud_bot"])
& (dataframe["tenkan"] < dataframe["kijun"])
& (dataframe["close"] < dataframe["close_prev26"])
& (dataframe["adx"] > adx_min)
& (dataframe["cloud_width_pct"] > cloud_min)
& (dataframe["volume"] > 0)
)
if self.require_tk_cross.value:
long_cond &= dataframe["tenkan"].shift(1) <= dataframe["kijun"].shift(1)
short_cond &= dataframe["tenkan"].shift(1) >= dataframe["kijun"].shift(1)
dataframe.loc[long_cond, "enter_long"] = 1
dataframe.loc[short_cond, "enter_short"] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(((dataframe["tenkan"] < dataframe["kijun"]) | (dataframe["close"] < dataframe["cloud_bot"]))
& (dataframe["volume"] > 0)),
"exit_long",
] = 1
dataframe.loc[
(((dataframe["tenkan"] > dataframe["kijun"]) | (dataframe["close"] > dataframe["cloud_top"]))
& (dataframe["volume"] > 0)),
"exit_short",
] = 1
return dataframe