- 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
95 lines
3.6 KiB
Python
95 lines
3.6 KiB
Python
# pragma pylint: disable=missing-docstring, invalid-name, too-few-public-methods
|
|
"""
|
|
LongShortStrategy — stratégie symétrique (futures) qui gagne dans les deux sens.
|
|
|
|
- LONG quand la tendance est haussière (EMA fast>slow, prix>EMA50, momentum +).
|
|
- SHORT quand la tendance est baissière (miroir exact).
|
|
But : ne plus subir les marchés baissiers — profiter de la baisse comme de la hausse.
|
|
Levier 1x par défaut (on isole l'edge directionnel ; le levier viendra après si robuste).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import talib.abstract as ta
|
|
from pandas import DataFrame
|
|
|
|
from freqtrade.strategy import IStrategy
|
|
|
|
|
|
class LongShortStrategy(IStrategy):
|
|
INTERFACE_VERSION = 3
|
|
timeframe = "1h"
|
|
can_short = True # futures requis
|
|
|
|
minimal_roi = {"0": 0.05, "120": 0.03, "360": 0.01, "720": 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 = 60
|
|
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 # 1x — edge directionnel pur, sans amplification
|
|
|
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe["ema_fast"] = ta.EMA(dataframe, timeperiod=9)
|
|
dataframe["ema_slow"] = ta.EMA(dataframe, timeperiod=21)
|
|
dataframe["ema_trend"] = ta.EMA(dataframe, timeperiod=50)
|
|
dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
|
|
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
# LONG : croisement haussier + tendance MT haussière + tendance forte
|
|
dataframe.loc[
|
|
(
|
|
(dataframe["ema_fast"] > dataframe["ema_slow"])
|
|
& (dataframe["ema_fast"].shift(1) <= dataframe["ema_slow"].shift(1))
|
|
& (dataframe["close"] > dataframe["ema_trend"])
|
|
& (dataframe["adx"] > 20)
|
|
& (dataframe["rsi"] > 45)
|
|
& (dataframe["rsi"] < 75)
|
|
& (dataframe["volume"] > 0)
|
|
),
|
|
"enter_long",
|
|
] = 1
|
|
# SHORT : miroir exact
|
|
dataframe.loc[
|
|
(
|
|
(dataframe["ema_fast"] < dataframe["ema_slow"])
|
|
& (dataframe["ema_fast"].shift(1) >= dataframe["ema_slow"].shift(1))
|
|
& (dataframe["close"] < dataframe["ema_trend"])
|
|
& (dataframe["adx"] > 20)
|
|
& (dataframe["rsi"] < 55)
|
|
& (dataframe["rsi"] > 25)
|
|
& (dataframe["volume"] > 0)
|
|
),
|
|
"enter_short",
|
|
] = 1
|
|
return dataframe
|
|
|
|
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
# Sortie LONG : la tendance courte se retourne à la baisse
|
|
dataframe.loc[
|
|
(
|
|
(dataframe["ema_fast"] < dataframe["ema_slow"])
|
|
& (dataframe["ema_fast"].shift(1) >= dataframe["ema_slow"].shift(1))
|
|
& (dataframe["volume"] > 0)
|
|
),
|
|
"exit_long",
|
|
] = 1
|
|
# Sortie SHORT : la tendance courte se retourne à la hausse
|
|
dataframe.loc[
|
|
(
|
|
(dataframe["ema_fast"] > dataframe["ema_slow"])
|
|
& (dataframe["ema_fast"].shift(1) <= dataframe["ema_slow"].shift(1))
|
|
& (dataframe["volume"] > 0)
|
|
),
|
|
"exit_short",
|
|
] = 1
|
|
return dataframe
|