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/

    Plotting: how to get lines to have specific colours and thickness?

    General Code/Help
    4
    4
    2215
    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.
    • R
      randomshinichi last edited by randomshinichi

      I just want to customize the colours and thicknesses of the various lines in Ichimoku.
      I had no idea it was going to be this hard:

      1. There is no way to customize colours using the plotinfo variable, so I have to do this via PlotScheme (which didn't work either)
      2. There also isn't a way to customize line thickness, only on horizontal lines. Why?

      From the documentation on Plotting:
      https://www.backtrader.com/docu/plotting/plotting.html

      I can pass a custom list to cerebro.plot as lcolors:
      lcolors=['blue', 'green', 'red', 'turquoise']

      But since PlotScheme.color() uses tab10_index, I cannot change the order in which the colours are used!
      tab10_index = [3, 0, 2, 1, 2, 4, 5, 6, 7, 8, 9]
      So since 'turquoise' is index 3, it will be used first. Then blue, red, green. Why does there need to be an array that picks specific colours from the Tableau 10 palette in that specific order anyway?

      OK, let's say the proper solution is to subclass PlotScheme. But I cannot import it either, even though I can import every other folder around it, and there is a init.py in backtrader/plot/:

      In [3]: import backtrader as bt
      
      In [4]: bt.plot
      ---------------------------------------------------------------------------
      AttributeError                            Traceback (most recent call last)
      <ipython-input-4-f26508c6d1b4> in <module>()
      ----> 1 bt.plot
      
      AttributeError: module 'backtrader' has no attribute 'plot'
      
      In [5]: bt.observers
      Out[5]: <module 'backtrader.observers' from '/Users/shinichi/source/cryptocoins/backtrader/observers/__init__.py'>
      
      In [6]: bt.signals
      Out[6]: <module 'backtrader.signals' from '/Users/shinichi/source/cryptocoins/backtrader/signals/__init__.py'>
      
      In [7]: bt.sizers
      Out[7]: <module 'backtrader.sizers' from '/Users/shinichi/source/cryptocoins/backtrader/sizers/__init__.py'>
      
      In [8]: bt.stores
      Out[8]: <module 'backtrader.stores' from '/Users/shinichi/source/cryptocoins/backtrader/stores/__init__.py'>
      
      In [9]: 
      

      I must be missing something here because backtrader looks pythonic, but is actually very confusing.

      The documentation should make it more obvious that in order to customize plotting, the intended route is to subclass the Indicator and override its self.plotlines via self._plotinit(). Looking at plotlines=(dict()) doesn't help.

      1 Reply Last reply Reply Quote 0
      • PeterCHK
        PeterCHK last edited by

        I spent some time investigating this problem also.

        For multiple lines plotting, I managed to change the colour inside ichimoku.py with plotlines.

        Just paste the following inside the ichimoku.py and restart the iPython to make it work.

        plotlines = dict(
            senkou_span_a=dict(_fill_gt=('senkou_span_b', 'cyan'),
                               _fill_lt=('senkou_span_b', 'magenta'),
                               color='blue'),
            
            senkou_span_b=dict(color='yellow'),
                               
            tenkan_sen=dict(_name='TenK', color='red'),
                            
            kijun_sen=dict(_name='KJ',color='green'),
            
            chikou_span=dict(_name='chi', color='black')
            
        )
        1 Reply Last reply Reply Quote 0
        • P
          Paska Houso last edited by

          What about simply subclassing Ichimoku and having that plotlines definition?. As in

          class MyIchimoku(bt.indicators.Ichimoku):
              plotlines = dict(
                  senkou_span_a=dict(_fill_gt=('senkou_span_b', 'cyan'), _fill_lt=('senkou_span_b', 'magenta'), color='blue'),
                  senkou_span_b=dict(color='yellow'),
                  tenkan_sen=dict(_name='TenK', color='red'),
                  kijun_sen=dict(_name='KJ',color='green'),
                  chikou_span=dict(_name='chi', color='black')    
              )
          

          And then of course using your subclass instead of the internal indicator.

          1 Reply Last reply Reply Quote 1
          • F
            freedumb2000 last edited by

            Another, maybe clearer, option is:

            ichimoku = bt.indicators.Ichimoku()
            ichimoku.plotlines.senkou_span_b.color = "yellow"
            [...]
            
            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(); }); }