Quick Start
Parse, dump, unparse, lint, and evaluate Pine Script™ with the pyne CLI and library in under ten minutes.
This page
Quick Start
Abstract
This page is a linear path from a working install to the five desk operations most users need: parse, dump, unparse, lint, and evaluate. Full option trees live in CLI commands; deeper evaluation semantics live in Evaluate scripts.
Conceptual model
Rendering…
Interface surface
Assumes:
pip install hoox-pyne # https://pypi.org/project/hoox-pyne/ · 0.3.14+
# optional:
# pip install "hoox-pyne[lsp]" # editors
# pip install "hoox-pyne[compile]" # compile / run / prewarm
# pip install "hoox-pyne[data]" # ccxt providers
pyne info
pyne check script.pine
pyne lint script.pine
# aliases still work: pynescript info …
Sample script in-tree: examples/rsi_strategy.pine. Prefer //@version=6 and .pyne / .pine for new work (.pinev5 remains a supported legacy association).
Internals (repo paths)
| Step | Implementation |
|---|---|
| CLI parse/dump | src/pynescript/__main__.py → parse_and_dump |
| CLI unparse | parse_and_unparse |
| CLI lint | lint → pynescript.ast.linter.lint_script |
| Library helpers | src/pynescript/ast/helper.py |
| Bar-loop Runtime SoT | src/pynescript/runtime/ (from pynescript.runtime import Runtime) |
| Example scripts | examples/parse_dump_unparse.py, examples/evaluate_expressions.py |
Invariants & edge cases
- Always declare
//@version=6at the top (v5 still parses); the linter warns (W001) if the pragma is missing. parse-and-unparseis a formatter via AST, not a semantic optimizer.literal_evalis for expressions / built-in calls with optional series context — not a full multi-bar strategy backtester. For bar loops, usepynescript.runtime.Runtime(or the Pro API/run).- Filename arguments to the CLI must exist and be readable; lint may also read stdin (
-or no file).
Worked examples
1. Parse and dump the AST
pyne parse-and-dump examples/rsi_strategy.pine
Pretty-print with indent and optional file output:
pyne parse-and-dump examples/rsi_strategy.pine --indent 2 --output-file /tmp/rsi.ast.txt
Library equivalent:
from pynescript.ast import parse, dump
with open("examples/rsi_strategy.pine", encoding="utf-8") as f:
tree = parse(f.read(), "examples/rsi_strategy.pine")
print(dump(tree, indent=2))
2. Round-trip unparse (normalize)
pyne parse-and-unparse examples/rsi_strategy.pine
pyne parse-and-unparse messy.pine --output-file clean.pine
from pynescript.ast import parse, unparse
source = """
//@version=6
indicator("My RSI")
rsi(close, 14)
"""
print(unparse(parse(source)))
Canonical demo: examples/parse_dump_unparse.py.
3. Lint before upload
pyne lint examples/rsi_strategy.pine
pyne lint --fail-on warnings examples/rsi_strategy.pine
echo '//@version=6\nindicator("x")\nplot(close)' | pyne lint -
Library:
from pynescript.ast.linter import lint_script
issues = lint_script(open("examples/rsi_strategy.pine").read(), "rsi_strategy.pine")
for w in issues:
print(w) # severity: [CODE] message at line N
4. Evaluate expressions
from pynescript.ast.helper import literal_eval
print(literal_eval("1 + 2 * 3")) # 7
print(literal_eval("math.sqrt(16)"))
prices = [100, 102, 101, 103, 105, 104, 106, 108, 107, 110]
print(literal_eval(f"ta.rsi({prices}, 9)"))
# Series history with context
ctx = {
"close": [100, 102, 101, 103, 105],
"open": [99, 101, 100, 102, 104],
}
print(literal_eval("close[0] - close[1]", ctx))
Broader demo: examples/evaluate_expressions.py.
5. Fetch sample market data (CLI)
# mock provider (no network)
pyne data AAPL --provider mock
# Yahoo (network)
pyne data AAPL --provider yahoo --period 6mo --interval 1d
# CCXT (needs hoox-pyne[data])
pyne data BTC/USDT --provider ccxt --exchange binance
6. Optional: local Pro API /run
# from monorepo with backend deps
make run
curl -s -X POST http://127.0.0.1:5002/run \
-H 'Content-Type: application/json' \
-d '{
"script": "//@version=6\nindicator(\"t\")\nplot(close)",
"mode": "auto",
"data": [
{"time": 1, "open": 1, "high": 2, "low": 0.5, "close": 1.5, "volume": 100},
{"time": 2, "open": 1.5, "high": 2.5, "low": 1.0, "close": 2.0, "volume": 120}
]
}' | python -m json.tool
Omit mode to use the schema default auto (warm compile when eligible, else interpret). Response may include series, plot_meta, events, drawings, and alerts. See Pro API usage for batch mode, webhooks, free-tier guards, and prewarm.
Prefer saving stack sources as .pyne (.pine still works).
7. Library bar-loop vs CLI smoke
Library Runtime.run defaults to interpret. pyne run is compile-only on synthetic bars and does not accept --mode.
from pynescript.runtime import Runtime
ohlcv = [
{"time": 1, "open": 1, "high": 2, "low": 0.5, "close": 1.5, "volume": 100},
{"time": 2, "open": 1.5, "high": 2.5, "low": 1.0, "close": 2.0, "volume": 120},
]
out = Runtime(symbol="DEMO").run(
'//@version=6\nindicator("t")\nplot(close)\n',
ohlcv,
mode="interpret",
timeout_seconds=5.0,
)
print(out.get("mode"), list(out.get("series", {})))
pip install "hoox-pyne[compile]"
pyne run examples/rsi_strategy.pine --bars 50
See modes.
8. Optional: start LSP for editors
pip install "hoox-pyne[lsp]"
pyne-lsp # stdio; normally launched by the editor
# alias: pynescript-lsp
Wire Neovim / Zed / Emacs using Editors and clients/.
Failure modes
| Step fails | Check |
|---|---|
Dump raises SyntaxError | Script version / unsupported construct — try a minimal indicator + plot(close) |
| Unparse output differs cosmetically | Expected; compare semantic structure via dump |
| Lint exits non-zero | --fail-on threshold; inspect codes E001, W001, … |
literal_eval NotImplementedError | Expression not in literal/builtin subset; use full Runtime |
data provider error | Network, API key, missing ccxt extra |