mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Merge pull request #2297 from jraviotta/scattergl
Enhancements to BB plotting
This commit is contained in:
commit
553a1b90ba
|
@ -64,14 +64,13 @@ def add_indicators(fig, row, indicators: List[str], data: pd.DataFrame) -> make_
|
||||||
"""
|
"""
|
||||||
for indicator in indicators:
|
for indicator in indicators:
|
||||||
if indicator in data:
|
if indicator in data:
|
||||||
# TODO: Figure out why scattergl causes problems
|
scatter = go.Scatter(
|
||||||
scattergl = go.Scatter(
|
|
||||||
x=data['date'],
|
x=data['date'],
|
||||||
y=data[indicator].values,
|
y=data[indicator].values,
|
||||||
mode='lines',
|
mode='lines',
|
||||||
name=indicator
|
name=indicator
|
||||||
)
|
)
|
||||||
fig.add_trace(scattergl, row, 1)
|
fig.add_trace(scatter, row, 1)
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Indicator "%s" ignored. Reason: This indicator is not found '
|
'Indicator "%s" ignored. Reason: This indicator is not found '
|
||||||
|
@ -92,7 +91,7 @@ def add_profit(fig, row, data: pd.DataFrame, column: str, name: str) -> make_sub
|
||||||
:param name: Name to use
|
:param name: Name to use
|
||||||
:return: fig with added profit plot
|
:return: fig with added profit plot
|
||||||
"""
|
"""
|
||||||
profit = go.Scattergl(
|
profit = go.Scatter(
|
||||||
x=data.index,
|
x=data.index,
|
||||||
y=data[column],
|
y=data[column],
|
||||||
name=name,
|
name=name,
|
||||||
|
@ -221,23 +220,27 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
|
||||||
else:
|
else:
|
||||||
logger.warning("No sell-signals found.")
|
logger.warning("No sell-signals found.")
|
||||||
|
|
||||||
|
# TODO: Figure out why scattergl causes problems plotly/plotly.js#2284
|
||||||
if 'bb_lowerband' in data and 'bb_upperband' in data:
|
if 'bb_lowerband' in data and 'bb_upperband' in data:
|
||||||
bb_lower = go.Scattergl(
|
bb_lower = go.Scatter(
|
||||||
x=data.date,
|
x=data.date,
|
||||||
y=data.bb_lowerband,
|
y=data.bb_lowerband,
|
||||||
name='BB lower',
|
showlegend=False,
|
||||||
line={'color': 'rgba(255,255,255,0)'},
|
line={'color': 'rgba(255,255,255,0)'},
|
||||||
)
|
)
|
||||||
bb_upper = go.Scattergl(
|
bb_upper = go.Scatter(
|
||||||
x=data.date,
|
x=data.date,
|
||||||
y=data.bb_upperband,
|
y=data.bb_upperband,
|
||||||
name='BB upper',
|
name='Bollinger Band',
|
||||||
fill="tonexty",
|
fill="tonexty",
|
||||||
fillcolor="rgba(0,176,246,0.2)",
|
fillcolor="rgba(0,176,246,0.2)",
|
||||||
line={'color': 'rgba(255,255,255,0)'},
|
line={'color': 'rgba(255,255,255,0)'},
|
||||||
)
|
)
|
||||||
fig.add_trace(bb_lower, 1, 1)
|
fig.add_trace(bb_lower, 1, 1)
|
||||||
fig.add_trace(bb_upper, 1, 1)
|
fig.add_trace(bb_upper, 1, 1)
|
||||||
|
if 'bb_upperband' in indicators1 and 'bb_lowerband' in indicators1:
|
||||||
|
indicators1.remove('bb_upperband')
|
||||||
|
indicators1.remove('bb_lowerband')
|
||||||
|
|
||||||
# Add indicators to main plot
|
# Add indicators to main plot
|
||||||
fig = add_indicators(fig=fig, row=1, indicators=indicators1, data=data)
|
fig = add_indicators(fig=fig, row=1, indicators=indicators1, data=data)
|
||||||
|
@ -248,11 +251,13 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
|
||||||
volume = go.Bar(
|
volume = go.Bar(
|
||||||
x=data['date'],
|
x=data['date'],
|
||||||
y=data['volume'],
|
y=data['volume'],
|
||||||
name='Volume'
|
name='Volume',
|
||||||
)
|
marker_color='DarkSlateGrey',
|
||||||
|
marker_line_color='DarkSlateGrey'
|
||||||
|
)
|
||||||
fig.add_trace(volume, 2, 1)
|
fig.add_trace(volume, 2, 1)
|
||||||
|
|
||||||
# Add indicators to seperate row
|
# Add indicators to separate row
|
||||||
fig = add_indicators(fig=fig, row=3, indicators=indicators2, data=data)
|
fig = add_indicators(fig=fig, row=3, indicators=indicators2, data=data)
|
||||||
|
|
||||||
return fig
|
return fig
|
||||||
|
@ -267,7 +272,7 @@ def generate_profit_graph(pairs: str, tickers: Dict[str, pd.DataFrame],
|
||||||
df_comb = create_cum_profit(df_comb, trades, 'cum_profit')
|
df_comb = create_cum_profit(df_comb, trades, 'cum_profit')
|
||||||
|
|
||||||
# Plot the pairs average close prices, and total profit growth
|
# Plot the pairs average close prices, and total profit growth
|
||||||
avgclose = go.Scattergl(
|
avgclose = go.Scatter(
|
||||||
x=df_comb.index,
|
x=df_comb.index,
|
||||||
y=df_comb['mean'],
|
y=df_comb['mean'],
|
||||||
name='Avg close price',
|
name='Avg close price',
|
||||||
|
|
|
@ -197,8 +197,7 @@ def test_generate_candlestick_graph_no_trades(default_conf, mocker, testdatadir)
|
||||||
# All buy-signals should be plotted
|
# All buy-signals should be plotted
|
||||||
assert int(data.sell.sum()) == len(sell.x)
|
assert int(data.sell.sum()) == len(sell.x)
|
||||||
|
|
||||||
assert find_trace_in_fig_data(figure.data, "BB lower")
|
assert find_trace_in_fig_data(figure.data, "Bollinger Band")
|
||||||
assert find_trace_in_fig_data(figure.data, "BB upper")
|
|
||||||
|
|
||||||
assert row_mock.call_count == 2
|
assert row_mock.call_count == 2
|
||||||
assert trades_mock.call_count == 1
|
assert trades_mock.call_count == 1
|
||||||
|
@ -239,7 +238,7 @@ def test_add_profit(testdatadir):
|
||||||
fig1 = add_profit(fig, row=2, data=cum_profits, column='cum_profits', name='Profits')
|
fig1 = add_profit(fig, row=2, data=cum_profits, column='cum_profits', name='Profits')
|
||||||
figure = fig1.layout.figure
|
figure = fig1.layout.figure
|
||||||
profits = find_trace_in_fig_data(figure.data, "Profits")
|
profits = find_trace_in_fig_data(figure.data, "Profits")
|
||||||
assert isinstance(profits, go.Scattergl)
|
assert isinstance(profits, go.Scatter)
|
||||||
assert profits.yaxis == "y2"
|
assert profits.yaxis == "y2"
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,14 +267,14 @@ def test_generate_profit_graph(testdatadir):
|
||||||
assert len(figure.data) == 4
|
assert len(figure.data) == 4
|
||||||
|
|
||||||
avgclose = find_trace_in_fig_data(figure.data, "Avg close price")
|
avgclose = find_trace_in_fig_data(figure.data, "Avg close price")
|
||||||
assert isinstance(avgclose, go.Scattergl)
|
assert isinstance(avgclose, go.Scatter)
|
||||||
|
|
||||||
profit = find_trace_in_fig_data(figure.data, "Profit")
|
profit = find_trace_in_fig_data(figure.data, "Profit")
|
||||||
assert isinstance(profit, go.Scattergl)
|
assert isinstance(profit, go.Scatter)
|
||||||
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}")
|
profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}")
|
||||||
assert isinstance(profit_pair, go.Scattergl)
|
assert isinstance(profit_pair, go.Scatter)
|
||||||
|
|
||||||
|
|
||||||
def test_start_plot_dataframe(mocker):
|
def test_start_plot_dataframe(mocker):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user