Change name of a line in indicator
Hi, I'm new to backtrader.... How do I change the _name of a line in a indicator? I tried:
x = btind.Momentum(self.datas, period=7, plotname='MyMomentum') x.plotlines = dict(momentum=dict(_name='mymomentum'))
The plotname is changed to MyMomentum, but the line name is still 'momentum' instead of 'mymomentum'. Thanks.
x.plotlines = dict(momentum=dict(_name='mymomentum'))
You are actually removing the existing
plotlinesobject and replacing it with a
dict. Using a
tuple) works when you are declaring the
plotlines, but in this case you are removing what the platform has done in the background.
x.plotlines.momentum._name = `mymomentum`
should do the trick.
@backtrader Great thanks!
The alternative as suggested by @ab_trader is to subclass the indicator and then do what you did with the dictionary assignment in the class declaration.
It is obviously a more permanent solution.