backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Bar graphs and oscillator support

Open namliz opened this issue 5 years ago • 4 comments

First of all, thank you for this project it is very well done.

This is a feature request to add support for bar graphs in addition to the current line and scatter plots.

Oscillators might also benefit from an alternative style with an area colouring like so: mom

And having two lines together in one graph: image

namliz avatar Mar 22 '20 17:03 namliz

And having two lines together in one graph

Indicator function can return multiple (i.e. a tuple of) arrays. This works.

self.I(lambda: (ta.SMA(close, self.slow), 
                ta.SMA(close, self.fast))

Area chart is meh, because that also needs a defined center/min. Bar chart would be near trivial to implement, but I don't see much informative difference in bars vs. a line. This is not TradingView. :stuck_out_tongue_winking_eye:

kernc avatar Mar 22 '20 22:03 kernc

The lambda trick is cool, how would you pass something like a different color/name to each one?

My argument in favour of something like bars (or more visual styles in general) is that it would be visually distinct, I realise it's not TrardingView heh. The only other way on a busy chart is to have a lot of color variations and that has its own downsides.

namliz avatar Mar 22 '20 22:03 namliz

how would you pass something like a different color/name to each one?

Something like this should work:

self.I(..., color=('pink', 'lime'))

but that was apparently lost in https://github.com/kernc/backtesting.py/commit/bae9340aaef4d5f407bec18daae22f74a98d4f13 (restored in https://github.com/kernc/backtesting.py/commit/c37e7a98546d58ead428b740eba789fa1c77e2f8, master). Default colors should be distinct, cycled from the colorgen.

kernc avatar Mar 23 '20 22:03 kernc

That was the first thing I tried, thanks for patching. It's actually color singular not colors plural, works now. Can't specify distinct names however.


backtesting.py in I(self, func, name, plot, overlay, color, scatter, *args, **kwargs)
    119             name = ('{}({})' if params else '{}').format(func_name, params)
    120         else:
--> 121             name = name.format(*map(_as_str, args),
    122                                **dict(zip(kwargs.keys(), map(_as_str, kwargs.values()))))
    123 

AttributeError: 'tuple' object has no attribute 'format'

namliz avatar Mar 23 '20 23:03 namliz