Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Change name of a line in indicator

    Indicators/Strategies/Analyzers
    3
    5
    1423
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      winefx last edited by winefx

      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.

      A B 2 Replies Last reply Reply Quote 0
      • A
        ab_trader @winefx last edited by

        @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.

        docs - plotting

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @winefx last edited by

          @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 a dict. Using a dict (or 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.

          W 1 Reply Last reply Reply Quote 0
          • W
            winefx @backtrader last edited by

            @backtrader Great thanks!

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }