TEST SHORT
This commit is contained in:
126
EmptyShort.py
126
EmptyShort.py
@@ -571,7 +571,7 @@ class EmptyShort(IStrategy):
|
||||
#
|
||||
if current_profit > tp_price and \
|
||||
(baisse > last_candle[f"range_pos"] and last_candle[f"close"] > last_candle[self.b30_indicateur.value]) \
|
||||
and last_candle['hapercent'] > 0 and last_candle['sma12_deriv2_1h'] > 0.0:
|
||||
and last_candle['hapercent'] > 0: # and last_candle['sma12_deriv2_1h'] > 0.0:
|
||||
self.pairs[pair]['force_sell'] = True
|
||||
return 'B30Sht'
|
||||
|
||||
@@ -609,7 +609,7 @@ class EmptyShort(IStrategy):
|
||||
tp_price = max(0.02, self.pairs[pair]['take_profit'])
|
||||
if current_profit > tp_price and \
|
||||
(baisse > min(last_candle[f"range_pos"], 0.5) and last_candle[f"close"] <= last_candle[self.b30_indicateur.value]) \
|
||||
and last_candle['hapercent'] <0 and last_candle['sma12_deriv1_1h'] < 0.004:
|
||||
and last_candle['hapercent'] <0 : #and last_candle['sma12_deriv1_1h'] < 0.004:
|
||||
# if current_profit > 0.01:
|
||||
# self.pairs[pair]['force_buy'] = True
|
||||
self.pairs[pair]['force_sell'] = True
|
||||
@@ -759,7 +759,7 @@ class EmptyShort(IStrategy):
|
||||
informative['haclose'] = heikinashi['close']
|
||||
informative['hapercent'] = (informative['haclose'] - informative['haopen']) / informative['haclose']
|
||||
informative['mid'] = informative['open'] + (informative['close'] - informative['open']) / 2
|
||||
for timeperiod in [3, 5, 12]:
|
||||
for timeperiod in [3, 5, 12, 50, 200]:
|
||||
informative[f'max{timeperiod}'] = talib.MAX(informative['close'], timeperiod=timeperiod)
|
||||
informative[f'min{timeperiod}'] = talib.MIN(informative['close'], timeperiod=timeperiod)
|
||||
# informative[f"range{timeperiod}"] = ((informative["close"] - informative[f'min{timeperiod}']) / (informative[f'max{timeperiod}'] - informative[f'min{timeperiod}']))
|
||||
@@ -771,9 +771,9 @@ class EmptyShort(IStrategy):
|
||||
informative = self.calculateRegression(informative, column='sma3', window=10, degree=1, future_offset=2)
|
||||
informative = self.calculateRegression(informative, column='low', window=10, degree=1, future_offset=2)
|
||||
|
||||
for timeperiod in long_timeperiods:
|
||||
informative[f"sma{timeperiod}"] = informative['mid'].ewm(span=timeperiod, adjust=False).mean()
|
||||
self.calculeDerivees(informative, f"sma{timeperiod}", timeframe=self.timeframe, ema_period=timeperiod)
|
||||
# for timeperiod in long_timeperiods:
|
||||
# informative[f"sma{timeperiod}"] = informative['mid'].ewm(span=timeperiod, adjust=False).mean()
|
||||
# self.calculeDerivees(informative, f"sma{timeperiod}", timeframe=self.timeframe, ema_period=timeperiod)
|
||||
|
||||
informative['rsi'] = talib.RSI(informative['close'], timeperiod=14)
|
||||
self.calculeDerivees(informative, f"rsi", timeframe=self.timeframe, ema_period=14)
|
||||
@@ -818,9 +818,9 @@ class EmptyShort(IStrategy):
|
||||
informative[f"sma{timeperiod}"] = informative['mid'].ewm(span=timeperiod, adjust=False).mean()
|
||||
self.calculeDerivees(informative, f"sma{timeperiod}", timeframe=self.timeframe, ema_period=timeperiod)
|
||||
|
||||
for timeperiod in long_timeperiods:
|
||||
informative[f"sma{timeperiod}"] = informative['mid'].ewm(span=timeperiod, adjust=False).mean()
|
||||
self.calculeDerivees(informative, f"sma{timeperiod}", timeframe=self.timeframe, ema_period=timeperiod)
|
||||
# for timeperiod in long_timeperiods:
|
||||
# informative[f"sma{timeperiod}"] = informative['mid'].ewm(span=timeperiod, adjust=False).mean()
|
||||
# self.calculeDerivees(informative, f"sma{timeperiod}", timeframe=self.timeframe, ema_period=timeperiod)
|
||||
|
||||
informative['rsi'] = talib.RSI(informative['close'], timeperiod=14)
|
||||
self.calculeDerivees(informative, f"rsi", timeframe=self.timeframe, ema_period=14)
|
||||
@@ -881,6 +881,8 @@ class EmptyShort(IStrategy):
|
||||
dataframe['volume_spike'] = (abs(dataframe['volume2']) > abs(dataframe['volume2'].rolling(window=20).mean() * 5)) \
|
||||
& (dataframe['volume'].rolling(window=5).max() > 1000)
|
||||
|
||||
dataframe['sma5_1h'] = dataframe['sma5_1h'].rolling(window=60).mean()
|
||||
|
||||
# récupérer le dernier trade fermé
|
||||
trades = Trade.get_trades_proxy(pair=pair,is_open=False)
|
||||
if trades:
|
||||
@@ -894,60 +896,92 @@ class EmptyShort(IStrategy):
|
||||
pair = metadata['pair']
|
||||
dataframe.loc[
|
||||
(
|
||||
# (qtpylib.crossed_above(dataframe['sma60'], dataframe['mid_regression_1h']))
|
||||
(dataframe['sma12_deriv1_1h'] > 0)
|
||||
& (dataframe['max_rsi_12'] < 70)
|
||||
& (dataframe['max_rsi_12_1h'] < 70)
|
||||
& (dataframe['range_pos'] < 1)
|
||||
# (dataframe['sma5_1h'] > dataframe['close'])
|
||||
# & (dataframe['sma12_deriv1_1h'] > 0)
|
||||
# & (dataframe['max_rsi_12'] > 45)
|
||||
# & (
|
||||
# (
|
||||
# (dataframe['max_rsi_24_1h'] < 45) & (dataframe['range_pos'] < 0.3)
|
||||
# | (dataframe['sma12_deriv1_1d'] > 0)
|
||||
# )
|
||||
# )
|
||||
(dataframe['sma60_deriv1'] > 0)
|
||||
& (dataframe['sma60_deriv2'] > 0)
|
||||
# & (dataframe['sma5_deriv1_1h'] > 0)
|
||||
& (dataframe['hapercent'] > 0)
|
||||
& (dataframe['pct_min_max_12_1d'] < 0.04)
|
||||
& (dataframe['up_count'] >= 3)
|
||||
& (dataframe['up_count'] <= 7)
|
||||
# & (dataframe['open'] < dataframe['sma5_1h'] * 1.01)
|
||||
),
|
||||
['enter_long', 'enter_tag']
|
||||
] = (1, 'long')
|
||||
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe['volume_spike'] == 1)
|
||||
& (dataframe['down_count'] >= 3)
|
||||
& (dataframe['down_count'] < 15)
|
||||
& (dataframe['hapercent'] > 0)
|
||||
& (dataframe['sma60'] > dataframe['sma60'].shift(1))
|
||||
),
|
||||
['enter_long', 'enter_tag']
|
||||
] = (1, 'long_spike')
|
||||
# dataframe.loc[
|
||||
# (
|
||||
# # (dataframe['sma5_1h'] > dataframe['close'])
|
||||
# (dataframe['sma60_deriv1'] < 0)
|
||||
# & (dataframe['sma60_deriv2'] < 0)
|
||||
# & (dataframe['sma12_deriv1_1h'] > 0)
|
||||
# & (dataframe['volume_spike'] == 1)
|
||||
# & (dataframe['down_count'] >= 3)
|
||||
# & (dataframe['down_count'] < 15)
|
||||
# & (dataframe['hapercent'] > 0)
|
||||
# & (dataframe['sma60'] > dataframe['sma60'].shift(1))
|
||||
# ),
|
||||
# ['enter_long', 'enter_tag']
|
||||
# ] = (1, 'long_spike')
|
||||
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe['sma12_deriv1_1h'] < -0.0005)
|
||||
& (dataframe['max_rsi_12'] < 60)
|
||||
& (
|
||||
(
|
||||
(dataframe['max_rsi_24_1h'] > 60) & (dataframe['range_pos'] > 0.8)
|
||||
| (dataframe['sma12_deriv1_1d'] < -0.01)
|
||||
)
|
||||
)
|
||||
# (dataframe['sma5_1h'] < dataframe['close'])
|
||||
# & (dataframe['sma12_deriv1_1h'] < -0.0005)
|
||||
# & (dataframe['max_rsi_12'] < 60)
|
||||
# & (
|
||||
# (
|
||||
# (dataframe['max_rsi_24_1h'] > 60) & (dataframe['range_pos'] > 0.8)
|
||||
# | (dataframe['sma12_deriv1_1d'] < -0.01)
|
||||
# )
|
||||
# )
|
||||
(dataframe['sma60_deriv1'] < 0)
|
||||
& (dataframe['sma60_deriv2'] < 0)
|
||||
# & (dataframe['sma5_deriv1_1h'] < 0)
|
||||
& (dataframe['hapercent'] < 0)
|
||||
# & (dataframe['pct_min_max_12_1d'] > 0.04)
|
||||
& (dataframe['down_count'] <= -3)
|
||||
& (dataframe['down_count'] > -15)
|
||||
& (dataframe['down_count'] >= -7)
|
||||
# & (dataframe['open'] > dataframe['sma5_1h'] * 1.01)
|
||||
),
|
||||
['enter_short', 'enter_tag']
|
||||
] = (1, 'short')
|
||||
|
||||
dataframe.loc[
|
||||
(
|
||||
(dataframe['volume_spike'] == 1)
|
||||
& (dataframe['down_count'] <= -3)
|
||||
& (dataframe['down_count'] > -15)
|
||||
& (dataframe['hapercent'] < 0)
|
||||
& (dataframe['sma60'] < dataframe['sma60'].shift(1))
|
||||
),
|
||||
['enter_short', 'enter_tag']
|
||||
] = (1, 'short_spike')
|
||||
# dataframe.loc[
|
||||
# (
|
||||
# (dataframe['sma5_1h'] < dataframe['close'])
|
||||
# & (dataframe['volume_spike'] == 1)
|
||||
# & (dataframe['down_count'] <= -3)
|
||||
# & (dataframe['down_count'] > -15)
|
||||
# & (dataframe['hapercent'] < 0)
|
||||
# & (dataframe['sma60'] < dataframe['sma60'].shift(1))
|
||||
# ),
|
||||
# ['enter_short', 'enter_tag']
|
||||
# ] = (1, 'short_spike')
|
||||
|
||||
dataframe['short'] = np.where(dataframe['enter_short'] == 1, dataframe['close'] * 0.99, np.nan)
|
||||
dataframe['long'] = np.where(dataframe['enter_long'] == 1, dataframe['close'] * 1.01, np.nan)
|
||||
|
||||
# no_trade = (
|
||||
# # range
|
||||
# (abs(dataframe['sma50_1h'] - dataframe['sma200_1h']) / dataframe['close'] < 0.002)
|
||||
# # momentum faible
|
||||
# | (abs(dataframe['sma12_deriv1']) < 0.0002)
|
||||
# # RSI neutre
|
||||
# | ((dataframe['rsi'] > 45) & (dataframe['rsi'] < 55))
|
||||
# # faible volatilité
|
||||
# | (dataframe['atr'] / dataframe['close'] < 0.003)
|
||||
# # milieu de range
|
||||
# | (dataframe['range_pos'].between(0.4, 0.6))
|
||||
# )
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@@ -1366,8 +1400,8 @@ class EmptyShort(IStrategy):
|
||||
return df
|
||||
|
||||
def calculateDownAndUp(self, dataframe, limit=0.0001):
|
||||
dataframe['down'] = dataframe['mid_regression'] <= dataframe['mid_regression'].shift(1)
|
||||
dataframe['up'] = dataframe['mid_regression'] >= dataframe['mid_regression'].shift(1)
|
||||
dataframe['down'] = dataframe['hapercent'] < 0
|
||||
dataframe['up'] = dataframe['hapercent'] > 0
|
||||
dataframe['down_count'] = - dataframe['down'].astype(int) * (
|
||||
dataframe['down'].groupby((dataframe['down'] != dataframe['down'].shift()).cumsum()).cumcount() + 1)
|
||||
dataframe['up_count'] = dataframe['up'].astype(int) * (
|
||||
|
||||
Reference in New Issue
Block a user