添加第二类卖卖点
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# --- Do not remove these libs ---
|
||||
from statistics import median
|
||||
from freqtrade.strategy import IStrategy
|
||||
from freqtrade.strategy import IStrategy, stoploss_from_absolute
|
||||
import sys
|
||||
import os
|
||||
# 添加父目录到系统路径
|
||||
@@ -61,9 +61,11 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"2400": 0.025,
|
||||
"3600": 0
|
||||
}
|
||||
can_short = False
|
||||
can_short = True
|
||||
lev = 2.0
|
||||
stoploss = -0.5
|
||||
use_custom_stoploss = True
|
||||
|
||||
trailing_stop = False
|
||||
trailing_stop_positive = 0.025
|
||||
trailing_stop_positive_offset = 0.045
|
||||
@@ -77,10 +79,12 @@ class ChanLun_BTC_30(IStrategy):
|
||||
time30 = 30
|
||||
time60 = 60
|
||||
time4h = 240
|
||||
time30 = 60
|
||||
last_time = datetime.now()
|
||||
chan = ChanLun()
|
||||
chanpy = ChanPY()
|
||||
classifier = ChanLunClassifier(None)
|
||||
last_order = None
|
||||
last_trade = None
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
|
||||
@@ -107,9 +111,9 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#self.chan.plot_dual(dataframe_5, dataframe_30)
|
||||
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
|
||||
state_list = self.chan.get_klc_state_list(dataframe_60)
|
||||
dataframe_60['state'] = state_list
|
||||
dataframe_60['fx'] = state_list
|
||||
|
||||
#bi_list_1 = self.chan.get_bi_list(dataframe)
|
||||
#bi_list_5 = self.chan.get_bi_list(dataframe_5)
|
||||
@@ -126,7 +130,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
print("-------------------------------------------------------------------------------")
|
||||
self.last_time = datetime.now()
|
||||
dataframe = resampled_merge(dataframe, dataframe_5)
|
||||
dataframe = resampled_merge(dataframe, dataframe_30)
|
||||
dataframe = resampled_merge(dataframe, dataframe_60)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_30)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_60)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_4h)
|
||||
@@ -188,7 +192,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
new_exitprice = proposed_rate - 50
|
||||
return new_exitprice
|
||||
|
||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
||||
def confirm_trade_entry1(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:
|
||||
if self.last_trade:
|
||||
@@ -207,7 +211,20 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#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_stoploss1(self, pair: str, trade: Trade, current_time: datetime,
|
||||
current_rate: float, current_profit: float, after_fill: bool,
|
||||
**kwargs) -> float | None:
|
||||
|
||||
last_high = trade.get_custom_data(key="entry_candle_high")
|
||||
last_low = trade.get_custom_data(key="entry_candle_low")
|
||||
|
||||
# Convert absolute price to percentage relative to current_rate
|
||||
if last_high:
|
||||
return stoploss_from_absolute(last_high, current_rate, is_short=trade.is_short)
|
||||
if last_low:
|
||||
return stoploss_from_absolute(last_low, current_rate, is_short=trade.is_short)
|
||||
# return maximum stoploss value, keeping current stoploss price unchanged
|
||||
return None
|
||||
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)
|
||||
@@ -229,15 +246,15 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"""
|
||||
if trade.is_short:
|
||||
last_high = trade.get_custom_data(key="entry_candle_high")
|
||||
if current_rate > last_high:
|
||||
if last_high and current_rate > last_high:
|
||||
#print(trade.open_date, last_high, current_rate, "Relay Top FX exit")
|
||||
return "Relay Top FX exit"
|
||||
else:
|
||||
last_low = trade.get_custom_data(key="entry_candle_low")
|
||||
if current_rate < last_low:
|
||||
if last_low and current_rate < last_low:
|
||||
#print(trade.open_date, last_low, current_rate, "Relay Bottom FX exit")
|
||||
return "Relay Bottom FX exit"
|
||||
def order_filled1(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:
|
||||
def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:
|
||||
"""
|
||||
Called right after an order fills.
|
||||
Will be called for all order types (entry, exit, stoploss, position adjustment).
|
||||
@@ -250,17 +267,26 @@ class ChanLun_BTC_30(IStrategy):
|
||||
# Obtain pair dataframe (just to show how to access it)
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
||||
#last_candle = dataframe.iloc[-1].squeeze()
|
||||
klc_list = self.chan.get_klc_list(resample_to_interval(dataframe, self.get_ticker_indicator() * 30))
|
||||
klc_list = self.chan.get_klc_list(resample_to_interval(dataframe, self.get_ticker_indicator() * self.time30))
|
||||
bi_list = self.chan.cal_bi_list(klc_list)
|
||||
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)
|
||||
if self.last_order is None:
|
||||
if trade.is_short and klc_list[-2].last_top_klc:
|
||||
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):
|
||||
last_high = klc_list[-2].last_top_klc.high
|
||||
print(klc_list[-2].start_time, "--------------------------------", order.order_date, order.side, last_high)
|
||||
trade.set_custom_data(key="entry_candle_high", value=last_high)
|
||||
else:
|
||||
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side) and klc_list[-2].last_bottom_klc:
|
||||
last_low = klc_list[-2].last_bottom_klc.low
|
||||
trade.set_custom_data(key="entry_candle_low", value=last_low)
|
||||
print(klc_list[-2].start_time, "--------------------------------", order.order_date, order.side, last_low)
|
||||
#print(trade.open_date, trade.close_date, last_high, last_low, order.ft_order_side, klc_list[-2].start_time, klc_list[-2].end_time)
|
||||
self.last_order = order
|
||||
else:
|
||||
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):
|
||||
trade.set_custom_data(key="entry_candle_low", value=last_low)
|
||||
#print(trade.open_date, trade.close_date, last_high, last_low, order.ft_order_side, klc_list[-2].start_time, klc_list[-2].end_time)
|
||||
if self.last_order.side != order.side:
|
||||
self.last_order = None
|
||||
trade.set_custom_data(key="entry_candle_high", value=None)
|
||||
trade.set_custom_data(key="entry_candle_low", value=None)
|
||||
self.last_trade = trade
|
||||
return None
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@@ -272,8 +298,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == -1)
|
||||
(dataframe[state_str].shift(shift_time) == "-10")
|
||||
#(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") &
|
||||
@@ -284,8 +310,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == 1)
|
||||
(dataframe[state_str].shift(shift_time) == "10")
|
||||
#(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") &
|
||||
@@ -303,8 +329,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state']== "30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == 1)
|
||||
(dataframe[state_str].shift(shift_time) == "101")
|
||||
#(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")
|
||||
@@ -313,8 +339,8 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state']== "30")
|
||||
(dataframe[state_str].shift(shift_time) > strength) &
|
||||
(dataframe[fx_str].shift(shift_time) == -1)
|
||||
(dataframe[state_str].shift(shift_time) == "-101")
|
||||
#(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