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/IchimokuStrategy.py
Normal file
117
freqtrade/user_data/strategies/IchimokuStrategy.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, too-few-public-methods
|
||||
"""
|
||||
IchimokuStrategy — long/short basé sur Ichimoku Kinko Hyo (futures).
|
||||
|
||||
Composants :
|
||||
Tenkan-sen (9), Kijun-sen (26), Senkou A/B (nuage/Kumo), confirmation type Chikou.
|
||||
|
||||
Signaux :
|
||||
LONG : prix au-dessus du nuage + croisement Tenkan>Kijun + momentum (close > close[-26]).
|
||||
SHORT : miroir exact (prix sous le nuage + Tenkan<Kijun + close < close[-26]).
|
||||
|
||||
⚠️ Anti-lookahead : les Senkou sont décalés de +26 (donnée passée projetée au présent),
|
||||
la confirmation "Chikou" utilise close vs close d'il y a 26 bougies (pas de futur).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.strategy import IStrategy
|
||||
|
||||
|
||||
class IchimokuStrategy(IStrategy):
|
||||
INTERFACE_VERSION = 3
|
||||
timeframe = "1h"
|
||||
can_short = True
|
||||
|
||||
minimal_roi = {"0": 0.06, "240": 0.03, "720": 0.01, "1440": 0}
|
||||
stoploss = -0.08
|
||||
trailing_stop = True
|
||||
trailing_stop_positive = 0.025
|
||||
trailing_stop_positive_offset = 0.04
|
||||
trailing_only_offset_is_reached = True
|
||||
|
||||
startup_candle_count: int = 120 # 52 (Senkou B) + 26 (décalage) + marge
|
||||
process_only_new_candles = True
|
||||
use_exit_signal = True
|
||||
|
||||
def leverage(self, pair, current_time, current_rate, proposed_leverage,
|
||||
max_leverage, entry_tag, side, **kwargs) -> float:
|
||||
return 1.0 # edge directionnel pur
|
||||
|
||||
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
|
||||
|
||||
# Senkou décalés de +26 : valeur du nuage au présent issue de données passées.
|
||||
dataframe["senkou_a"] = ((tenkan + kijun) / 2).shift(26)
|
||||
dataframe["senkou_b"] = (
|
||||
(high.rolling(52).max() + low.rolling(52).min()) / 2
|
||||
).shift(26)
|
||||
|
||||
# Bornes du nuage
|
||||
dataframe["cloud_top"] = dataframe[["senkou_a", "senkou_b"]].max(axis=1)
|
||||
dataframe["cloud_bot"] = dataframe[["senkou_a", "senkou_b"]].min(axis=1)
|
||||
|
||||
# Confirmation momentum type Chikou (close vs close d'il y a 26 bougies)
|
||||
dataframe["close_prev26"] = close.shift(26)
|
||||
|
||||
dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
|
||||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
# LONG : au-dessus du nuage + croisement TK haussier + momentum
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe["close"] > dataframe["cloud_top"])
|
||||
& (dataframe["tenkan"] > dataframe["kijun"])
|
||||
& (dataframe["tenkan"].shift(1) <= dataframe["kijun"].shift(1))
|
||||
& (dataframe["close"] > dataframe["close_prev26"])
|
||||
& (dataframe["adx"] > 20)
|
||||
& (dataframe["volume"] > 0)
|
||||
),
|
||||
"enter_long",
|
||||
] = 1
|
||||
# SHORT : sous le nuage + croisement TK baissier + momentum baissier
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe["close"] < dataframe["cloud_bot"])
|
||||
& (dataframe["tenkan"] < dataframe["kijun"])
|
||||
& (dataframe["tenkan"].shift(1) >= dataframe["kijun"].shift(1))
|
||||
& (dataframe["close"] < dataframe["close_prev26"])
|
||||
& (dataframe["adx"] > 20)
|
||||
& (dataframe["volume"] > 0)
|
||||
),
|
||||
"enter_short",
|
||||
] = 1
|
||||
return dataframe
|
||||
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
# Sortie LONG : Tenkan repasse sous Kijun, ou prix replonge dans le nuage
|
||||
dataframe.loc[
|
||||
(
|
||||
(
|
||||
(dataframe["tenkan"] < dataframe["kijun"])
|
||||
| (dataframe["close"] < dataframe["cloud_bot"])
|
||||
)
|
||||
& (dataframe["volume"] > 0)
|
||||
),
|
||||
"exit_long",
|
||||
] = 1
|
||||
# Sortie SHORT : Tenkan repasse au-dessus de Kijun, ou prix remonte dans le nuage
|
||||
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