Skip to content

Commit

Permalink
Cover case in which lines wrapped in a LineSeriesStup are a clock in …
Browse files Browse the repository at this point in the history
…the strategy (and maybe the only clock actually)
  • Loading branch information
backtrader committed Oct 11, 2018
1 parent 74a265b commit b7efdcd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion backtrader/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import backtrader as bt
from .lineiterator import LineIterator, StrategyBase
from .lineroot import LineSingle
from .lineseries import LineSeriesStub
from .metabase import ItemCollection, findowner
from .trade import Trade
from .utils import OrderedDict, AutoOrderedDict, AutoDictList
Expand Down Expand Up @@ -181,11 +182,30 @@ def _periodset(self):
if clk is None:
continue # no clock found, go to next

# LineSeriesStup wraps a line and the clock is the wrapped line and
# no the wrapper itself.
if isinstance(clk, LineSeriesStub):
clk = clk.lines[0]

_dminperiods[clk].append(lineiter._minperiod)

self._minperiods = list()
for data in self.datas:
# dminperiod = max(_dminperiods[data] or [self._minperiod])

# Do not only consider the data as clock but also its lines which
# may have been individually passed as clock references and
# discovered as clocks above

# Initialize with data min period if any
dlminperiods = _dminperiods[data]

for l in data.lines: # search each line for min periods
if l in _dminperiods:
dlminperiods += _dminperiods[l] # found, add it

# keep the reference to the line if any was found
_dminperiods[data] = [max(dlminperiods)] if dlminperiods else []

dminperiod = max(_dminperiods[data] or [data._minperiod])
self._minperiods.append(dminperiod)

Expand Down

0 comments on commit b7efdcd

Please sign in to comment.