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:
117
freqtrade/user_data/strategies/IchimokuHyper3.py
Normal file
117
freqtrade/user_data/strategies/IchimokuHyper3.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, too-few-public-methods
|
||||
"""
|
||||
IchimokuHyper3 — espace de paramètres ÉLARGI (périodes Ichimoku optimisables).
|
||||
|
||||
Round 3 de la boucle d'optimisation : on donne plus de liberté à l'optimiseur
|
||||
(Tenkan/Kijun/Senkou B + lookback momentum + filtres) pour pousser le gain.
|
||||
⚠️ Plus de paramètres = plus de capacité d'overfitting (le gain in-sample monte,
|
||||
mais l'OOS sera à surveiller).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.strategy import (
|
||||
IStrategy,
|
||||
IntParameter,
|
||||
DecimalParameter,
|
||||
BooleanParameter,
|
||||
)
|
||||
|
||||
|
||||
class IchimokuHyper3(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 = 260
|
||||
process_only_new_candles = True
|
||||
use_exit_signal = True
|
||||
|
||||
# Périodes Ichimoku optimisables
|
||||
p_tenkan = IntParameter(5, 20, default=9, space="buy", optimize=True)
|
||||
p_kijun = IntParameter(15, 45, default=26, space="buy", optimize=True)
|
||||
p_senkou = IntParameter(40, 90, default=52, space="buy", optimize=True)
|
||||
p_shift = IntParameter(15, 40, default=26, space="buy", optimize=True)
|
||||
p_mom = IntParameter(10, 40, default=26, space="buy", optimize=True)
|
||||
# Filtres
|
||||
buy_adx_min = IntParameter(10, 40, default=20, 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)
|
||||
use_macro = BooleanParameter(default=False, space="buy", optimize=True)
|
||||
|
||||
def leverage(self, pair, current_time, current_rate, proposed_leverage,
|
||||
max_leverage, entry_tag, side, **kwargs) -> float:
|
||||
return 1.0
|
||||
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
high, low, close = dataframe["high"], dataframe["low"], dataframe["close"]
|
||||
t, k, s, sh = (
|
||||
self.p_tenkan.value, self.p_kijun.value,
|
||||
self.p_senkou.value, self.p_shift.value,
|
||||
)
|
||||
tenkan = (high.rolling(t).max() + low.rolling(t).min()) / 2
|
||||
kijun = (high.rolling(k).max() + low.rolling(k).min()) / 2
|
||||
dataframe["tenkan"] = tenkan
|
||||
dataframe["kijun"] = kijun
|
||||
dataframe["senkou_a"] = ((tenkan + kijun) / 2).shift(sh)
|
||||
dataframe["senkou_b"] = ((high.rolling(s).max() + low.rolling(s).min()) / 2).shift(sh)
|
||||
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_prev"] = close.shift(self.p_mom.value)
|
||||
dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
|
||||
dataframe["ema200"] = ta.EMA(dataframe, timeperiod=200)
|
||||
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_prev"])
|
||||
& (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_prev"])
|
||||
& (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)
|
||||
if self.use_macro.value:
|
||||
long_cond &= dataframe["close"] > dataframe["ema200"]
|
||||
short_cond &= dataframe["close"] < dataframe["ema200"]
|
||||
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
|
||||
Reference in New Issue
Block a user