pynescript


Namepynescript JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryHandle Pinescript using Python
upload_time2024-02-27 23:24:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords pinescript python tradingview
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pynescript

[![PyPI](https://img.shields.io/pypi/v/pynescript.svg)][pypi_]
[![Status](https://img.shields.io/pypi/status/pynescript.svg)][status]
[![Python Version](https://img.shields.io/pypi/pyversions/pynescript)][python version]
[![License](https://img.shields.io/pypi/l/pynescript)][license]

[![Read the documentation at https://pynescript.readthedocs.io/](https://img.shields.io/readthedocs/pynescript/latest.svg?label=Read%20the%20Docs)][read the docs]
[![Tests](https://github.com/elbakramer/pynescript/workflows/Tests/badge.svg)][tests]
[![Codecov](https://codecov.io/gh/elbakramer/pynescript/branch/main/graph/badge.svg)][codecov]

[pypi_]: https://pypi.org/project/pynescript/
[status]: https://pypi.org/project/pynescript/
[python version]: https://pypi.org/project/pynescript
[read the docs]: https://pynescript.readthedocs.io/
[tests]: https://github.com/elbakramer/pynescript/actions?workflow=Tests
[codecov]: https://app.codecov.io/gh/elbakramer/pynescript

## Features

Handle [Pinescript] using [Python]

-   Parse Pinescript code into AST
-   Dump parsed AST
-   Unparse parsed AST back to Pinescript code

Given an example pinescript with name of `rsi_strategy.pine`:

```pinescript
//@version=5
strategy("RSI Strategy", overlay=true)
length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
vrsi = ta.rsi(price, length)
co = ta.crossover(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)
if (not na(vrsi))
	if (co)
		strategy.entry("RsiLE", strategy.long, comment="RsiLE")
	if (cu)
		strategy.entry("RsiSE", strategy.short, comment="RsiSE")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
```

Parsing script into AST and dumping it:

```console
$ pynescript parse-and-dump rsi_strategy.pine
```

Gives like:

```python
Script(
  body=[
    Expr(
      value=Call(
        func=Name(id='strategy', ctx=Load()),
        args=[
          Arg(
            value=Constant(value='RSI Strategy')),
          Arg(
            value=Constant(value=True),
            name='overlay')])),
    Assign(
      target=Name(id='length', ctx=Store()),
      value=Call(
        func=Name(id='input', ctx=Load()),
        args=[
          Arg(
            value=Constant(value=14))]),
      annotations=[]),
    ...
```

<details>
    <summary>Full AST dump that is quite long...</summary>

```python
Script(
  body=[
    Expr(
      value=Call(
        func=Name(id='strategy', ctx=Load()),
        args=[
          Arg(
            value=Constant(value='RSI Strategy')),
          Arg(
            value=Constant(value=True),
            name='overlay')])),
    Assign(
      target=Name(id='length', ctx=Store()),
      value=Call(
        func=Name(id='input', ctx=Load()),
        args=[
          Arg(
            value=Constant(value=14))]),
      annotations=[]),
    Assign(
      target=Name(id='overSold', ctx=Store()),
      value=Call(
        func=Name(id='input', ctx=Load()),
        args=[
          Arg(
            value=Constant(value=30))]),
      annotations=[]),
    Assign(
      target=Name(id='overBought', ctx=Store()),
      value=Call(
        func=Name(id='input', ctx=Load()),
        args=[
          Arg(
            value=Constant(value=70))]),
      annotations=[]),
    Assign(
      target=Name(id='price', ctx=Store()),
      value=Name(id='close', ctx=Load()),
      annotations=[]),
    Assign(
      target=Name(id='vrsi', ctx=Store()),
      value=Call(
        func=Attribute(
          value=Name(id='ta', ctx=Load()),
          attr='rsi',
          ctx=Load()),
        args=[
          Arg(
            value=Name(id='price', ctx=Load())),
          Arg(
            value=Name(id='length', ctx=Load()))]),
      annotations=[]),
    Assign(
      target=Name(id='co', ctx=Store()),
      value=Call(
        func=Attribute(
          value=Name(id='ta', ctx=Load()),
          attr='crossover',
          ctx=Load()),
        args=[
          Arg(
            value=Name(id='vrsi', ctx=Load())),
          Arg(
            value=Name(id='overSold', ctx=Load()))]),
      annotations=[]),
    Assign(
      target=Name(id='cu', ctx=Store()),
      value=Call(
        func=Attribute(
          value=Name(id='ta', ctx=Load()),
          attr='crossunder',
          ctx=Load()),
        args=[
          Arg(
            value=Name(id='vrsi', ctx=Load())),
          Arg(
            value=Name(id='overBought', ctx=Load()))]),
      annotations=[]),
    Expr(
      value=If(
        test=UnaryOp(
          op=Not(),
          operand=Call(
            func=Name(id='na', ctx=Load()),
            args=[
              Arg(
                value=Name(id='vrsi', ctx=Load()))])),
        body=[
          Expr(
            value=If(
              test=Name(id='co', ctx=Load()),
              body=[
                Expr(
                  value=Call(
                    func=Attribute(
                      value=Name(id='strategy', ctx=Load()),
                      attr='entry',
                      ctx=Load()),
                    args=[
                      Arg(
                        value=Constant(value='RsiLE')),
                      Arg(
                        value=Attribute(
                          value=Name(id='strategy', ctx=Load()),
                          attr='long',
                          ctx=Load())),
                      Arg(
                        value=Constant(value='RsiLE'),
                        name='comment')]))],
              orelse=[])),
          Expr(
            value=If(
              test=Name(id='cu', ctx=Load()),
              body=[
                Expr(
                  value=Call(
                    func=Attribute(
                      value=Name(id='strategy', ctx=Load()),
                      attr='entry',
                      ctx=Load()),
                    args=[
                      Arg(
                        value=Constant(value='RsiSE')),
                      Arg(
                        value=Attribute(
                          value=Name(id='strategy', ctx=Load()),
                          attr='short',
                          ctx=Load())),
                      Arg(
                        value=Constant(value='RsiSE'),
                        name='comment')]))],
              orelse=[]))],
        orelse=[]))],
  annotations=[
    '//@version=5'])
```

</details>

Parsing into AST and unparsing it back:

```console
$ pynescript parse-and-unparse rsi_strategy.pine
```

Gives (with some difference in syntax including spacing):

```pinescript
//@version=5
strategy("RSI Strategy", overlay=true)
length = input(14)
overSold = input(30)
overBought = input(70)
price = close
vrsi = ta.rsi(price, length)
co = ta.crossover(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)
if not na(vrsi)
    if co
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
    if cu
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
```

## Requirements

-   Python 3.10 or higher

## Installation

You can install _Pynescript_ via [pip] from [PyPI]:

```console
$ pip install pynescript
```

## Usage

Please see the [Usage][usage] for details.

## License

Distributed under the terms of the [LGPL 3.0 license][license],
_Pynescript_ is free and open source software.

## Issues

If you encounter any problems,
please [file an issue] along with a detailed description.

[pinescript]: https://www.tradingview.com/pine-script-docs/en/v5/Introduction.html
[python]: https://www.python.org/

[pip]: https://pip.pypa.io/
[pypi]: https://pypi.org/

[file an issue]: https://github.com/elbakramer/pynescript/issues

<!-- github-only -->

[license]: https://github.com/elbakramer/pynescript/blob/main/LICENSE
[usage]: https://pynescript.readthedocs.io/en/latest/usage.html
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pynescript",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Yunseong Hwang <kika1492@gmail.com>",
    "keywords": "pinescript,python,tradingview",
    "author": null,
    "author_email": "Yunseong Hwang <kika1492@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f2/44/6fcb1ff55aa727f7d2f0107786c4533900a3f6bcb3fc4bd88b78f5bb5eb2/pynescript-0.2.0.tar.gz",
    "platform": null,
    "description": "# Pynescript\n\n[![PyPI](https://img.shields.io/pypi/v/pynescript.svg)][pypi_]\n[![Status](https://img.shields.io/pypi/status/pynescript.svg)][status]\n[![Python Version](https://img.shields.io/pypi/pyversions/pynescript)][python version]\n[![License](https://img.shields.io/pypi/l/pynescript)][license]\n\n[![Read the documentation at https://pynescript.readthedocs.io/](https://img.shields.io/readthedocs/pynescript/latest.svg?label=Read%20the%20Docs)][read the docs]\n[![Tests](https://github.com/elbakramer/pynescript/workflows/Tests/badge.svg)][tests]\n[![Codecov](https://codecov.io/gh/elbakramer/pynescript/branch/main/graph/badge.svg)][codecov]\n\n[pypi_]: https://pypi.org/project/pynescript/\n[status]: https://pypi.org/project/pynescript/\n[python version]: https://pypi.org/project/pynescript\n[read the docs]: https://pynescript.readthedocs.io/\n[tests]: https://github.com/elbakramer/pynescript/actions?workflow=Tests\n[codecov]: https://app.codecov.io/gh/elbakramer/pynescript\n\n## Features\n\nHandle [Pinescript] using [Python]\n\n-   Parse Pinescript code into AST\n-   Dump parsed AST\n-   Unparse parsed AST back to Pinescript code\n\nGiven an example pinescript with name of `rsi_strategy.pine`:\n\n```pinescript\n//@version=5\nstrategy(\"RSI Strategy\", overlay=true)\nlength = input( 14 )\noverSold = input( 30 )\noverBought = input( 70 )\nprice = close\nvrsi = ta.rsi(price, length)\nco = ta.crossover(vrsi, overSold)\ncu = ta.crossunder(vrsi, overBought)\nif (not na(vrsi))\n\tif (co)\n\t\tstrategy.entry(\"RsiLE\", strategy.long, comment=\"RsiLE\")\n\tif (cu)\n\t\tstrategy.entry(\"RsiSE\", strategy.short, comment=\"RsiSE\")\n//plot(strategy.equity, title=\"equity\", color=color.red, linewidth=2, style=plot.style_areabr)\n```\n\nParsing script into AST and dumping it:\n\n```console\n$ pynescript parse-and-dump rsi_strategy.pine\n```\n\nGives like:\n\n```python\nScript(\n  body=[\n    Expr(\n      value=Call(\n        func=Name(id='strategy', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value='RSI Strategy')),\n          Arg(\n            value=Constant(value=True),\n            name='overlay')])),\n    Assign(\n      target=Name(id='length', ctx=Store()),\n      value=Call(\n        func=Name(id='input', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value=14))]),\n      annotations=[]),\n    ...\n```\n\n<details>\n    <summary>Full AST dump that is quite long...</summary>\n\n```python\nScript(\n  body=[\n    Expr(\n      value=Call(\n        func=Name(id='strategy', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value='RSI Strategy')),\n          Arg(\n            value=Constant(value=True),\n            name='overlay')])),\n    Assign(\n      target=Name(id='length', ctx=Store()),\n      value=Call(\n        func=Name(id='input', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value=14))]),\n      annotations=[]),\n    Assign(\n      target=Name(id='overSold', ctx=Store()),\n      value=Call(\n        func=Name(id='input', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value=30))]),\n      annotations=[]),\n    Assign(\n      target=Name(id='overBought', ctx=Store()),\n      value=Call(\n        func=Name(id='input', ctx=Load()),\n        args=[\n          Arg(\n            value=Constant(value=70))]),\n      annotations=[]),\n    Assign(\n      target=Name(id='price', ctx=Store()),\n      value=Name(id='close', ctx=Load()),\n      annotations=[]),\n    Assign(\n      target=Name(id='vrsi', ctx=Store()),\n      value=Call(\n        func=Attribute(\n          value=Name(id='ta', ctx=Load()),\n          attr='rsi',\n          ctx=Load()),\n        args=[\n          Arg(\n            value=Name(id='price', ctx=Load())),\n          Arg(\n            value=Name(id='length', ctx=Load()))]),\n      annotations=[]),\n    Assign(\n      target=Name(id='co', ctx=Store()),\n      value=Call(\n        func=Attribute(\n          value=Name(id='ta', ctx=Load()),\n          attr='crossover',\n          ctx=Load()),\n        args=[\n          Arg(\n            value=Name(id='vrsi', ctx=Load())),\n          Arg(\n            value=Name(id='overSold', ctx=Load()))]),\n      annotations=[]),\n    Assign(\n      target=Name(id='cu', ctx=Store()),\n      value=Call(\n        func=Attribute(\n          value=Name(id='ta', ctx=Load()),\n          attr='crossunder',\n          ctx=Load()),\n        args=[\n          Arg(\n            value=Name(id='vrsi', ctx=Load())),\n          Arg(\n            value=Name(id='overBought', ctx=Load()))]),\n      annotations=[]),\n    Expr(\n      value=If(\n        test=UnaryOp(\n          op=Not(),\n          operand=Call(\n            func=Name(id='na', ctx=Load()),\n            args=[\n              Arg(\n                value=Name(id='vrsi', ctx=Load()))])),\n        body=[\n          Expr(\n            value=If(\n              test=Name(id='co', ctx=Load()),\n              body=[\n                Expr(\n                  value=Call(\n                    func=Attribute(\n                      value=Name(id='strategy', ctx=Load()),\n                      attr='entry',\n                      ctx=Load()),\n                    args=[\n                      Arg(\n                        value=Constant(value='RsiLE')),\n                      Arg(\n                        value=Attribute(\n                          value=Name(id='strategy', ctx=Load()),\n                          attr='long',\n                          ctx=Load())),\n                      Arg(\n                        value=Constant(value='RsiLE'),\n                        name='comment')]))],\n              orelse=[])),\n          Expr(\n            value=If(\n              test=Name(id='cu', ctx=Load()),\n              body=[\n                Expr(\n                  value=Call(\n                    func=Attribute(\n                      value=Name(id='strategy', ctx=Load()),\n                      attr='entry',\n                      ctx=Load()),\n                    args=[\n                      Arg(\n                        value=Constant(value='RsiSE')),\n                      Arg(\n                        value=Attribute(\n                          value=Name(id='strategy', ctx=Load()),\n                          attr='short',\n                          ctx=Load())),\n                      Arg(\n                        value=Constant(value='RsiSE'),\n                        name='comment')]))],\n              orelse=[]))],\n        orelse=[]))],\n  annotations=[\n    '//@version=5'])\n```\n\n</details>\n\nParsing into AST and unparsing it back:\n\n```console\n$ pynescript parse-and-unparse rsi_strategy.pine\n```\n\nGives (with some difference in syntax including spacing):\n\n```pinescript\n//@version=5\nstrategy(\"RSI Strategy\", overlay=true)\nlength = input(14)\noverSold = input(30)\noverBought = input(70)\nprice = close\nvrsi = ta.rsi(price, length)\nco = ta.crossover(vrsi, overSold)\ncu = ta.crossunder(vrsi, overBought)\nif not na(vrsi)\n    if co\n        strategy.entry(\"RsiLE\", strategy.long, comment=\"RsiLE\")\n    if cu\n        strategy.entry(\"RsiSE\", strategy.short, comment=\"RsiSE\")\n```\n\n## Requirements\n\n-   Python 3.10 or higher\n\n## Installation\n\nYou can install _Pynescript_ via [pip] from [PyPI]:\n\n```console\n$ pip install pynescript\n```\n\n## Usage\n\nPlease see the [Usage][usage] for details.\n\n## License\n\nDistributed under the terms of the [LGPL 3.0 license][license],\n_Pynescript_ is free and open source software.\n\n## Issues\n\nIf you encounter any problems,\nplease [file an issue] along with a detailed description.\n\n[pinescript]: https://www.tradingview.com/pine-script-docs/en/v5/Introduction.html\n[python]: https://www.python.org/\n\n[pip]: https://pip.pypa.io/\n[pypi]: https://pypi.org/\n\n[file an issue]: https://github.com/elbakramer/pynescript/issues\n\n<!-- github-only -->\n\n[license]: https://github.com/elbakramer/pynescript/blob/main/LICENSE\n[usage]: https://pynescript.readthedocs.io/en/latest/usage.html",
    "bugtrack_url": null,
    "license": null,
    "summary": "Handle Pinescript using Python",
    "version": "0.2.0",
    "project_urls": {
        "Documentation": "https://github.com/elbakramer/pynescript#readme",
        "Issues": "https://github.com/elbakramer/pynescript/issues",
        "Source": "https://github.com/elbakramer/pynescript"
    },
    "split_keywords": [
        "pinescript",
        "python",
        "tradingview"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2be4d51cc188ade6b2d340f1f14b900a079986a63533121fa0c67fcb0f35c415",
                "md5": "53b57d9138cce59eed353cecd8128443",
                "sha256": "053cfb1a920a8a814597feaae9cf854c9219c512f05960a6f050785013084b26"
            },
            "downloads": -1,
            "filename": "pynescript-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "53b57d9138cce59eed353cecd8128443",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 116957,
            "upload_time": "2024-02-27T23:24:44",
            "upload_time_iso_8601": "2024-02-27T23:24:44.864661Z",
            "url": "https://files.pythonhosted.org/packages/2b/e4/d51cc188ade6b2d340f1f14b900a079986a63533121fa0c67fcb0f35c415/pynescript-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f2446fcb1ff55aa727f7d2f0107786c4533900a3f6bcb3fc4bd88b78f5bb5eb2",
                "md5": "ad1f4929c503cec1c58ffa80c40a32d9",
                "sha256": "c10bb91e223a61ee4f126f894767977e98d0f757a445bb50793d13cf1f211ea4"
            },
            "downloads": -1,
            "filename": "pynescript-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad1f4929c503cec1c58ffa80c40a32d9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 225576,
            "upload_time": "2024-02-27T23:24:47",
            "upload_time_iso_8601": "2024-02-27T23:24:47.091420Z",
            "url": "https://files.pythonhosted.org/packages/f2/44/6fcb1ff55aa727f7d2f0107786c4533900a3f6bcb3fc4bd88b78f5bb5eb2/pynescript-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-27 23:24:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "elbakramer",
    "github_project": "pynescript#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pynescript"
}
        
Elapsed time: 0.19491s