renaming, comments, cleanups

This commit is contained in:
Christof 2020-12-19 21:37:52 +01:00
parent fabb31e1bc
commit c1b8ad7232

View File

@ -263,10 +263,10 @@ def create_plotconfig(indicators1: List[str], indicators2: List[str],
return plot_config return plot_config
def plot_area_between(fig, row: int, data: pd.DataFrame, indicator_a: str, def plot_area(fig, row: int, data: pd.DataFrame, indicator_a: str,
indicator_b: str, label: str = "", indicator_b: str, label: str = "",
fill_color: str = "rgba(0,176,246,0.2)") -> make_subplots: fill_color: str = "rgba(0,176,246,0.2)") -> make_subplots:
""" Creates plot for the area between two traces and adds it to fig. """ Creates a plot for the area between two traces and adds it to fig.
:param fig: Plot figure to append to :param fig: Plot figure to append to
:param row: row number for this plot :param row: row number for this plot
:param data: candlestick DataFrame :param data: candlestick DataFrame
@ -277,6 +277,7 @@ def plot_area_between(fig, row: int, data: pd.DataFrame, indicator_a: str,
:return: fig with added filled_traces plot :return: fig with added filled_traces plot
""" """
if indicator_a in data and indicator_b in data: if indicator_a in data and indicator_b in data:
# make lines invisible to get the area plotted, only.
line = {'color': 'rgba(255,255,255,0)'} line = {'color': 'rgba(255,255,255,0)'}
# TODO: Figure out why scattergl causes problems plotly/plotly.js#2284 # TODO: Figure out why scattergl causes problems plotly/plotly.js#2284
trace_a = go.Scatter(x=data.date, y=data[indicator_a], trace_a = go.Scatter(x=data.date, y=data[indicator_a],
@ -303,10 +304,11 @@ def add_areas(fig, row: int, data: pd.DataFrame, indicators) -> make_subplots:
if 'fill_to' in ind_conf: if 'fill_to' in ind_conf:
indicator_b = ind_conf['fill_to'] indicator_b = ind_conf['fill_to']
if indicator in data and indicator_b in data: if indicator in data and indicator_b in data:
label = ind_conf.get('fill_label', '') label = ind_conf.get('fill_label',
f'{indicator}<>{indicator_b}')
fill_color = ind_conf.get('fill_color', 'rgba(0,176,246,0.2)') fill_color = ind_conf.get('fill_color', 'rgba(0,176,246,0.2)')
fig = plot_area_between(fig, row, data, indicator, indicator_b, fig = plot_area(fig, row, data, indicator, indicator_b,
label=label, fill_color=fill_color) label=label, fill_color=fill_color)
elif indicator not in data: elif indicator not in data:
logger.info( logger.info(
'Indicator "%s" ignored. Reason: This indicator is not ' 'Indicator "%s" ignored. Reason: This indicator is not '
@ -402,25 +404,20 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
fig.add_trace(sells, 1, 1) fig.add_trace(sells, 1, 1)
else: else:
logger.warning("No sell-signals found.") logger.warning("No sell-signals found.")
# Add Bollinger Bands # Add Bollinger Bands
fig = plot_area_between(fig, 1, data, 'bb_lowerband', 'bb_upperband', fig = plot_area(fig, 1, data, 'bb_lowerband', 'bb_upperband',
label="Bollinger Band") label="Bollinger Band")
# prevent bb_lower and bb_upper from plotting # prevent bb_lower and bb_upper from plotting
try: try:
del plot_config['main_plot']['bb_lowerband'] del plot_config['main_plot']['bb_lowerband']
del plot_config['main_plot']['bb_upperband'] del plot_config['main_plot']['bb_upperband']
except KeyError: except KeyError:
pass pass
# main plot goes to row 1
# Add indicators to main plot
fig = add_indicators(fig=fig, row=1, indicators=plot_config['main_plot'], data=data) fig = add_indicators(fig=fig, row=1, indicators=plot_config['main_plot'], data=data)
# fill area between indicators ( 'fill_to': 'other_indicator')
fig = add_areas(fig, 1, data, plot_config['main_plot']) fig = add_areas(fig, 1, data, plot_config['main_plot'])
fig = plot_trades(fig, trades) fig = plot_trades(fig, trades)
# sub plot: Volume goes to row 2
# Volume goes to row 2
volume = go.Bar( volume = go.Bar(
x=data['date'], x=data['date'],
y=data['volume'], y=data['volume'],
@ -429,8 +426,7 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
marker_line_color='DarkSlateGrey' marker_line_color='DarkSlateGrey'
) )
fig.add_trace(volume, 2, 1) fig.add_trace(volume, 2, 1)
# Add each sub plot to a separate row
# Add indicators to separate row
for i, label in enumerate(plot_config['subplots']): for i, label in enumerate(plot_config['subplots']):
sub_config = plot_config['subplots'][label] sub_config = plot_config['subplots'][label]
row = 3 + i row = 3 + i
@ -438,7 +434,6 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
data=data) data=data)
# fill area between indicators ( 'fill_to': 'other_indicator') # fill area between indicators ( 'fill_to': 'other_indicator')
fig = add_areas(fig, row, data, sub_config) fig = add_areas(fig, row, data, sub_config)
return fig return fig