Talib Functions Examples¶
Examples use pandas data, but most functions should be compatible with a polars dataframe as well.
In [1]:
Copied!
from mplchart.chart import Chart
from mplchart.samples import sample_prices
from mplchart.primitives import Candlesticks, OHLC, Volume, LinePlot
from talib.abstract import Function
from mplchart.chart import Chart
from mplchart.samples import sample_prices
from mplchart.primitives import Candlesticks, OHLC, Volume, LinePlot
from talib.abstract import Function
In [2]:
Copied!
prices = sample_prices(backend="polars")
prices
prices = sample_prices(backend="polars")
prices
Out[2]:
shape: (11_325, 6)
| date | open | high | low | close | volume |
|---|---|---|---|---|---|
| date | f64 | f64 | f64 | f64 | i64 |
| 1980-12-12 | 0.098389 | 0.098817 | 0.098389 | 0.098389 | 469033600 |
| 1980-12-15 | 0.093684 | 0.093684 | 0.093256 | 0.093256 | 175884800 |
| 1980-12-16 | 0.086839 | 0.086839 | 0.086412 | 0.086412 | 105728000 |
| 1980-12-17 | 0.08855 | 0.088978 | 0.08855 | 0.08855 | 86441600 |
| 1980-12-18 | 0.091118 | 0.091545 | 0.091118 | 0.091118 | 73449600 |
| … | … | … | … | … | … |
| 2025-11-11 | 269.809998 | 275.910004 | 269.799988 | 275.25 | 46208300 |
| 2025-11-12 | 275.0 | 275.730011 | 271.700012 | 273.470001 | 48398000 |
| 2025-11-13 | 274.109985 | 276.700012 | 272.089996 | 272.950012 | 49602800 |
| 2025-11-14 | 271.049988 | 275.959991 | 269.600006 | 272.410004 | 47399300 |
| 2025-11-17 | 268.815002 | 270.48999 | 265.730011 | 267.459991 | 42862157 |
In [3]:
Copied!
# Candlesticks chart with SMA, RSI and MACD
title = "Talib Example"
Chart(prices, title=title, max_bars=250).plot(
Candlesticks(),
Function("SMA", 50),
Function("SMA", 200),
).pane("above").plot(
Function("RSI"),
).pane("below").plot(
Function("MACD"),
).show()
# Candlesticks chart with SMA, RSI and MACD
title = "Talib Example"
Chart(prices, title=title, max_bars=250).plot(
Candlesticks(),
Function("SMA", 50),
Function("SMA", 200),
).pane("above").plot(
Function("RSI"),
).pane("below").plot(
Function("MACD"),
).show()
In [4]:
Copied!
# Bollinger Bands
title = "Bollinger Bands"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
Function("BBANDS", 20),
).show()
# Bollinger Bands
title = "Bollinger Bands"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
Function("BBANDS", 20),
).show()
In [5]:
Copied!
# Stochastic Oscillator
title = "Stochastic Oscillator"
indicators = [
Candlesticks(),
Function("STOCH"),
]
Chart(prices, title=title, max_bars=250).plot(
Candlesticks(),
Function("STOCH"),
).show()
# Stochastic Oscillator
title = "Stochastic Oscillator"
indicators = [
Candlesticks(),
Function("STOCH"),
]
Chart(prices, title=title, max_bars=250).plot(
Candlesticks(),
Function("STOCH"),
).show()
In [6]:
Copied!
# Parabolic Stop and Reverse
title = "Parabolic Stop and Reverse"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
LinePlot(Function("SAR"), style="marker"),
).show()
# Parabolic Stop and Reverse
title = "Parabolic Stop and Reverse"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
LinePlot(Function("SAR"), style="marker"),
).show()
In [7]:
Copied!
# Hilbert Transform
title = "Hilbert Transform"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
).pane("below").plot(
Function("HT_SINE")
).pane("below").plot(
Function("HT_DCPHASE")
).pane("below").plot(
Function("HT_DCPERIOD")
)
# Hilbert Transform
title = "Hilbert Transform"
Chart(prices, title=title, max_bars=150).plot(
Candlesticks(),
).pane("below").plot(
Function("HT_SINE")
).pane("below").plot(
Function("HT_DCPHASE")
).pane("below").plot(
Function("HT_DCPERIOD")
)
Out[7]:
<mplchart.chart.Chart at 0xffff5400a850>
In [ ]:
Copied!