A mechanical approach to determine the trend of a stock along with breakout and reversal levels.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swingtrend-2.0.2.post1.tar.gz.
File metadata
- Download URL: swingtrend-2.0.2.post1.tar.gz
- Upload date:
- Size: 257.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85726ab136e2d1a824b7629fba778383276e7dfe9de61450c3f7f8bfd097ecf7
|
|
| MD5 |
494281fc8c7149d9f5dcc49a2228622e
|
|
| BLAKE2b-256 |
8119f62544435eccac2b05961598449b390a2517655fdbd2f31d774027411ae5
|
Provenance
The following attestation bundles were made for swingtrend-2.0.2.post1.tar.gz:
Publisher:
publish-to-pypi.yml on BennyThadikaran/SwingTrend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
swingtrend-2.0.2.post1.tar.gz -
Subject digest:
85726ab136e2d1a824b7629fba778383276e7dfe9de61450c3f7f8bfd097ecf7 - Sigstore transparency entry: 847416237
- Sigstore integration time:
-
Permalink:
BennyThadikaran/SwingTrend@5bfa1441bc588d693b2373d5455f2ef09b4cd2d8 -
Branch / Tag:
refs/tags/v2.0.2-1 - Owner: https://github.com/BennyThadikaran
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5bfa1441bc588d693b2373d5455f2ef09b4cd2d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file swingtrend-2.0.2.post1-py3-none-any.whl.
File metadata
- Download URL: swingtrend-2.0.2.post1-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3db934dfd6d776612fd87880b37aa5153f3255e8f542dca9e18515bb590e687a
|
|
| MD5 |
1bfb0f8e8ce02bcaad3f83cda6c50fe0
|
|
| BLAKE2b-256 |
7777794e919581915863406c1d309b8c4ceb38bb31901839909400df84bb0743
|
Provenance
The following attestation bundles were made for swingtrend-2.0.2.post1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on BennyThadikaran/SwingTrend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
swingtrend-2.0.2.post1-py3-none-any.whl -
Subject digest:
3db934dfd6d776612fd87880b37aa5153f3255e8f542dca9e18515bb590e687a - Sigstore transparency entry: 847416283
- Sigstore integration time:
-
Permalink:
BennyThadikaran/SwingTrend@5bfa1441bc588d693b2373d5455f2ef09b4cd2d8 -
Branch / Tag:
refs/tags/v2.0.2-1 - Owner: https://github.com/BennyThadikaran
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5bfa1441bc588d693b2373d5455f2ef09b4cd2d8 -
Trigger Event:
push
-
Statement type: