Bullische Trading-Strategie
Timeframe
1h
Direction
Long Only
Stoploss
-5.0%
Trailing Stop
No
ROI
0m: 4.0%, 30m: 2.0%, 60m: 1.0%
Interface Version
3
Startup Candles
N/A
Indicators
9
freqtrade/freqtrade-strategies
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
"""
Bullish Trading Strategy für das Crypto Multi-Agent System
Optimiert für bullische Marktphasen
"""
import talib.abstract as ta
from freqtrade.strategy import IStrategy, DecimalParameter, IntParameter
from pandas import DataFrame
import numpy as np
class StrategyBullish(IStrategy):
"""
Bullische Trading-Strategie
Diese Strategie ist optimiert für bullische Marktphasen und wird
vom Multi-Agent System aktiviert, wenn bullische Signale erkannt werden.
"""
# Strategy interface version
INTERFACE_VERSION = 3
# Minimal ROI designed for the strategy
minimal_roi = {
"60": 0.01, # 1% nach 1 Stunde
"30": 0.02, # 2% nach 30 Minuten
"0": 0.04 # 4% sofort
}
# Optimal stoploss
stoploss = -0.05 # 5% Stoploss
# 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
buy_rsi_threshold = IntParameter(20, 40, default=30, space="buy")
buy_macd_threshold = DecimalParameter(-0.01, 0.01, default=0.0, space="buy")
sell_rsi_threshold = IntParameter(60, 80, default=70, space="sell")
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Fügt Indikatoren zum Dataframe hinzu
"""
# 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
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)
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Bullische Entry-Signale
"""
conditions = []
# Grundlegende bullische Bedingungen
conditions.append(
(dataframe['close'] > dataframe['ema_9']) &
(dataframe['ema_9'] > dataframe['ema_21']) &
(dataframe['ema_21'] > dataframe['ema_50'])
)
# RSI nicht überkauft
conditions.append(dataframe['rsi'] < self.sell_rsi_threshold.value)
conditions.append(dataframe['rsi'] > self.buy_rsi_threshold.value)
# MACD bullish
conditions.append(
(dataframe['macd'] > dataframe['macdsignal']) &
(dataframe['macd'] > self.buy_macd_threshold.value)
)
# Volume-Bestätigung
conditions.append(dataframe['volume_ratio'] > 1.0)
# Bollinger Bands - nicht an oberer Grenze
conditions.append(dataframe['bb_percent'] < 0.9)
conditions.append(dataframe['bb_percent'] > 0.1)
# ADX zeigt Trend
conditions.append(dataframe['adx'] > 25)
# Stochastic nicht überkauft
conditions.append(dataframe['stoch_k'] < 80)
# Williams %R
conditions.append(dataframe['williams_r'] > -80)
conditions.append(dataframe['williams_r'] < -20)
# Kombiniere alle Bedingungen
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'enter_long'
] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Bullische Exit-Signale
"""
conditions = []
# RSI überkauft
conditions.append(dataframe['rsi'] > self.sell_rsi_threshold.value)
# MACD bearish crossover
conditions.append(
(dataframe['macd'] < dataframe['macdsignal']) &
(dataframe['macd'].shift(1) > dataframe['macdsignal'].shift(1))
)
# Preis unter EMA9
conditions.append(dataframe['close'] < dataframe['ema_9'])
# Bollinger Bands - an oberer Grenze
conditions.append(dataframe['bb_percent'] > 0.95)
# Stochastic überkauft
conditions.append(
(dataframe['stoch_k'] > 80) &
(dataframe['stoch_d'] > 80)
)
# Williams %R überkauft
conditions.append(dataframe['williams_r'] > -20)
# CCI überkauft
conditions.append(dataframe['cci'] > 100)
# Exit wenn eine der Bedingungen erfüllt ist
if conditions:
dataframe.loc[
reduce(lambda x, y: x | y, 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 bullische Strategie
"""
# Trailing Stoploss nach 30 Minuten
if current_time - trade.open_date_utc >= timedelta(minutes=30):
if current_profit > 0.02: # 2% Gewinn
return -0.01 # Trailing auf 1%
elif current_profit > 0.01: # 1% Gewinn
return -0.02 # Trailing auf 2%
# 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
"""
# Zusätzliche Validierung für bullische Märkte
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if len(dataframe) < 1:
return False
last_candle = dataframe.iloc[-1]
# Bestätige nur bei starken bullischen Signalen
if (last_candle['rsi'] > 25 and
last_candle['rsi'] < 75 and
last_candle['macd'] > last_candle['macdsignal'] and
last_candle['volume_ratio'] > 0.8):
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
"""
# Immer bestätigen bei Stoploss
if exit_reason == 'stoploss':
return True
# Bei ROI nur bestätigen wenn RSI nicht extrem niedrig
if exit_reason == 'roi':
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if len(dataframe) < 1:
return True
last_candle = dataframe.iloc[-1]
if last_candle['rsi'] < 30: # Nicht verkaufen bei oversold
return False
return True
# Hilfsfunktion für reduce
from functools import reduce