For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Unable to use LinePlotterIndicator

  • I calculated an indicator externally and add it to the datafeed extending Pandas datafeed.
    Now I want to show in the chart this indicator.

    # Create a Stratey
    class FTB3Strategy(bt.Strategy):
       params = (
           ('slots', 1),
       def __init__(self):
           for d in self.datas:
               bt.LinePlotterIndicator(, name='SS')
           # to show date/time progress
           self.trace  = 0

    Error Trace:

    <ipython-input-66-1fe598047c76> in __init__(self)
        20         for d in self.datas:
    ---> 21             bt.LinePlotterIndicator(, name='SS')
        22         # to show date/time progress
        23         self.trace  = 0
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\ in __call__(cls, *args, **kwargs)
        51     def __call__(cls, *args, **kwargs):
        52         if not cls._icacheuse:
    ---> 53             return super(MetaIndicator, cls).__call__(*args, **kwargs)
        55         # implement a cache to avoid duplicating lines actions
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\ in __call__(cls, *args, **kwargs)
        84     def __call__(cls, *args, **kwargs):
        85         cls, args, kwargs = cls.doprenew(*args, **kwargs)
    ---> 86         _obj, args, kwargs = cls.donew(*args, **kwargs)
        87         _obj, args, kwargs = cls.dopreinit(_obj, *args, **kwargs)
        88         _obj, args, kwargs = cls.doinit(_obj, *args, **kwargs)
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\ in donew(cls, *args, **kwargs)
       154             super(MtLinePlotterIndicator, cls).donew(*args, **kwargs)
    --> 156         _obj.owner =
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\backtrader\ in __getattr__(self, name)
       459         # in this object if we set an attribute in this object it will be
       460         # found before we end up here
    --> 461         return getattr(self.lines, name)
       463     def __len__(self):
    AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute '_clock'

    Am I doing something wrong?

  • @ernegraf I've found a workaround/solution using a dummy line (instantiating abstract line):

        def __init__(self):
            dummy_lines = dict()
            for d in self.datas:
                dummy_lines[d._name] = * 1.0
                bt.LinePlotterIndicator(dummy_lines[d._name], name='SS:'+d._name, 
                                        subplot=False, plotmaster=d)
            # to show date/time progress
            self.trace  = 0

  • administrators

    @ernegraf said in Unable to use LinePlotterIndicator:

    Am I doing something wrong?

    You were trying to plot pure "data" lines. The LinePlotterIndicator was conceived to plot things that are created as temporary operations inside the Strategy, but which you don't want to wrap/package as an Indicator

    @ernegraf said in Unable to use LinePlotterIndicator:

    dummy_lines[d._name] = * 1.0

    With this action you convert the pure data lines into a temporary line which can be a target for LinePlotterIndicator

Log in to reply