# trendln: support and resistance trend lines for any time series

> trendln is a Python library that finds local extrema in a price series, fits average lines through them and then searches for the best individual trend lines, with several interchangeable methods for detecting the extrema. It ships as version 0.1.18, a single release from 2026-04-09, and its documentation lives in the README and one long article.

**GregoryMorse/trendln** — Support and Resistance Trend lines Calculator for Financial Analysis

- Repository: https://github.com/GregoryMorse/trendln
- Stars: 732 · Forks: 162
- Language: Python
- License: MIT
- Published: 2026-10-21 · Updated: 2026-10-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/gregorymorse-trendln

## Extrema, an average line through them, and then trend lines

trendln is a support and resistance trend line calculator for financial analysis, and the README makes a point of widening that scope: the library can calculate and plot trend lines for any time series, not only for its primary intended purpose.

The core entry point is calc_support_resistance, which returns a two-tuple of results, one for minima and one for maxima. Each side carries four pieces of information. The first is the sorted list of indexes of the local minima or maxima. The second is the slope and intercept of the average best fit line through all of those points. The third is a sorted list of trend lines, each pairing the indexes of the points in the line with a result tuple, and the fourth is a list of windows, each holding the trend lines found in that window.

The result tuple itself is the part worth learning. For each trend line it carries the slope and intercept of the best fit, the sum of squares due to regression, the standard error of the slope and of the intercept, and areaAvg, described as the Riemann sum area of the difference between the best fit trend line and the actual data points averaged per time unit. That last figure is what lets you compare lines that cross at different levels, which is the reason to prefer a library over a spreadsheet.

A single call can also return just one side. Passing a two-tuple where one element is None, or the low and high series separately, means a two-tuple is not returned but only the relevant half.

## Seven ways to find an extremum, with different dependencies

How the extrema are found is a parameter, not a fixed behaviour, and the choice pulls in different dependencies. METHOD_NUMDIFF is the default and uses numerical differentiation, requiring the findiff package, with an accuracy setting where a 5-point stencil means accuracy=4. METHOD_NAIVE finds any local minima or maxima for a single interval and currently requires pandas, while METHOD_NAIVECONSEC extends that to include consecutive constant intervals and also requires pandas.

METHOD_NCUBED is described as a simple exhaustive 3 point search and the slowest of the set. METHOD_NSQUREDLOGN is the default for the trend line search itself and is a 2 point sorted slope search, described as fast. The remaining three are Hough based: METHOD_HOUGHPOINTS is a Hough line transform optimized for points, METHOD_HOUGHLINES is an image-based Hough line transform requiring scikit-image, and METHOD_PROBHOUGH is the image-based Probabilistic Hough transform, also requiring scikit-image, with its own iteration count parameter.

The practical consequence is that the method names are a proxy for your dependency set. A minimal installation can use the numerical differentiation path with findiff alone, while the Hough variants pull in scikit-image, which is the heaviest of the requirements listed in the repository. Choosing a method for algorithmic reasons and discovering later that it needs a package you did not install is the most common friction point in this library.

## Windows, merging and the slope error threshold

The trend line search works on windows before the results are merged together, and the window size is a parameter with a default of 125. This is the mechanism that lets the library find short lived supports and resistances inside a long series rather than only the global ones, and the returned structure keeps that provenance, because the windows list holds the trend lines found in each window.

Two error controls shape the output. errpct is the maximum percentage slope standard error, defaulting to 0.005, which rejects lines whose fit is too uncertain. The Hough methods add hough_scale, the smallest unit increment for discretization, described with cents and pennies as the example and defaulting to 0.01, and hough_prob_iter, the number of iterations for the probabilistic variant, defaulting to 10.

Ordering is controlled by sortError. When it is false the results are sorted by slope standard error, and when it is true they are sorted by area under the wrong side of the curve instead, which favours lines that sit above the data for resistance and below it for support. That switch changes which lines come back first, so it is a modelling decision rather than a formatting one, and it is worth running both on your data before you fix it in a pipeline.

Averaged over all of this, the returned average lines pmin and pmax are plain slope and intercept pairs, so they can be plotted or extrapolated with any linear code you already have.

## Installing the package and its four hard dependencies

trendln is on PyPI and the repository carries the usual packaging files, setup.py and setup.cfg, plus a MANIFEST.in, an example.py at the root and a tests directory. The dependency list in requirements.txt is short and pinned to minimum versions:

```python
numpy>=1.23.5
findiff>=0.10.0
scikit-image>=0.19.0
pandas>=1.4.0
matplotlib>=3.5.0
```

The setup.py file records the package name, the version 0.1.18, the author, the MIT licence and the project URLs, and it is where the release and upgrade commands are kept as comments. The upgrade command for a Windows Python install is kept there as a comment, and reads:

```bash
#"%ProgramFiles%\Python37\scripts\pip.exe" install trendln --upgrade
```

Two details in the packaging metadata are worth noting. The Development Status classifier is set to Production/Stable while the Alpha and Beta options sit commented out directly above it, and the operating system classifier is OS Independent. A version number of 0.1.18 with a stable status label is a common pattern for a solo maintained utility, and it tells you the version number carries the maturity information, not the classifier.

## Running the quick start, and plotting the best lines

The README quick start pulls prices from yfinance and hands the closing series to the library, with a comment noting the series stands in for security or index closing prices, or for low and high prices:

```python
	import yfinance as yf # requires yfinance - pip install yfinance
	tick = yf.Ticker('^GSPC') # S&P500
	hist = tick.history(period="max", rounding=True)
	h = hist[-1000:].Close
	mins, maxs = trendln.calc_support_resistance(h)
```

The optional data source, yfinance, is not in the requirements list, which is why the import carries an inline note about installing it separately.

Plotting is a separate call. plot_support_resistance calculates and plots the average and the top two support and resistance lines, marks the extrema used, applies a maximum history length and otherwise takes identical arguments to the calculation function. It needs matplotlib, and the README shows the figure being saved as an SVG before being displayed:

```python
	fig = trendln.plot_support_resistance(hist[-1000:].Close) # requires matplotlib - pip install matplotlib
	plt.savefig('suppres.svg', format='svg')
	plt.show()
	plt.clf() #clear figure
```

Two parameters control what appears on the chart. numbest sets how many best support and best resistance lines to display, defaulting to 2, and fromwindows decides whether those best lines are drawn from each window separately. An xformatter argument lets you replace the numeric x-axis indexes with a display formatter, which is how you get dates on the axis instead of integers.

If you only want the turning points and none of the fitting work, get_extrema returns the minima and maxima indexes alone using the same method and accuracy parameters.

## One release, a stable classifier and a doc set of two

The maintenance record is short and you should read it before depending on this. The repository publishes a single release, v0.1.18, and the last push was on 2026-04-09, the same day as that release. On that evidence the project is not actively developed, and the reasonable assumption is that it is maintained in bursts rather than on a schedule.

The documentation is similarly narrow. The README carries the API reference and points to CHANGELOG.md, and a link to a long article on programmatic identification of support and resistance trend lines with Python on Medium is given as the place to read how the library and its features are implemented. The repository itself holds a trendln package directory, the tests, an example script, a requirements-dev.txt, an img directory, and a meta.yaml file, which is the recipe format used for conda packages, so there is a path to installation outside pip as well.

The licence is MIT, which means commercial and modified use are both allowed with the notice retained, and the CI badge in the README points at a GitHub Actions workflow, so the test suite is expected to run on every push.

Given all that, the sensible use is as a well specified piece of analysis code you can read, fork and pin, rather than as a dependency that will absorb upstream fixes for you. The function signatures and the returned tuples are documented in enough detail to reimplement the parts you rely on, which is the strongest argument for a library with a single release: you are not locked in.

## Conclusion

Adopt trendln when you need a repeatable, parameterised way to extract support and resistance levels from a price series or any other time series, and you are willing to tune the window size, the slope error threshold and the extrema method rather than draw levels by hand. Do not adopt it if you need a maintained research library with a release history to pin to, since the only release is v0.1.18 from 2026-04-09 and the last push was on the same day, and do not read its output as a trading signal because it fits lines to extrema rather than modelling returns. Verify first which extrema method your data supports, since several of them need pandas, findiff or scikit-image to be installed, and check the returned slope error and area figures against a hand calculation on a short series before you automate anything with it.

## FAQ

### What does trendln calculate?

The calc_support_resistance function returns, for minima and maxima separately, the sorted indexes of the local extrema, the slope and intercept of the average best fit line through them, a list of individual trend lines with their statistics, and the windows the search was run over. Each trend line result carries slope, intercept, SSR, slope error, intercept error and an averaged area measure.

### Which packages does trendln need?

The requirements list numpy, findiff, scikit-image, pandas and matplotlib with minimum versions. Individual extrema methods need particular ones of those: the naive methods require pandas, the default numerical differentiation method requires findiff, and the Hough line transform methods require scikit-image.

### How do I plot support and resistance lines with trendln?

Use plot_support_resistance, which calculates and plots the average and the top two support and resistance lines and marks the extrema used. It takes the same arguments as the calculation function, and the README shows the figure being saved with plt.savefig and then displayed, with matplotlib required.

### Is trendln still maintained?

The repository publishes a single release, v0.1.18, and the last push was on 2026-04-09. The setup.py metadata carries a Production/Stable development status classifier, but the 0.1.x version number is the more useful signal about maturity.

## Sources

- [GregoryMorse/trendln on GitHub](https://github.com/GregoryMorse/trendln)
- [Issues](https://github.com/GregoryMorse/trendln/issues)
- [License: MIT](https://github.com/GregoryMorse/trendln/blob/master/LICENSE)
- [README](https://github.com/GregoryMorse/trendln/blob/master/README.md)
- [Releases](https://github.com/GregoryMorse/trendln/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/gregorymorse-trendln
