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[0], 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.
-
@winefx based on examples shown in docs, you may need to subclass an indicator and use
plotlines
inside new class. I did it this way when modified line properties. -
@winefx said in Change name of a line in indicator:
x.plotlines = dict(momentum=dict(_name='mymomentum'))
You are actually removing the existing
plotlines
object and replacing it with adict
. Using adict
(or atuple
) works when you are declaring theplotlines
, 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.