Skip to main content

SwingTrend

SwingTrend provides a mechanical approach to determine the stock trend, with breakout and reversal levels.

Python version: >= 3.8

  • Can track trends on historical as well as real-time OHLC data.
  • Use it as a trend indicator or screener.
  • Lightweight and serializable. The Class state can be saved/restored. Useful for day-to-day tracking of trends.
  • Timeframe agnostic - pass data from any timeframe to establish the current trend.
  • Linux, Windows, and Mac. No external dependencies. 90% test coverage of core functionality.

If you ❤️ my work so far, please 🌟 this repo.

👽 Documentation

https://bennythadikaran.github.io/SwingTrend

Installation

pip install swingtrend

Basic Usage (As of v2.0.1`)

from swingtrend import Swing`

# Initialise with default values
swing = Swing(
    retrace_threshold_pct=5,
    sideways_threshold=20,
    minimum_bar_count=40,
    debug=False,
)

swing = swing.run(sym="HDFCBANK", df.iloc[-60:])

swing.trend # UP or DOWN or None

swing.is_sideways # True or False.

swing.bars_since # Count of candles since last swing high or low.

swing.is_trend_stable # Is trend accurate, given the number candles supplied?

swing.leg_count # Number of swing legs, the trend has completed.

swing.sph # if trend is UP and SPH is confirmed else None

swing.spl # if trend in DOWN and SPL is confirmed else None

swing.coc # Reversal price for the current trend.

swing.high # the current highest high within a swing.

swing.low # the current lowest low within a swing.

swing.df # A reference to the dataframe passed to Swing.run()

swing.symbol # Symbol name passed to Swing.run()

# Below represent datetime of the respective candles.
swing.sph_dt
swing.spl_dt
swing.coc_dt
swing.high_dt
swing.low_dt

See the documentation for more details.

Inspiration

This work was inspired by youtube channel Matt Donlevey - Photon Trading.

You can watch their video How To Understand Market Structure to understand some of the concepts.

How the class works

See simple explanation of how the program works

To use the Photon method as explained in the video, instantiate the class as Swing(retrace_threshold_pct=None)

With the Photon method, both major or minor pivots can result in trend continuation or reversal. (including a single bar pullback).

I prefer avoiding the minor pivots by setting a minimum threshold percent. With an 8% threshold, the pullback must retrace atleast 8% or more to be considered a level for trend reversal or continuation.

Metadata

Release files for swingtrend 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swingtrend 2.0.4
File Size Uploaded Provenance Actions
swingtrend-2.0.4.tar.gz 258.0 kB With provenance Details for swingtrend-2.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swingtrend 2.0.4
File Interpreter ABI Platform Actions
swingtrend-2.0.4-py3-none-any.whl Python 3 none any Details for swingtrend-2.0.4-py3-none-any.whl

Total release size: 277.5 kB

Release files / swingtrend-2.0.4.tar.gz

Download URL swingtrend-2.0.4.tar.gz
Size 258.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c4e5f742adf83e41ceb0f25302a188bbdf11712b4de4906b65b9e2824435d747
BLAKE2b-256 checksum
How to use checksums
b7c342801d86c50e398cc484f560291188c3545eb40d6859c14c517218096db1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

Release files / swingtrend-2.0.4-py3-none-any.whl

Download URL swingtrend-2.0.4-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
462563740e0e52bff966ea1a749f881ed9eb8be40434e5a5f9bc5957bc6f5913
BLAKE2b-256 checksum
How to use checksums
01adfc7b4a2401253a43f68591800adaf84ff9c61e456d1c6e853fe9c4e0c2d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

Security for swingtrend 2.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for swingtrend-2.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page