Custom indicator disappears during live trading
I'm starting to try live trading with my startegy which has up to now only been backtested.
I have a custom indicator and a custom analyzer which both run fine during backtesting, however now I'm trying to run the same strat live (using the ccxtbt store for Binance) and this is what happens:
class customIndicator(bt.Indicator): lines = ('someLine') params = (('dataClose', 0)) plotlines = dict(someLine = dict(_name='someLine', color='green', linewidth = 1, alpha=0.9)) def __init__(self): self.l.someLine = ... class customAnalyzer(Analyzer): def __init__(self): self.var = 0 def start(self): pass def next(self): if (self.strategy.customIndicator.l.someLine > 10): self.var += 1 ... def stop(self): ... def get_analysis(self): return dict(var = self.var)
Obviously I simplified the example code to it's essence.
This is the error I get:
File "...main.py", line 221, in next if (self.strategy.customIndicator.l.someLine > 10): File "...\lib\site-packages\backtrader\lineseries.py", line 461, in __getattr__ return getattr(self.lines, name) AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'customIndicator'
So for some reason the customIndicator has not yet been initialised, but the
In the analyzer is already being called. Is this normal? Why is this different during Live trading than backtesting?
Apparantly I had simply forgotten to add the strategy when live trading using
This also meant none of the indicators were initialized...
Hope this helps someone!