Add ATR
This commit is contained in:
@@ -49,7 +49,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"240": 0
|
||||
}
|
||||
# 15m and 30m
|
||||
minimal_roi = {
|
||||
minimal_roi_1 = {
|
||||
"0": 0.1,
|
||||
"240": 0.05,
|
||||
"480": 0.03,
|
||||
@@ -61,9 +61,9 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"2400": 0.025,
|
||||
"3600": 0
|
||||
}
|
||||
can_short = True
|
||||
lev = 1.0
|
||||
stoploss = -0.3
|
||||
can_short = False
|
||||
lev = 2.0
|
||||
stoploss = -0.5
|
||||
trailing_stop = False
|
||||
trailing_stop_positive = 0.025
|
||||
trailing_stop_positive_offset = 0.045
|
||||
@@ -105,13 +105,22 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe_4h = self.add_indicators(dataframe_4h)
|
||||
dataframe_1d = self.add_indicators(dataframe_1d)
|
||||
#self.chan.plot_dual(dataframe_5, dataframe_30)
|
||||
dataframe_5['chanpy_state'] = self.chanpy.get_bsp_state(dataframe_5)
|
||||
chanpy_state = self.chanpy.get_bsp_state(dataframe_5)
|
||||
dataframe_5['chanpy_state'] = chanpy_state
|
||||
state_list, fx_list = self.chan.get_klc_strength_list(dataframe_30)
|
||||
dataframe_30['state'] = state_list
|
||||
dataframe_30['fx'] = fx_list
|
||||
|
||||
#bi_list_1 = self.chan.get_bi_list(dataframe)
|
||||
#bi_list_5 = self.chan.get_bi_list(dataframe_5)
|
||||
#bi_list_15 = self.chan.get_bi_list(dataframe_15)
|
||||
#bi_list_30 = self.chan.get_bi_list(dataframe_30)
|
||||
#bi_list_60 = self.chan.get_bi_list(dataframe_60)
|
||||
if self.last_time + timedelta(minutes=1) < datetime.now():
|
||||
|
||||
#self.print_bi(bi_list_1)
|
||||
#self.print_bi(bi_list_5)
|
||||
#self.print_bi(bi_list_15)
|
||||
#self.print_bi(bi_list_30)
|
||||
#self.print_bi(bi_list_60)
|
||||
print("-------------------------------------------------------------------------------")
|
||||
self.last_time = datetime.now()
|
||||
dataframe = resampled_merge(dataframe, dataframe_5)
|
||||
@@ -120,7 +129,11 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#dataframe = resampled_merge(dataframe, dataframe_60)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_4h)
|
||||
return dataframe
|
||||
|
||||
def print_bi(self, bi_list):
|
||||
if bi_list and len(bi_list) > 2:
|
||||
bi1 = bi_list[-1]
|
||||
bi2 = bi_list[-2]
|
||||
print(bi1.start_time, bi1.end_time, bi1.dir, bi2.start_time, bi2.end_time, bi2.dir)
|
||||
def add_indicators(self, df):
|
||||
fast = 8
|
||||
slow = 16
|
||||
@@ -167,16 +180,26 @@ class ChanLun_BTC_30(IStrategy):
|
||||
return new_exitprice
|
||||
|
||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
||||
time_in_force: str, current_time: datetime, entry_tag: str | None,
|
||||
side: str, **kwargs) -> bool:
|
||||
time_in_force: str, current_time: datetime, entry_tag: str | None,
|
||||
side: str, **kwargs) -> bool:
|
||||
if self.last_trade:
|
||||
if self.last_trade.open_date + timedelta(minutes=30) > current_time:
|
||||
return False
|
||||
if self.last_trade.is_short:
|
||||
if side == 'short':
|
||||
if self.last_trade.open_date + timedelta(minutes=30) > current_time:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
if side == 'long':
|
||||
if self.last_trade.open_date + timedelta(minutes=30) > current_time:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
#if self.last_trade:
|
||||
#print(self.last_trade.open_date, current_time, self.last_trade.open_date + timedelta(minutes=self.time5))
|
||||
return True
|
||||
|
||||
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||
def custom_exit1(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||
current_profit: float, **kwargs):
|
||||
#dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
#last_candle = dataframe.iloc[-1].squeeze()
|
||||
@@ -220,8 +243,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#last_candle = dataframe.iloc[-1].squeeze()
|
||||
klc_list = self.chan.get_klc_list(resample_to_interval(dataframe, self.get_ticker_indicator() * 30))
|
||||
bi_list = self.chan.cal_bi_list(klc_list)
|
||||
last_high = klc_list[-3].high
|
||||
last_low = klc_list[-3].low
|
||||
last_high = klc_list[-2].high
|
||||
last_low = klc_list[-2].low
|
||||
if trade.is_short:
|
||||
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):
|
||||
trade.set_custom_data(key="entry_candle_high", value=last_high)
|
||||
@@ -234,15 +257,15 @@ class ChanLun_BTC_30(IStrategy):
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
state_str = 'resample_{}_state'.format(self.get_ticker_indicator()*self.time30)
|
||||
fx_str = 'resample_{}_fx'.format(self.get_ticker_indicator()*self.time30)
|
||||
chanpy_state_str = 'resample_{}_chanpy_state'.format(self.get_ticker_indicator()*self.time5)
|
||||
shift_time = self.time30*2
|
||||
strength = 2.2
|
||||
#chanpy_state_str = 'resample_{}_chanpy_state'.format(self.get_ticker_indicator()*self.time5)
|
||||
shift_time = self.time30
|
||||
strength = 0.9
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == -1) &
|
||||
(dataframe[chanpy_state_str].shift(shift_time+30) == 1)
|
||||
(dataframe[fx_str].shift(shift_time) == -1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == 1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "-10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10")
|
||||
@@ -253,8 +276,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
(
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == 1) &
|
||||
(dataframe[chanpy_state_str].shift(shift_time+30) == -1)
|
||||
(dataframe[fx_str].shift(shift_time) == 1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == -1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "-10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10")
|
||||
@@ -265,15 +288,15 @@ class ChanLun_BTC_30(IStrategy):
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
state_str = 'resample_{}_state'.format(self.get_ticker_indicator()*self.time30)
|
||||
fx_str = 'resample_{}_fx'.format(self.get_ticker_indicator()*self.time30)
|
||||
chanpy_state_str = 'resample_{}_chanpy_state'.format(self.get_ticker_indicator()*self.time5)
|
||||
shift_time = self.time30*2
|
||||
strength = 2.2
|
||||
#chanpy_state_str = 'resample_{}_chanpy_state'.format(self.get_ticker_indicator()*self.time5)
|
||||
shift_time = self.time30
|
||||
strength = 0.9
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state']== "30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == 1) &
|
||||
(dataframe[chanpy_state_str].shift(shift_time+30) == -1)
|
||||
(dataframe[fx_str].shift(shift_time) == 1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == -1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time60)] == "10")
|
||||
),
|
||||
@@ -282,8 +305,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
(
|
||||
#(dataframe['state']== "30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == -1) &
|
||||
(dataframe[chanpy_state_str].shift(shift_time+30) == 1)
|
||||
(dataframe[fx_str].shift(shift_time) == -1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == 1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "10") &
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time60)] == "10")
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user