# Trend lines generator
Usage example:
```python
#! 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()
```
![trend lines](https://github.com/nanvel/trend-lines/raw/master/docs/trend_lines.png)
For each time in the serie:
![trend lines daily](https://github.com/nanvel/trend-lines/raw/master/docs/trend_lines_daily.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/nanvel/trend-lines-generator",
"name": "trend-lines-generator",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "trendlines,trend lines,trend,ta,resistance,support,technical,indicators,financial",
"author": "Oleksandr Polieno",
"author_email": "polyenoom@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d0/aa/715a63fb14bbe3755a6b03750768ddf0aab046a203faf4e5bbed8bc419b1/trend_lines_generator-1.0.1.tar.gz",
"platform": null,
"description": "# Trend lines generator\n\nUsage example:\n```python\n#! pip install trend-lines-generator\nimport requests\nimport mplfinance as mpf\nfrom pandas import DataFrame, to_datetime\n\nfrom trend_lines import generate_trend_lines, Side\n\n\ndef main():\n columns = [\n (\"ts\", \"int\"),\n (\"volume_quote\", \"float64\"),\n (\"open\", \"float64\"),\n (\"high\", \"float64\"),\n (\"low\", \"float64\"),\n (\"close\", \"float64\"),\n ]\n url = \"https://api.gateio.ws/api/v4/spot/candlesticks?currency_pair=MOVR_USDT&interval=1h&limit=100\"\n response = requests.get(url)\n\n rows = response.json()\n\n df = (\n DataFrame([r[: len(columns)] for r in rows], columns=[i[0] for i in columns])\n .astype(dict(columns))\n .set_index(\"ts\")\n )\n df.index = to_datetime(df.index, unit=\"s\")\n\n lines = generate_trend_lines(low_series=df[\"low\"], high_series=df[\"high\"])\n\n x1 = df.index[0]\n x2 = df.index[-1]\n\n mpf.plot(\n df,\n type=\"candle\",\n tight_layout=True,\n alines={\n \"alines\": [((x1, line.get_y(x1)), (x2, line.get_y(x2))) for line in lines],\n \"colors\": [\"g\" if line.side == Side.LOW else \"r\" for line in lines],\n },\n )\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n![trend lines](https://github.com/nanvel/trend-lines/raw/master/docs/trend_lines.png)\n\nFor each time in the serie:\n\n![trend lines daily](https://github.com/nanvel/trend-lines/raw/master/docs/trend_lines_daily.png)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Trend lines generator.",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/nanvel/trend-lines-generator",
"Repository": "https://github.com/nanvel/trend-lines-generator"
},
"split_keywords": [
"trendlines",
"trend lines",
"trend",
"ta",
"resistance",
"support",
"technical",
"indicators",
"financial"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c158ffc6bf9bf9c85bdac414ed3e4a4b549a92d1383b231ce9c0dda1b88972ad",
"md5": "db283c43a93192dcd7358dfe8c626759",
"sha256": "d108a0a30b1a154528ab7dd71cb9b873458d63a8833370e78c441ea44bca5ad0"
},
"downloads": -1,
"filename": "trend_lines_generator-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "db283c43a93192dcd7358dfe8c626759",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 8561,
"upload_time": "2024-02-25T05:22:24",
"upload_time_iso_8601": "2024-02-25T05:22:24.608962Z",
"url": "https://files.pythonhosted.org/packages/c1/58/ffc6bf9bf9c85bdac414ed3e4a4b549a92d1383b231ce9c0dda1b88972ad/trend_lines_generator-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d0aa715a63fb14bbe3755a6b03750768ddf0aab046a203faf4e5bbed8bc419b1",
"md5": "e72b9e9b3b7fecd855d51fd7983711b6",
"sha256": "332a7b9df2ffdbab1dc1057657e1400201896aa316f2653ec6184431508ce7e6"
},
"downloads": -1,
"filename": "trend_lines_generator-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "e72b9e9b3b7fecd855d51fd7983711b6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 6817,
"upload_time": "2024-02-25T05:22:26",
"upload_time_iso_8601": "2024-02-25T05:22:26.565732Z",
"url": "https://files.pythonhosted.org/packages/d0/aa/715a63fb14bbe3755a6b03750768ddf0aab046a203faf4e5bbed8bc419b1/trend_lines_generator-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-25 05:22:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nanvel",
"github_project": "trend-lines-generator",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "trend-lines-generator"
}