For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Custom indicator disappears during live trading
-
Hi all,
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[0] > 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[0] > 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
def next(self):
In the analyzer is already being called. Is this normal? Why is this different during Live trading than backtesting?
Kind regards,
Fred -
Apparantly I had simply forgotten to add the strategy when live trading using
cerebro.addstrategy( TestStrategy)
This also meant none of the indicators were initialized...
Hope this helps someone!