TEST calculateMarketState

This commit is contained in:
Jérôme Delacotte
2026-03-27 20:52:36 +01:00
parent 812aa01135
commit 1bc5a38796
3 changed files with 56 additions and 20 deletions

View File

@@ -17,13 +17,13 @@
"max_open_trades": 20 "max_open_trades": 20
}, },
"sell": { "sell": {
"b30_indicateur": "sma24", "b30_indicateur": "sma36",
"baisse": 0.2, "baisse": 0.3,
"sell_force_sell": -0.121, "sell_force_sell": -0.03,
"sell_indicator": "sma36" "sell_indicator": "sma36"
}, },
"protection": { "protection": {
"drop_from_last_entry": 0.0, "drop_from_last_entry": -0.01,
"mises_bull": 4 "mises_bull": 4
} }
}, },

View File

@@ -19,6 +19,8 @@ from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalP
import ta import ta
import talib.abstract as talib import talib.abstract as talib
import freqtrade.vendor.qtpylib.indicators as qtpylib import freqtrade.vendor.qtpylib.indicators as qtpylib
from ta.trend import SMAIndicator, EMAIndicator, MACD, ADXIndicator
from ta.momentum import RSIIndicator, StochasticOscillator
from functools import reduce from functools import reduce
from random import shuffle from random import shuffle
@@ -103,6 +105,7 @@ class Empty5m(IStrategy):
position_adjustment_enable = True position_adjustment_enable = True
use_custom_stoploss = True use_custom_stoploss = True
can_short = True
#max_open_trades = 3 #max_open_trades = 3
# Optimal ticker interval for the strategy. # Optimal ticker interval for the strategy.
@@ -559,12 +562,12 @@ class Empty5m(IStrategy):
self.pairs[pair]['force_sell'] = True self.pairs[pair]['force_sell'] = True
return 'smaBF' return 'smaBF'
else: else:
if current_profit < self.sell_force_sell.value \ if current_profit < self.sell_force_sell.value and self.wallets.get_available_stake_amount() < 50 \
and last_candle[f"close"] <= last_candle[self.sell_indicator.value]: and last_candle[f"close"] <= last_candle[self.sell_indicator.value]:
self.pairs[pair]['force_sell'] = True self.pairs[pair]['force_sell'] = True
return 'sma' return 'sma'
if current_profit > 0.00 and \ if current_profit > 0.01 and \
(baisse > self.baisse.value and last_candle[f"close"] <= last_candle[self.b30_indicateur.value]) \ (baisse > self.baisse.value and last_candle[f"close"] <= last_candle[self.b30_indicateur.value]) \
and last_candle['hapercent'] < 0: and last_candle['hapercent'] < 0:
self.pairs[pair]['force_sell'] = True self.pairs[pair]['force_sell'] = True
@@ -694,12 +697,14 @@ class Empty5m(IStrategy):
dataframe["volume_mean"] = dataframe["volume"].rolling(20).mean() dataframe["volume_mean"] = dataframe["volume"].rolling(20).mean()
dataframe["volume_ratio"] = dataframe["volume"] / dataframe["volume_mean"] dataframe["volume_ratio"] = dataframe["volume"] / dataframe["volume_mean"]
dataframe["market_state"] = 0 # dataframe["market_state"] = 0
#
# dataframe.loc[dataframe["percent"] < -0.005, "market_state"] = -1
# dataframe.loc[(dataframe["percent3"] < -0.015) & (dataframe["volume_ratio"] > 2), "market_state"] = -2
# dataframe.loc[(dataframe["percent"] > 0.003) & (dataframe["volume_ratio"] > 1.5), "market_state"] = 1
# dataframe["velocity"] = dataframe["percent"] - dataframe["percent3"]
dataframe.loc[dataframe["percent"] < -0.005, "market_state"] = -1 dataframe = self.calculateMarketState(dataframe, metadata)
dataframe.loc[(dataframe["percent3"] < -0.015) & (dataframe["volume_ratio"] > 2), "market_state"] = -2
dataframe.loc[(dataframe["percent"] > 0.003) & (dataframe["volume_ratio"] > 1.5), "market_state"] = 1
dataframe["velocity"] = dataframe["percent"] - dataframe["percent3"]
# ###################################################################################################### # ######################################################################################################
################### INFORMATIVE 1h ################### INFORMATIVE 1h
@@ -746,6 +751,7 @@ class Empty5m(IStrategy):
informative['stop_buying'] = latched informative['stop_buying'] = latched
informative = self.calculateDownAndUp(informative, limit=0.0001) informative = self.calculateDownAndUp(informative, limit=0.0001)
informative = self.calculateMarketState(informative, metadata)
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1h", ffill=True) dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1h", ffill=True)
# ###################################################################################################### # ######################################################################################################
@@ -789,6 +795,7 @@ class Empty5m(IStrategy):
else: else:
latched[i] = latched[i - 1] latched[i] = latched[i - 1]
informative['stop_buying'] = latched informative['stop_buying'] = latched
informative = self.calculateMarketState(informative, metadata)
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True) dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
# ###################################################################################################### # ######################################################################################################
@@ -981,17 +988,23 @@ class Empty5m(IStrategy):
conditions = list() conditions = list()
# conditions.append(dataframe['mid_regression'].shift(2) > dataframe['mid_regression'].shift(1)) # conditions.append(dataframe['mid_regression'].shift(2) > dataframe['mid_regression'].shift(1))
# conditions.append(dataframe['mid_regression'].shift(1) < dataframe['mid_regression']) # conditions.append(dataframe['mid_regression'].shift(1) < dataframe['mid_regression'])
conditions.append(dataframe['close'] <= dataframe['min12_1h']) conditions.append(dataframe['close'] <= dataframe['min3_1h'])
conditions.append(dataframe['min60'] == dataframe['min60'].shift(5)) # conditions.append(dataframe['min60'] == dataframe['min60'].shift(5))
conditions.append(dataframe['has_cross_min_6'] == 1) conditions.append(dataframe['has_cross_min_6'] == 1)
conditions.append(dataframe['down_count'] <= 5) # conditions.append(dataframe['down_count'] <= 5)
conditions.append(dataframe['down_count'] <= 5)
# conditions.append(dataframe['sma12_deriv1'] >= 0) # conditions.append(dataframe['sma12_deriv1'] >= 0)
dataframe.loc[ dataframe.loc[
reduce(lambda x, y: x & y, conditions), reduce(lambda x, y: x & y, conditions),
['enter_long', 'enter_tag'] ['enter_long', 'enter_tag']
] = (1, 'Mid') ] = (1, 'Mid')
dataframe.loc[
(
(dataframe['rsi'] > 70) # surachat
),
'enter_short'
] = 1
return dataframe return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
@@ -1414,3 +1427,26 @@ class Empty5m(IStrategy):
down_pct_values[i] = 100 * (dataframe['close'].iloc[i] - dataframe['close'].iloc[i - shift_value]) / \ down_pct_values[i] = 100 * (dataframe['close'].iloc[i] - dataframe['close'].iloc[i - shift_value]) / \
dataframe['close'].iloc[i - shift_value] dataframe['close'].iloc[i - shift_value]
return down_pct_values return down_pct_values
def calculateMarketState(self, dataframe, metadata):
dataframe['ema50'] = EMAIndicator(dataframe['close'], window=50).ema_indicator()
dataframe['ema200'] = EMAIndicator(dataframe['close'], window=200).ema_indicator()
# RSI
dataframe['rsi'] = RSIIndicator(dataframe['close'], window=14).rsi()
dataframe["market_state"] = 0
cond_bull = (
(dataframe["rsi"] > 55) &
(dataframe["ema50"] > dataframe["ema200"])
)
cond_bear = (
(dataframe["rsi"] < 45) &
(dataframe["ema50"] < dataframe["ema200"])
)
dataframe.loc[cond_bull, "market_state"] = 1
dataframe.loc[cond_bear, "market_state"] = -1
return dataframe

View File

@@ -1267,7 +1267,7 @@ class FrictradeLearning(IStrategy):
# hours_since_first_price = (current_time - trade.open_date_utc).seconds / 3600.0 # hours_since_first_price = (current_time - trade.open_date_utc).seconds / 3600.0
# days_since_first_price = (current_time - trade.open_date_utc).days # days_since_first_price = (current_time - trade.open_date_utc).days
hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0 hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0
# minutes = (current_time - trade.date_last_filled_utc).total_seconds() / 60.0 minutes = (current_time - trade.date_last_filled_utc).total_seconds() / 60.0
count_of_buys = trade.nr_of_successful_entries count_of_buys = trade.nr_of_successful_entries
# current_time_utc = current_time.astimezone(timezone.utc) # current_time_utc = current_time.astimezone(timezone.utc)
@@ -1331,8 +1331,8 @@ class FrictradeLearning(IStrategy):
increase = - decline increase = - decline
# FIN ########################## ALGO ATH # FIN ########################## ALGO ATH
force = hours > 12 #self.hours_force.value and last_candle[self.indic_1h_force_buy.value] > 0 force = False #self.hours_force.value and last_candle[self.indic_1h_force_buy.value] > 0
condition = last_candle['percent'] > 0 \ condition = minutes > 5 and last_candle['percent'] > 0 \
and ((count_of_buys <= 4 and last_candle['sma24_deriv1'] > 0) or (count_of_buys > 4 and last_candle['sma60_deriv1'] > 0))\ and ((count_of_buys <= 4 and last_candle['sma24_deriv1'] > 0) or (count_of_buys > 4 and last_candle['sma60_deriv1'] > 0))\
and last_candle['close'] < self.pairs[pair]['first_price'] and last_candle['close'] < self.pairs[pair]['first_price']