Skip to main content

Trend lines generator.

Project description

Trend lines generator

Usage example:

#! pip install trend-lines-generator
import requests
import mplfinance as mpf
from pandas import DataFrame, to_datetime

from trend_lines import generate_trend_lines, Side


def main():
    columns = [
        ("ts", "int"),
        ("volume_quote", "float64"),
        ("open", "float64"),
        ("high", "float64"),
        ("low", "float64"),
        ("close", "float64"),
    ]
    url = "https://api.gateio.ws/api/v4/spot/candlesticks?currency_pair=MOVR_USDT&interval=1h&limit=100"
    response = requests.get(url)

    rows = response.json()

    df = (
        DataFrame([r[: len(columns)] for r in rows], columns=[i[0] for i in columns])
        .astype(dict(columns))
        .set_index("ts")
    )
    df.index = to_datetime(df.index, unit="s")

    lines = generate_trend_lines(low_series=df["low"], high_series=df["high"])

    x1 = df.index[0]
    x2 = df.index[-1]

    mpf.plot(
        df,
        type="candle",
        tight_layout=True,
        alines={
            "alines": [((x1, line.get_y(x1)), (x2, line.get_y(x2))) for line in lines],
            "colors": ["g" if line.side == Side.LOW else "r" for line in lines],
        },
    )


if __name__ == "__main__":
    main()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trend_lines_generator-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

trend_lines_generator-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file trend_lines_generator-0.1.0.tar.gz.

File metadata

  • Download URL: trend_lines_generator-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/22.1.0

File hashes

Hashes for trend_lines_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 96bff8e2f30dd6f11ca7f477eab1606e37bf3e31971be6956e82987f7875d51b
MD5 2a28d5283b65001685270c33637839d1
BLAKE2b-256 0e9d83a473d4e89fbb55c009c69135ae2e466d41e2cbf12942abf5e326d9a2ec

See more details on using hashes here.

File details

Details for the file trend_lines_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for trend_lines_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6cc6772586f646b76fd2880dc4724d09fe25e1c1b406e84e04d649c98a223e0
MD5 e69466b23070283d573911dcccad49b6
BLAKE2b-256 30ed32d187a352d5d6929cb6bba47d5abf2a35120b9a7bddbc85dbd115ca1bb9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page