mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

Adding an oscillator to a Renko chart

Open Maurice-D-Elbee opened this issue 1 year ago • 1 comments

Hello Daniel,

Thanks again for your fabulous library. I'm scratching my head on how to add a subpanel for a renko chart. I'm trying to add an indicator in the lower panel (an oscillator). Getting into some non-iterrable item error using the external_axes trick. Some help would be much appreciated.

I'm looking for this end result:

Screenshot 2022-08-08 at 11 16 41 PM

PS: How to control the border width on the boxes please :)

Maurice-D-Elbee avatar Aug 08 '22 15:08 Maurice-D-Elbee

Regarding adding a lower panel (for an oscillator or anything else) to a Renko chart, as you may have noticed, mplfinance does not support mpf.make_addplot() with Renko or Point and Figure. This is because both of these chart types (and all such "price movement" chart types) create a very non-linear (and non-regular) time axis.

This complicates very much trying to plot anything else on the same x-axis. Therefore, rather than add a large of amount of complex code (and assumptions) to the addplot portion of mplfinance code, we chose not to support addplot for Renko or other "price movement" types of charts.

That said, regarding

Getting into some non-iterrable item error using the external_axes trick

I would have to see your exact code, and the full error and traceback, to be able to comment. (I would think this could work.)

I would also suggest thinking seriously about how one might interpret an oscillator (for example MACD) that is usually plotted on a linear time axis, for the case of plotting such an oscillator on a time-axes where some portions of the axis are far more compressed than other portions of the axis (as is the case for charts based on the movement of prices, instead of based on the movement of time).


Finally, regarding

PS: How to control the border width on the boxes please`

This is not presently supported, however it would be a relatively easy enhancement to either (1) allow mplfinance widths configuration to affect renko bar line widths, or (2) allow a line width paramenter to be passed in among the "renko paramters."

If you are interested in making this relatively easy enhancement, I would be happy to guide you through the process.

Alternatively, as a workaround, you can create your own custom style by copying an existing style and simply adding rc={'patch.linewidth':<value>} in your call to mpf.make_mpf_style() ... for example:

s = mpf.make_mpf_style( base_mpf_style='yahoo',rc={'patch.linewidth':2.0} )
mpf.plot( df, style=s )

the above theoretically should modify the line widths of the renko bricks (although I have not tried it yet myself).

DanielGoldfarb avatar Aug 09 '22 14:08 DanielGoldfarb