Update plotting to use entry/exit terminology

This commit is contained in:
Matthias 2022-07-16 22:28:46 +02:00
parent 9347677c60
commit 05a5ae4fcf
2 changed files with 29 additions and 29 deletions

View File

@ -255,18 +255,18 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
""" """
# Trades can be empty # Trades can be empty
if trades is not None and len(trades) > 0: if trades is not None and len(trades) > 0:
# Create description for sell summarizing the trade # Create description for exit summarizing the trade
trades['desc'] = trades.apply( trades['desc'] = trades.apply(
lambda row: f"{row['profit_ratio']:.2%}, " + lambda row: f"{row['profit_ratio']:.2%}, " +
(f"{row['enter_tag']}, " if row['enter_tag'] is not None else "") + (f"{row['enter_tag']}, " if row['enter_tag'] is not None else "") +
f"{row['exit_reason']}, " + f"{row['exit_reason']}, " +
f"{row['trade_duration']} min", f"{row['trade_duration']} min",
axis=1) axis=1)
trade_buys = go.Scatter( trade_entries = go.Scatter(
x=trades["open_date"], x=trades["open_date"],
y=trades["open_rate"], y=trades["open_rate"],
mode='markers', mode='markers',
name='Trade buy', name='Trade entry',
text=trades["desc"], text=trades["desc"],
marker=dict( marker=dict(
symbol='circle-open', symbol='circle-open',
@ -277,12 +277,12 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
) )
) )
trade_sells = go.Scatter( trade_exits = go.Scatter(
x=trades.loc[trades['profit_ratio'] > 0, "close_date"], x=trades.loc[trades['profit_ratio'] > 0, "close_date"],
y=trades.loc[trades['profit_ratio'] > 0, "close_rate"], y=trades.loc[trades['profit_ratio'] > 0, "close_rate"],
text=trades.loc[trades['profit_ratio'] > 0, "desc"], text=trades.loc[trades['profit_ratio'] > 0, "desc"],
mode='markers', mode='markers',
name='Sell - Profit', name='Exit - Profit',
marker=dict( marker=dict(
symbol='square-open', symbol='square-open',
size=11, size=11,
@ -290,12 +290,12 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
color='green' color='green'
) )
) )
trade_sells_loss = go.Scatter( trade_exits_loss = go.Scatter(
x=trades.loc[trades['profit_ratio'] <= 0, "close_date"], x=trades.loc[trades['profit_ratio'] <= 0, "close_date"],
y=trades.loc[trades['profit_ratio'] <= 0, "close_rate"], y=trades.loc[trades['profit_ratio'] <= 0, "close_rate"],
text=trades.loc[trades['profit_ratio'] <= 0, "desc"], text=trades.loc[trades['profit_ratio'] <= 0, "desc"],
mode='markers', mode='markers',
name='Sell - Loss', name='Exit - Loss',
marker=dict( marker=dict(
symbol='square-open', symbol='square-open',
size=11, size=11,
@ -303,9 +303,9 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
color='red' color='red'
) )
) )
fig.add_trace(trade_buys, 1, 1) fig.add_trace(trade_entries, 1, 1)
fig.add_trace(trade_sells, 1, 1) fig.add_trace(trade_exits, 1, 1)
fig.add_trace(trade_sells_loss, 1, 1) fig.add_trace(trade_exits_loss, 1, 1)
else: else:
logger.warning("No trades found.") logger.warning("No trades found.")
return fig return fig
@ -444,7 +444,7 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
Generate the graph from the data generated by Backtesting or from DB Generate the graph from the data generated by Backtesting or from DB
Volume will always be ploted in row2, so Row 1 and 3 are to our disposal for custom indicators Volume will always be ploted in row2, so Row 1 and 3 are to our disposal for custom indicators
:param pair: Pair to Display on the graph :param pair: Pair to Display on the graph
:param data: OHLCV DataFrame containing indicators and buy/sell signals :param data: OHLCV DataFrame containing indicators and entry/exit signals
:param trades: All trades created :param trades: All trades created
:param indicators1: List containing Main plot indicators :param indicators1: List containing Main plot indicators
:param indicators2: List containing Sub plot indicators :param indicators2: List containing Sub plot indicators

View File

@ -72,7 +72,7 @@ def test_add_indicators(default_conf, testdatadir, caplog):
strategy = StrategyResolver.load_strategy(default_conf) strategy = StrategyResolver.load_strategy(default_conf)
# Generate buy/sell signals and indicators # Generate entry/exit signals and indicators
data = strategy.analyze_ticker(data, {'pair': pair}) data = strategy.analyze_ticker(data, {'pair': pair})
fig = generate_empty_figure() fig = generate_empty_figure()
@ -113,7 +113,7 @@ def test_add_areas(default_conf, testdatadir, caplog):
ind_plain = {"macd": {"fill_to": "macdhist"}} ind_plain = {"macd": {"fill_to": "macdhist"}}
strategy = StrategyResolver.load_strategy(default_conf) strategy = StrategyResolver.load_strategy(default_conf)
# Generate buy/sell signals and indicators # Generate entry/exit signals and indicators
data = strategy.analyze_ticker(data, {'pair': pair}) data = strategy.analyze_ticker(data, {'pair': pair})
fig = generate_empty_figure() fig = generate_empty_figure()
@ -165,24 +165,24 @@ def test_plot_trades(testdatadir, caplog):
fig = plot_trades(fig, trades) fig = plot_trades(fig, trades)
figure = fig1.layout.figure figure = fig1.layout.figure
# Check buys - color, should be in first graph, ... # Check entry - color, should be in first graph, ...
trade_buy = find_trace_in_fig_data(figure.data, 'Trade buy') trade_entries = find_trace_in_fig_data(figure.data, 'Trade entry')
assert isinstance(trade_buy, go.Scatter) assert isinstance(trade_entries, go.Scatter)
assert trade_buy.yaxis == 'y' assert trade_entries.yaxis == 'y'
assert len(trades) == len(trade_buy.x) assert len(trades) == len(trade_entries.x)
assert trade_buy.marker.color == 'cyan' assert trade_entries.marker.color == 'cyan'
assert trade_buy.marker.symbol == 'circle-open' assert trade_entries.marker.symbol == 'circle-open'
assert trade_buy.text[0] == '3.99%, buy_tag, roi, 15 min' assert trade_entries.text[0] == '3.99%, buy_tag, roi, 15 min'
trade_sell = find_trace_in_fig_data(figure.data, 'Sell - Profit') trade_exit = find_trace_in_fig_data(figure.data, 'Exit - Profit')
assert isinstance(trade_sell, go.Scatter) assert isinstance(trade_exit, go.Scatter)
assert trade_sell.yaxis == 'y' assert trade_exit.yaxis == 'y'
assert len(trades.loc[trades['profit_ratio'] > 0]) == len(trade_sell.x) assert len(trades.loc[trades['profit_ratio'] > 0]) == len(trade_exit.x)
assert trade_sell.marker.color == 'green' assert trade_exit.marker.color == 'green'
assert trade_sell.marker.symbol == 'square-open' assert trade_exit.marker.symbol == 'square-open'
assert trade_sell.text[0] == '3.99%, buy_tag, roi, 15 min' assert trade_exit.text[0] == '3.99%, buy_tag, roi, 15 min'
trade_sell_loss = find_trace_in_fig_data(figure.data, 'Sell - Loss') trade_sell_loss = find_trace_in_fig_data(figure.data, 'Exit - Loss')
assert isinstance(trade_sell_loss, go.Scatter) assert isinstance(trade_sell_loss, go.Scatter)
assert trade_sell_loss.yaxis == 'y' assert trade_sell_loss.yaxis == 'y'
assert len(trades.loc[trades['profit_ratio'] <= 0]) == len(trade_sell_loss.x) assert len(trades.loc[trades['profit_ratio'] <= 0]) == len(trade_sell_loss.x)