Bearische Trading-Strategie
Timeframe
1h
Direction
Long Only
Stoploss
-3.0%
Trailing Stop
No
ROI
0m: 2.5%, 15m: 1.5%, 30m: 1.0%
Interface Version
3
Startup Candles
N/A
Indicators
12
freqtrade/freqtrade-strategies
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
"""
Bearish Trading Strategy für das Crypto Multi-Agent System
Optimiert für bearische Marktphasen
"""
import talib.abstract as ta
from freqtrade.strategy import IStrategy, DecimalParameter, IntParameter
from pandas import DataFrame
import numpy as np
from functools import reduce
from datetime import timedelta
class StrategyBearish(IStrategy):
"""
Bearische Trading-Strategie
Diese Strategie ist optimiert für bearische Marktphasen und wird
vom Multi-Agent System aktiviert, wenn bearische Signale erkannt werden.
Fokus auf Short-Positionen und defensive Trades.
"""
# Strategy interface version
INTERFACE_VERSION = 3
# Minimal ROI designed for bearish markets (schnellere Gewinnmitnahme)
minimal_roi = {
"30": 0.01, # 1% nach 30 Minuten
"15": 0.015, # 1.5% nach 15 Minuten
"0": 0.025 # 2.5% sofort
}
# Tighter stoploss for bearish markets
stoploss = -0.03 # 3% Stoploss (enger als bullish)
# Optimal timeframe for the strategy
timeframe = '1h'
# Run "populate_indicators" only for new candle
process_only_new_candles = True
# These values can be overridden in the config
use_exit_signal = True
exit_profit_only = False
ignore_roi_if_entry_signal = False
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 30
# Optional order type mapping
order_types = {
'entry': 'limit',
'exit': 'limit',
'stoploss': 'market',
'stoploss_on_exchange': False
}
# Optional order time in force
order_time_in_force = {
'entry': 'gtc',
'exit': 'gtc'
}
# Hyperopt parameters für bearish strategy
buy_rsi_threshold = IntParameter(15, 35, default=25, space="buy")
buy_bb_threshold = DecimalParameter(0.05, 0.3, default=0.15, space="buy")
sell_rsi_threshold = IntParameter(55, 75, default=65, space="sell")
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Fügt Indikatoren zum Dataframe hinzu (bearish optimiert)
"""
# RSI
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
# MACD
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
# Bollinger Bands
bollinger = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2, nbdevdn=2)
dataframe['bb_lowerband'] = bollinger['lowerband']
dataframe['bb_middleband'] = bollinger['middleband']
dataframe['bb_upperband'] = bollinger['upperband']
dataframe['bb_percent'] = (dataframe['close'] - dataframe['bb_lowerband']) / (dataframe['bb_upperband'] - dataframe['bb_lowerband'])
dataframe['bb_width'] = (dataframe['bb_upperband'] - dataframe['bb_lowerband']) / dataframe['bb_middleband']
# EMA (für Trend-Erkennung)
dataframe['ema_9'] = ta.EMA(dataframe, timeperiod=9)
dataframe['ema_21'] = ta.EMA(dataframe, timeperiod=21)
dataframe['ema_50'] = ta.EMA(dataframe, timeperiod=50)
# SMA
dataframe['sma_20'] = ta.SMA(dataframe, timeperiod=20)
# Volume indicators
dataframe['volume_sma'] = ta.SMA(dataframe['volume'], timeperiod=20)
dataframe['volume_ratio'] = dataframe['volume'] / dataframe['volume_sma']
# ADX (Average Directional Index)
dataframe['adx'] = ta.ADX(dataframe, timeperiod=14)
# Stochastic
stoch = ta.STOCH(dataframe)
dataframe['stoch_k'] = stoch['slowk']
dataframe['stoch_d'] = stoch['slowd']
# Williams %R
dataframe['williams_r'] = ta.WILLR(dataframe, timeperiod=14)
# CCI (Commodity Channel Index)
dataframe['cci'] = ta.CCI(dataframe, timeperiod=20)
# Parabolic SAR
dataframe['sar'] = ta.SAR(dataframe)
# Money Flow Index
dataframe['mfi'] = ta.MFI(dataframe, timeperiod=14)
# Rate of Change
dataframe['roc'] = ta.ROC(dataframe, timeperiod=10)
# Support/Resistance Levels
dataframe['support'] = dataframe['low'].rolling(window=20).min()
dataframe['resistance'] = dataframe['high'].rolling(window=20).max()
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Bearische Entry-Signale (Oversold Bounces in bearish market)
"""
conditions = []
# Oversold Bedingungen für Bounce-Trades
conditions.append(dataframe['rsi'] < self.buy_rsi_threshold.value)
# Bollinger Bands - nahe unterer Grenze
conditions.append(dataframe['bb_percent'] < self.buy_bb_threshold.value)
# Stochastic oversold
conditions.append(
(dataframe['stoch_k'] < 20) &
(dataframe['stoch_d'] < 20)
)
# Williams %R oversold
conditions.append(dataframe['williams_r'] < -80)
# CCI oversold
conditions.append(dataframe['cci'] < -100)
# Volume-Bestätigung (erhöhtes Volumen bei Oversold)
conditions.append(dataframe['volume_ratio'] > 1.2)
# Preis nahe Support
conditions.append(
dataframe['close'] <= (dataframe['support'] * 1.02) # 2% über Support
)
# MACD zeigt mögliche Umkehr
conditions.append(
(dataframe['macd'] > dataframe['macd'].shift(1)) & # MACD steigt
(dataframe['macd'] < 0) # aber noch negativ
)
# Money Flow Index oversold
conditions.append(dataframe['mfi'] < 20)
# Rate of Change zeigt Verlangsamung des Abwärtstrends
conditions.append(
(dataframe['roc'] > dataframe['roc'].shift(1)) & # ROC verbessert sich
(dataframe['roc'] < 0) # aber noch negativ
)
# Kombiniere alle Bedingungen (mindestens 6 von 10 müssen erfüllt sein)
if conditions:
condition_sum = sum(conditions)
dataframe.loc[
condition_sum >= 6,
'enter_long'
] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Bearische Exit-Signale (schnelle Gewinnmitnahme)
"""
conditions = []
# RSI erreicht moderate Levels (nicht überkauft warten)
conditions.append(dataframe['rsi'] > self.sell_rsi_threshold.value)
# Bollinger Bands - mittlere oder obere Region
conditions.append(dataframe['bb_percent'] > 0.6)
# Stochastic zeigt Überkauft-Signale
conditions.append(
(dataframe['stoch_k'] > 70) |
(dataframe['stoch_d'] > 70)
)
# Williams %R zeigt Überkauft
conditions.append(dataframe['williams_r'] > -30)
# Preis erreicht EMA21 (Widerstand in bearish market)
conditions.append(dataframe['close'] >= dataframe['ema_21'])
# MACD zeigt Schwäche
conditions.append(
(dataframe['macd'] < dataframe['macdsignal']) |
(dataframe['macd'] < dataframe['macd'].shift(1))
)
# Preis nahe Widerstand
conditions.append(
dataframe['close'] >= (dataframe['resistance'] * 0.98) # 2% unter Widerstand
)
# Volume abnimmt (schwächere Aufwärtsbewegung)
conditions.append(
(dataframe['volume_ratio'] < 0.8) &
(dataframe['close'] > dataframe['close'].shift(1))
)
# Money Flow Index zeigt Überkauft
conditions.append(dataframe['mfi'] > 70)
# Parabolic SAR Flip
conditions.append(dataframe['close'] < dataframe['sar'])
# Exit wenn eine der wichtigeren Bedingungen erfüllt ist
important_conditions = [
conditions[0], # RSI
conditions[1], # BB
conditions[4], # EMA21
conditions[5], # MACD
conditions[6], # Widerstand
]
if important_conditions:
dataframe.loc[
reduce(lambda x, y: x | y, important_conditions),
'exit_long'
] = 1
return dataframe
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: 'datetime',
current_rate: float, current_profit: float, **kwargs) -> float:
"""
Dynamischer Stoploss für bearische Strategie (aggressiver)
"""
# Sehr schneller Trailing Stoploss in bearish markets
if current_time - trade.open_date_utc >= timedelta(minutes=15):
if current_profit > 0.015: # 1.5% Gewinn
return -0.005 # Sehr enger Trailing auf 0.5%
elif current_profit > 0.01: # 1% Gewinn
return -0.01 # Trailing auf 1%
# Noch engerer Standard Stoploss nach 30 Minuten
if current_time - trade.open_date_utc >= timedelta(minutes=30):
return -0.02 # 2% Stoploss
# Standard Stoploss
return self.stoploss
def confirm_trade_entry(self, pair: str, order_type: str, amount: float,
rate: float, time_in_force: str, current_time: 'datetime',
entry_tag: str, side: str, **kwargs) -> bool:
"""
Bestätigung vor Trade-Entry (sehr konservativ in bearish markets)
"""
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if len(dataframe) < 1:
return False
last_candle = dataframe.iloc[-1]
# Sehr strenge Bedingungen für Entry in bearish market
conditions = [
last_candle['rsi'] < 30, # Stark oversold
last_candle['bb_percent'] < 0.2, # Nahe BB lower band
last_candle['volume_ratio'] > 1.0, # Erhöhtes Volumen
last_candle['stoch_k'] < 25, # Stochastic oversold
last_candle['williams_r'] < -75, # Williams %R oversold
]
# Mindestens 4 von 5 Bedingungen müssen erfüllt sein
if sum(conditions) >= 4:
return True
return False
def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,
rate: float, time_in_force: str, exit_reason: str,
current_time: 'datetime', **kwargs) -> bool:
"""
Bestätigung vor Trade-Exit (schnelle Gewinnmitnahme bevorzugen)
"""
# Immer bestätigen bei Stoploss
if exit_reason == 'stoploss':
return True
# Bei ROI immer bestätigen (schnelle Gewinnmitnahme in bearish market)
if exit_reason == 'roi':
return True
# Bei Exit-Signal prüfen ob nicht zu früh
if exit_reason == 'exit_signal':
# Mindestens 15 Minuten halten
if current_time - trade.open_date_utc >= timedelta(minutes=15):
return True
else:
# Nur bei starken Exit-Signalen früher verkaufen
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if len(dataframe) < 1:
return True
last_candle = dataframe.iloc[-1]
if (last_candle['rsi'] > 70 or
last_candle['bb_percent'] > 0.9 or
last_candle['close'] < last_candle['sar']):
return True
return False
return True
def leverage(self, pair: str, current_time: 'datetime', current_rate: float,
proposed_leverage: float, max_leverage: float, entry_tag: str,
side: str, **kwargs) -> float:
"""
Leverage für bearish strategy (konservativer)
"""
# Reduzierter Leverage in bearish markets
return min(proposed_leverage * 0.7, max_leverage)