furechan / mplchart

Classic Stock Charts in Python
MIT License
24 stars 6 forks source link

TA functions with additional lines #4

Closed vinaychuri closed 4 months ago

vinaychuri commented 9 months ago

I am using the example code and get the required plots.

from mplchart.chart import Chart
from mplchart.primitives import Candlesticks, Volume, TradeMarker, TradeSpan
from talib.abstract import Function
from mplchart.indicators import ROC, SMA, EMA, RSI, MACD,BBANDS
indicators = [
    Candlesticks(),BBANDS(),Volume(), #SMA(50), SMA(200), Volume(),
    RSI(),
    MACD(),
    Function('ADX'),
    # TradeMarker("macdhist>0"),
]
chart = Chart(title="ticker", max_bars=200)
chart.plot(df, indicators)

But TA.ADX function returns 3 columns namely ADX,DMP,DMN and all 3 are normally plotted together to understand trends. I see that my above plot displays only the line chart for ADX, How do i get the DMP,DMN line plot added to the same panel?

Secondly, ADX >25 is usually the tracking point for strong trends so how does one add one(or multiple) horizontal line at 25 or 30 or 50 in the ADX panel. The same request in the RSI panel where one needs horizontal line at 30 or 50

Thanks

vinaychuri commented 9 months ago

Update: I mixed up the functions within pandas_ta and talib pandas_ta.adx returns 3 columns of ADX,DMP,DMN while the talib.adx returns only the ADX so the plots are correct.

So one has to use the "custom-indicator.ipynb" example to be able to plot ADX,DMP,DMN at same time?

Also the issue of adding horizontal lines still remains.

furechan commented 9 months ago

Hi vinaychuri,

Yes, abstract.Function("ADX") returns a single series.

In anycase, I added an ADX indicator in the latest version with the three ADX lines and a grid line at 20. Also the RSI now displays the gridlines at 30, 70 more visibly. I will look to see if there is an easy way to specify custom grid lines ...

vinaychuri commented 9 months ago

image image

Firstly , THANK YOU for the quick response and the updates. ADX is now part of the package itself and works great!

Few observations:

  1. The ADX plot now shows the ADX,DMN,DMP lines but the Y axis shows values only for the grid line@20. The other Y axis values for ADX is missing. Not sure if its required or not or may be its a personal preference.
  2. The ADX plot also shows a dotted line , not sure what value is being plotted here.
  3. RSI plot shows grid line for 30,70 but it also shows a dotted line , not sure what value is being plotted here

The screens are enclosed for reference

furechan commented 9 months ago

Hi vinaychuri,

I see, thanks! Newest version (0.0.7) should now display labels for minor ticks as well, for both RSI and ADX.