Plot with filled area
I was trying to create filled area plot for the broker
valueobserver. I've sub-classed existing
zeroline, and filled area between
zerolines, same approach as you used for ichimoku indicator. Finally ended with the following code:
class ValueFilled(bt.Observer): lines = ('pnl', 'zero',) params = (('initial_cash', None),) plotinfo = dict(plot=True, subplot=True, plotname='Cumulative P/L') plotlines = dict(pnl=dict(ls='-', linewidth=1.0, color='black', _fill_gt=('zero', 'green'), _fill_lt=('zero', 'red'),), zero=dict(_plotskip=True,), ) def next(self): self.lines.pnl = self._owner.broker.getvalue() - self.p.initial_cash self.lines.zero = 0.0
Is there any easier way to draw filled area under/below the line? In the
plot.pyI've fond only
ax.fill_betweenmethod, so created second line above to use it.
Here is the link to the picture picture
Somehow pictures inserted into the post usually don't show up.
Not now. But it would seem sensible to support not only a line name as the reference to fill (above/below) but also a numeric value.
You may try this commit: https://github.com/mementum/backtrader/commit/8ef8555d4fd5685b4811c848009bcd19e553e4a4
Since this is re-written, could you please get hard-coded
alpha(line 471 of the
plot.py) for the fill to 'plotlines' parameter level?
The latest commit to
The Docs - Plotting has been updated to reflect the possibilities (you may need to use
Shift + F5to bypass the browser cache)
@backtrader Thank you!
It seems that you have a typo in the docs:
At least latter works.
Better in the docs as in the code. Updated