Clearly differentiate trade buys sells (positive and negative)
* Swap trade buys to cyan circles * Show sell-reason description on buy too * Green positive sells - red negative / 0 sells
This commit is contained in:
parent
bdda620397
commit
53499e01de
@ -113,11 +113,31 @@ 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
|
||||||
|
trades['desc'] = trades.apply(lambda row: f"{round(row['profitperc'] * 100, 1)}%, "
|
||||||
|
f"{row['sell_reason']}, {row['duration']} min",
|
||||||
|
axis=1)
|
||||||
trade_buys = go.Scatter(
|
trade_buys = go.Scatter(
|
||||||
x=trades["open_time"],
|
x=trades["open_time"],
|
||||||
y=trades["open_rate"],
|
y=trades["open_rate"],
|
||||||
mode='markers',
|
mode='markers',
|
||||||
name='trade_buy',
|
name='Trade buy',
|
||||||
|
text=trades["desc"],
|
||||||
|
marker=dict(
|
||||||
|
symbol='circle-open',
|
||||||
|
size=11,
|
||||||
|
line=dict(width=2),
|
||||||
|
color='cyan'
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
trade_sells = go.Scatter(
|
||||||
|
x=trades.loc[trades['profitperc'] > 0, "close_time"],
|
||||||
|
y=trades.loc[trades['profitperc'] > 0, "close_rate"],
|
||||||
|
text=trades.loc[trades['profitperc'] > 0, "desc"],
|
||||||
|
mode='markers',
|
||||||
|
name='Sell - Profit',
|
||||||
marker=dict(
|
marker=dict(
|
||||||
symbol='square-open',
|
symbol='square-open',
|
||||||
size=11,
|
size=11,
|
||||||
@ -125,16 +145,12 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
|
|||||||
color='green'
|
color='green'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Create description for sell summarizing the trade
|
trade_sells_loss = go.Scatter(
|
||||||
desc = trades.apply(lambda row: f"{round(row['profitperc'] * 100, 1)}%, "
|
x=trades.loc[trades['profitperc'] <= 0, "close_time"],
|
||||||
f"{row['sell_reason']}, {row['duration']} min",
|
y=trades.loc[trades['profitperc'] <= 0, "close_rate"],
|
||||||
axis=1)
|
text=trades.loc[trades['profitperc'] <= 0, "desc"],
|
||||||
trade_sells = go.Scatter(
|
|
||||||
x=trades["close_time"],
|
|
||||||
y=trades["close_rate"],
|
|
||||||
text=desc,
|
|
||||||
mode='markers',
|
mode='markers',
|
||||||
name='trade_sell',
|
name='Sell - Loss',
|
||||||
marker=dict(
|
marker=dict(
|
||||||
symbol='square-open',
|
symbol='square-open',
|
||||||
size=11,
|
size=11,
|
||||||
@ -144,6 +160,7 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots:
|
|||||||
)
|
)
|
||||||
fig.add_trace(trade_buys, 1, 1)
|
fig.add_trace(trade_buys, 1, 1)
|
||||||
fig.add_trace(trade_sells, 1, 1)
|
fig.add_trace(trade_sells, 1, 1)
|
||||||
|
fig.add_trace(trade_sells_loss, 1, 1)
|
||||||
else:
|
else:
|
||||||
logger.warning("No trades found.")
|
logger.warning("No trades found.")
|
||||||
return fig
|
return fig
|
||||||
|
@ -110,18 +110,29 @@ def test_plot_trades(testdatadir, caplog):
|
|||||||
figure = fig1.layout.figure
|
figure = fig1.layout.figure
|
||||||
|
|
||||||
# Check buys - color, should be in first graph, ...
|
# Check buys - color, should be in first graph, ...
|
||||||
trade_buy = find_trace_in_fig_data(figure.data, "trade_buy")
|
trade_buy = find_trace_in_fig_data(figure.data, 'Trade buy')
|
||||||
assert isinstance(trade_buy, go.Scatter)
|
assert isinstance(trade_buy, go.Scatter)
|
||||||
assert trade_buy.yaxis == 'y'
|
assert trade_buy.yaxis == 'y'
|
||||||
assert len(trades) == len(trade_buy.x)
|
assert len(trades) == len(trade_buy.x)
|
||||||
assert trade_buy.marker.color == 'green'
|
assert trade_buy.marker.color == 'cyan'
|
||||||
|
assert trade_buy.marker.symbol == 'circle-open'
|
||||||
|
assert trade_buy.text[0] == '4.0%, roi, 15 min'
|
||||||
|
|
||||||
trade_sell = find_trace_in_fig_data(figure.data, "trade_sell")
|
trade_sell = find_trace_in_fig_data(figure.data, 'Sell - Profit')
|
||||||
assert isinstance(trade_sell, go.Scatter)
|
assert isinstance(trade_sell, go.Scatter)
|
||||||
assert trade_sell.yaxis == 'y'
|
assert trade_sell.yaxis == 'y'
|
||||||
assert len(trades) == len(trade_sell.x)
|
assert len(trades.loc[trades['profitperc'] > 0]) == len(trade_sell.x)
|
||||||
assert trade_sell.marker.color == 'red'
|
assert trade_sell.marker.color == 'green'
|
||||||
assert trade_sell.text[0] == "4.0%, roi, 15 min"
|
assert trade_sell.marker.symbol == 'square-open'
|
||||||
|
assert trade_sell.text[0] == '4.0%, roi, 15 min'
|
||||||
|
|
||||||
|
trade_sell_loss = find_trace_in_fig_data(figure.data, 'Sell - Loss')
|
||||||
|
assert isinstance(trade_sell_loss, go.Scatter)
|
||||||
|
assert trade_sell_loss.yaxis == 'y'
|
||||||
|
assert len(trades.loc[trades['profitperc'] <= 0]) == len(trade_sell_loss.x)
|
||||||
|
assert trade_sell_loss.marker.color == 'red'
|
||||||
|
assert trade_sell_loss.marker.symbol == 'square-open'
|
||||||
|
assert trade_sell_loss.text[5] == '-10.4%, stop_loss, 720 min'
|
||||||
|
|
||||||
|
|
||||||
def test_generate_candlestick_graph_no_signals_no_trades(default_conf, mocker, testdatadir, caplog):
|
def test_generate_candlestick_graph_no_signals_no_trades(default_conf, mocker, testdatadir, caplog):
|
||||||
|
Loading…
Reference in New Issue
Block a user