kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
901 stars 210 forks source link

Divergencies not plot again #92

Open o-evgeny opened 7 months ago

o-evgeny commented 7 months ago

`` from finta import TA

from autotrader.autodata import GetData

from autotrader.autoplot import AutoPlot from autotrader.indicators import crossover, cross_values from autotrader import indicators

get_data = GetData()

instrument = 'AAPL' get_data = AutoData({'data_source': 'yahoo'}) data = get_data.fetch(instrument, '1d', start_time='2020-01-01', end_time='2021-01-01') rsi=TA.RSI(data,14) ema50=TA.EMA(data) rsi_divergence = indicators.autodetect_divergence(ema50, rsi) indicator_dict = { 'EMA (50)': {'type': 'MA', 'data': ema50}, 'RSI (14)': {'type': 'RSI', 'data': rsi}, 'Bullish divergence': {'type': 'below', 'data': pd.Series(rsi_divergence['regularBull'])}, }

ap = AutoPlot(ema50) ap.plot(indicators=indicator_dict,instrument='aapl') ``

Got error:

[*****100%%**] 1 of 1 completed


KeyError Traceback (most recent call last) Cell In[58], line 31 21 indicator_dict = { 22 'EMA (50)': {'type': 'MA', 23 'data': ema50}, (...) 27 'data': pd.Series(rsi_divergence['regularBull'])}, 28 } 30 ap = AutoPlot(ema50) ---> 31 ap.plot(indicators=indicator_dict,instrument='aapl')

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/autotrader/autoplot.py:380, in AutoPlot.plot(self, instrument, indicators, trade_results, show_fig) 375 # if len(open_trades) > 0: 376 # self._plot_trade_history(open_trades, main_plot, open_summary=True) 377 378 # Indicators 379 if indicators is not None: --> 380 bottom_figs = self._plot_indicators(indicators, main_plot) 382 # Auto-scale y-axis of candlestick chart 383 main_plot.x_range.js_on_change( 384 "end", CustomJS(args=self.autoscale_args, code=self._autoscale_code) 385 )

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/autotrader/autoplot.py:1059, in AutoPlot._plot_indicators(self, indicators, linked_fig) 1057 if indicators[indicator]["data"].name is None: 1058 indicators[indicator]["data"].name = "data" -> 1059 line_source = self._create_line_source( 1060 indicators[indicator]["data"] 1061 ) 1062 else: 1063 raise Exception("Plot data must be a timeseries.")

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/autotrader/autoplot.py:1113, in AutoPlot._create_line_source(self, indicator_data) 1111 merged_indicator_data.fillna(method="bfill", inplace=True) 1112 data_name = indicator_data.name -> 1113 line_source = ColumnDataSource(merged_indicator_data[[data_name, "data_index"]]) 1114 line_source.add(merged_indicator_data[data_name].values, "High") 1115 line_source.add(merged_indicator_data[data_name].values, "Low")

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/pandas/core/frame.py:3811, in DataFrame.getitem(self, key) 3809 if is_iterator(key): 3810 key = list(key) -> 3811 indexer = self.columns._get_indexer_strict(key, "columns")[1] 3813 # take() does not accept boolean indexers 3814 if getattr(indexer, "dtype", None) == bool:

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/pandas/core/indexes/base.py:6113, in Index._get_indexer_strict(self, key, axis_name) 6110 else: 6111 keyarr, indexer, new_indexer = self._reindex_non_unique(keyarr) -> 6113 self._raise_if_missing(keyarr, indexer, axis_name) 6115 keyarr = self.take(indexer) 6116 if isinstance(key, Index): 6117 # GH 42790 - Preserve name from an Index

File /opt/anaconda3/envs/work/lib/python3.10/site-packages/pandas/core/indexes/base.py:6176, in Index._raise_if_missing(self, key, indexer, axis_name) 6173 raise KeyError(f"None of [{key}] are in the [{axis_name}]") 6175 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique()) -> 6176 raise KeyError(f"{not_found} not in index")

KeyError: "['plot_data'] not in index"

o-evgeny commented 7 months ago

please, @kieran-mackle