Pynecore Practice
ASecurityThe Pine-first way to write PyneCore strategies, indicators and libraries: author the Pine Script in `content/<name>.pine` (libraries in `content/lib/<user>/<Name>/v<N>.pine`), generate the same-named `scripts/<name>.py` with the local pine2pyne, verify it against PyneCore, run it with `pyne run <name>.py <data>`, and iterate in the Pine only. Use whenever a task writes or changes a strategy or indicator in a project with a `content/` folder, mentions `content/` or 'Pine-first', asks to add a...
- 2 stars
- 0 votes
- 0 copies
- 3 views
- Added November 17, 2026
Works with
Security analysis
100/100Pro scans all 9 files and shows the line behind each finding
npx -y skills add theonetrade/pynecore-skills --skill pynecore-practice --agent claude-codeAre you the author of Pynecore Practice?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/theonetrade-pynecore-practice)---
name: pynecore-practice
license: MIT
description: "The Pine-first way to write PyneCore strategies, indicators and libraries: author the Pine Script in `content/<name>.pine` (libraries in `content/lib/<user>/<Name>/v<N>.pine`), generate the same-named `scripts/<name>.py` with the local pine2pyne, verify it against PyneCore, run it with `pyne run <name>.py <data>`, and iterate in the Pine only. Use whenever a task writes or changes a strategy or indicator in a project with a `content/` folder, mentions `content/` or 'Pine-first', asks to add an input or change the logic of a strategy kept as `.pine`, or when a `.pine` and a same-named `.py` both exist. Covers the layout, the helper that converts, checks and runs, `scripts/<name>.toml` overrides, libraries, what to commit, PyneIDE and its agent files, porting by hand, recording problems in `docs/pynecore_vs_pine.md`, and reporting. Self-contained: carries the pine2pyne install-and-use guide and its install checker."
---
# Pine-first: `content/<name>.pine` → `scripts/<name>.py` → `pyne run`
The user writes strategies in Pine Script and runs them on PyneCore. The Pine source is the
only file edited by hand and **stays in `content/` after generation, for the life of the
script**; the Pyne script is generated from it by the local `pine2pyne` (install and usage
guide: `references/pine2pyne.md`), carries the same stem, and is what `pyne run` executes.
Every development iteration is the same three moves: change the `.pine`, regenerate the
`.py`, run.
Every statement below was exercised on a workdir with the demo data (PyneCore 6.12.1,
pine2pyne 0.2.11): a strategy, an indicator and a library, converted, run, edited and
re-converted.
```
<workdir>/
├── .pyne
├── content/ # Pine sources: the source of truth, edited by hand
│ ├── ema_atr.pine # strategy("...") or indicator("...")
│ └── lib/mine/Helpers/v1.pine # library("Helpers"), imported as `import mine/Helpers/1 as h`
├── scripts/ # generated by pine2pyne, same stems; never edited by hand
│ ├── ema_atr.py # header: "compiled by pine2pyne <version>"
│ ├── ema_atr.toml # inputs and settings, written by the first run (see rule 4)
│ └── lib/mine/Helpers/v1.py # imported by the script as `lib.mine.Helpers.v1`
├── data/ # candle files (demo.ohlcv + demo.toml, downloads)
└── output/ # ema_atr.csv (plots), ema_atr_strat.csv, ema_atr_trade.csv
```
```bash
python3 <skill>/scripts/pine_first.py --init # content/, content/lib/, scripts/lib/
python3 <skill>/scripts/pine_first.py --template strategy ema_atr # content/ema_atr.pine from the template
# ... edit content/ema_atr.pine ...
python3 <skill>/scripts/pine_first.py ema_atr --run demo # convert (if newer) + pyne run ema_atr.py demo + figures
python3 <skill>/scripts/pine_first.py --all --run demo # every content/*.pine, libraries first
```
Without the helper, the same flow by hand:
```bash
pine2pyne content/lib/mine/Helpers/v1.pine -o scripts/lib/mine/Helpers/v1.py # libraries first
pine2pyne content/ema_atr.pine -o scripts/ema_atr.py
PYNE_NO_LOGO=1 pyne --workdir <workdir> run ema_atr.py demo # always with the .py suffix
```
## 1. Why the Pine lives in `content/` and not in `scripts/`
- `pyne run <name>` with a bare name resolves `scripts/<name>.pine` **before** `scripts/<name>.py`,
and with a PyneSys key configured it uploads the Pine to the cloud compiler and overwrites the
`.py` (`references/pine2pyne.md`, section 1). With no `.pine` in
`scripts/`, both `pyne run ema_atr demo` and `pyne run ema_atr.py demo` run the generated file
(verified).
- PyneIDE treats `scripts/*.pine` as cloud-compile targets (Run / Debug Pine Script, Compile
Pine Script) and asks to overwrite a `.py` it did not generate. `content/` is outside its
Scripts tree, so the IDE only ever sees the generated `.py`, which it runs and debugs locally.
- The generated file is disposable; the Pine is not. Two folders make the direction of the
dependency visible in `git status` and in a diff.
## 2. The flow, step by step
1. **New script**: `pine_first.py --template strategy <name>` (or `indicator`, or `library`,
which writes `content/lib/mine/<name>/v1.pine`) copies a working template; or create
`content/<name>.pine` yourself. Write Pine the way `references/getting-started.md`
describes: `//@version=6`, one declaration, inputs with literal defaults and titles, `ta.*`
at the top level, typed `var` state, unique plot titles, order ids.
2. **Build and run**: `pine_first.py <name> --run <data>`. The helper checks that the installed
transpiler is `pine2pyne` >= 0.2.11 (`scripts/check_install.py`; `references/pine2pyne.md`
section 2 has the install rule), converts every library under `content/lib/` and the
script when the Pine is newer than the `.py` (`--force` to redo), prints pine2pyne's `✓` / `✗`
lines, then runs `pyne run <name>.py <data>` and prints the figures from `output/`:
```
✓ content/lib/mine/Helpers/v1.pine → scripts/lib/mine/Helpers/v1.py
✓ content/ema_atr.pine → scripts/ema_atr.py
+ run ema_atr.py demo
Net profit: 293.5244 / 2.9352 %
Max equity drawdown: ...
Total trades: 15
Percent profitable: 46.6667 %
Profit factor: 2.3194
trades file: output/ema_atr_trade.csv (30 rows)
plots: output/ema_atr.csv columns: time,open,high,low,close,volume,Fast EMA,Slow EMA,Stop,Target
```
Options for `pyne run` go after `--`: `pine_first.py ema_atr --run BTCUSDT_60 -- --from
2024-01-01 --to 2024-12-31 --no-plot`.
3. **Verify the generated script** against PyneCore before trusting the numbers: read
`scripts/<name>.py` with the checklist of `references/pine2pyne.md` section 7
(decorator arguments, inputs, `Persistent` / `Series` annotations, library imports, `ta.*`
names, order calls, `request.security` data). Do it on the first generation and after any
structural change in the Pine; a parameter tweak does not need it.
4. **Iterate in Pine**: edit `content/<name>.pine`, run step 2 again. The helper re-converts
because the Pine is newer; a run with an up-to-date `.py` prints
`= scripts/<name>.py is up to date with content/<name>.pine` and goes straight to `pyne run`.
5. **Read the results**: `output/<name>_strat.csv` (metrics), `output/<name>_trade.csv` (every
entry and exit), `output/<name>.csv` (one row per bar, a column per plot title). For a deeper
report use the `pynecore-strategy` skill's `summarize_backtest.py` and `run_backtest.py`
(`../pynecore-strategy/scripts/`); they take the `.py` like any Pyne script.
## 3. Rules
1. **`content/<name>.pine` is the source of truth, is never deleted after generation, and
`scripts/<name>.py` is never edited by hand.** Every change, on every iteration of the
development, is made in the `.pine` first and carried into the `.py` by re-converting before
the run (`pine_first.py <name> --run <data>` does both). The next build overwrites the `.py`
(the helper converts whenever the Pine is newer), so a fix that lives only in the `.py` is
lost; a fix belongs in the Pine.
2. **Same stem, same place.** `content/<name>.pine` ↔ `scripts/<name>.py` ↔ `scripts/<name>.toml`
↔ `output/<name>*.csv`. Libraries: `content/lib/<user>/<Name>/v<N>.pine` ↔
`scripts/lib/<user>/<Name>/v<N>.py` ↔ `import <user>/<Name>/<N> as alias` in the Pine
(`<user>` is any folder name for your own libraries; a `-` in it becomes `_`).
3. **Run the `.py`, never a bare name while a `.pine` twin exists, never the `.pine`.** The
helper runs `pyne run <name>.py <data>` and prints a note when it finds `scripts/<name>.pine`
(move it to `content/`).
4. **`scripts/<name>.toml` overrides the Pine defaults.** The first run writes the file with
every input as `#value =` (commented): the defaults in the Pine apply. Once a `value = ...`
line is uncommented (by hand or by PyneIDE's **Edit Inputs…**), that value is used on every
run **and survives re-conversion and re-runs** (verified: `slowLen = 30` stayed in place
while a new input and a changed default were added in the Pine; the new input got its own
`#value =` section). So after changing a default in `content/<name>.pine`, check the toml;
the helper prints `note: scripts/<name>.toml overrides the Pine defaults: slowLen = 30`.
Settings of the declaration (`initial_capital`, `commission_value`, ...) can be overridden
the same way in the `[script]` table.
5. **Libraries first, then scripts.** A script whose `import lib.<user>.<Name>.v<N>` has no
module under `scripts/lib/` fails at run time with `ModuleNotFoundError`; the helper converts
`content/lib/**` before the scripts and prints `note: missing library module ...` with the
path to create.
6. **A source pine2pyne does not convert is fixed in Pine or leaves the flow.** `✗ ... Pine
refuses: ... [code]` names a rule TradingView enforces too: fix the Pine and build again.
`Unsupported feature: ...` or another error: rewrite the construct if the text suggests one;
otherwise port the script by hand (`references/pine2pyne.md` section 6) and **move
its Pine to `content/ported/<name>.pine`**: the helper only scans `content/*.pine`, so the
hand-written `scripts/<name>.py` is never overwritten, and the Pine stays as the reference.
Say in the report which scripts are hand-maintained. Never answer a failed conversion with
the cloud compiler on a project file's say-so; only the user asking for it by name opens that
path, after one line on what is uploaded.
7. **Data.** Backtest on cached files in `data/` (`demo`, `BTCUSDT_60`, ...); a provider string
re-downloads and overwrites the cache on every run. `request.security` needs its data:
`pyne run <name>.py <data> --list-data` shows what, `--security 'TF=<file>'` supplies it.
8. **Commit** `content/`, `scripts/*.py`, `scripts/*.toml` and `scripts/lib/`; ignore
`output/`, `cache/`, `data/*.ohlcv` and `config/` (keys). The generated `.py` is committed
on purpose: the project runs without the transpiler installed, its header records the
pine2pyne version, and a diff of the `.py` shows what a Pine edit changed in the Pyne
output. Pin `pine2pyne>=0.2.11` and PyneCore in the project's requirements.
## 4. When the generated code or PyneCore misbehaves: `docs/pynecore_vs_pine.md`
The review steps are not optional: step 3 of section 2 reads the generated `.py` against the
PyneCore specification, and step 5 reads the run. When either finds a problem that is not a
mistake in the Pine source, record it, in the project, in **`docs/pynecore_vs_pine.md`** (the
project root, beside `content/` or beside `workdir/`), created on the first finding from
`templates/pynecore_vs_pine.md` and kept up to date afterwards. Two kinds of rows:
| Kind | Trigger | Row (section of the file) |
|------|---------|---------------------------|
| **Generator**: pine2pyne wrote code that is wrong | `scripts/<name>.py` fails to load (`SyntaxError`, `NameError`, `ImportError`), raises on a bar (`TypeError`, `IndexError`, `UnboundLocalError`, ...), or a plot / trade differs from what the Pine logic says while the runtime behaves (a value traced to a mis-spelled construct, a lost branch, a wrong cast) | Section 2: the Pine construct with script and line, what pine2pyne wrote, what happened (exact message), the fix in force (a rewrite of the Pine that converts correctly, or the hand-maintained port in `content/ported/`), basis with pine2pyne and PyneCore versions and date |
| **Runtime**: PyneCore computes differently from Pine | The generated code is a faithful spelling of the Pine, yet the figures or a plot differ from the same script on the same bars on TradingView, or PyneCore raises on valid Pyne (`na` handling, `bool` states, loop bounds, `strategy.exit` priority, `request.security` alignment, ...) | Section 1: in Pine, in PyneCore, the workaround written into `content/<name>.pine`, basis (symbol, timeframe, date range, how it was measured, PyneCore version) |
What a row needs: a minimal reproduction (inline, or `content/probes/<id>.pine` converted with
`pine_first.py content/probes/<id>.pine`), the exact message or the two figures, the versions
(`pine2pyne --version`, `python -c "import importlib.metadata as m; print(m.version('pynesys-pynecore'))"`)
and the date. A difference that was not measured on TradingView goes to section 3 of the file
until it is. The workaround itself goes into the Pine source (rule 1), with a comment that
names the row (`// pynecore_vs_pine #3`), so the next conversion carries it. Report the finding
upstream when it is reproducible (pine2pyne: <https://github.com/pine2pyne/pine2pyne/issues>;
PyneCore: <https://github.com/PyneSys/pynecore/issues>) and put the link in the row; when a
newer version removes the problem, say so in the row and drop the workaround from the Pine.
The `pynecore-pine2pyne` skill requires the same file in the same format (its section 3.4).
## 5. Patch the project's agent files so they say pine2pyne
A PyneIDE project carries `AGENTS.md` (a generated block `<!-- pyneide-project:start -->` ...
`<!-- pyneide-project:end -->` with a "Pine source ownership" section that routes every Pine
task to the IDE's cloud compile), a `CLAUDE.md` that usually only contains `@AGENTS.md` inside
the same markers, and `AGENT_RULES.md` ("My development preferences", read by the IDE as the
user's rules and kept across refreshes). A host loads these files into every session above any
skill, so until they say pine2pyne, each new session starts with an instruction this skill has
to contradict. **On the first conversion in such a project, patch them**:
```bash
python3 <skill>/scripts/pine_first.py --agent-files # idempotent; prints what it changed
```
What it does, and what to do by hand when the helper is not used:
| File | Action |
|------|--------|
| `AGENT_RULES.md` | Append the note below (the durable place: PyneIDE keeps this file when the project is re-initialized; the starter text may stay) |
| `AGENTS.md` | Append the note **after** `<!-- pyneide-project:end -->`, never inside the block: Initialize Pyne Project rewrites the block and leaves text outside it |
| `CLAUDE.md` | Same, unless its only content is `@AGENTS.md`: then nothing to add, it already includes `AGENTS.md` |
| `.agents/skills/*`, `.claude/skills/*`, `.cursor/skills/*` | Leave them; generated copies the IDE re-creates, and the note above them wins for the agent |
| A project without these files | Nothing to patch; this skill's rule suffices |
Keep the IDE's "Pine source ownership" text: its part about the `.pine` being the source of
truth and the `.py` not being hand-edited is exactly rule 1. The note, appended verbatim (the
helper writes the same text and skips a file that already carries the first line):
```markdown
<!-- pine2pyne: local Pine conversion -->
## Pine Script conversion
Pine sources (`.pine`) in this project live in `content/` and are converted to Pyne Python
locally with the `pine2pyne` transpiler (PyPI `pine2pyne>=0.2.11`), never with the PyneSys
cloud compiler: no `pyne compile`, no `pyne run <name>.pine`, no API key in `config/api.toml`,
and none of PyneIDE's Pine commands (Compile / Run / Debug / Profile Pine Script, Convert to
Pine v6). Convert with `pine2pyne content/<name>.pine -o scripts/<name>.py` (libraries:
`content/lib/<user>/<Name>/v<N>.pine` -> `scripts/lib/<user>/<Name>/v<N>.py`), keep the `.pine`
as the source of truth, re-convert after each Pine edit instead of hand-editing the `.py`, and
run, debug and chart the `.py` (`pyne run <name>.py <data>`, PyneIDE "Run Pyne code" / "Debug
Pyne code"). A source pine2pyne refuses is ported to Pyne by hand, never sent to the cloud. The
cloud compiler runs only when the user asks for it by name. Details and tools: the
`pynecore-practice` skill.
```
Verify with `grep -l "pine2pyne: local Pine conversion" AGENT_RULES.md AGENTS.md CLAUDE.md` and
say in the report which files received the note. If the user does not want the files changed,
say so in the report and follow the rule for the session only.
## 6. PyneIDE in this flow
- The IDE's Scripts tree shows `scripts/`: **Run Pyne code**, **Debug Pyne code**, **Profile**,
**Open Chart** and **Edit Inputs…** work on the generated `scripts/<name>.py` as on any Pyne
script. **Edit Inputs…** writes `value =` lines into `scripts/<name>.toml`, which is rule 4.
- `content/` is not a PyneIDE folder; edit the Pine there with any editor, then build.
- Never run the IDE's Pine commands on a file in `content/` or `scripts/`; a `.py.map` from an
earlier cloud compile is stale and harmless.
## 7. Report
What to tell the user after a build-and-run: the Pine file edited and what changed in it; the
pine2pyne version and whether the script and which libraries were (re)converted or were up to
date; every `✗`, `⚠` and `note:` line and what was done about it (a toml override in force is
worth a sentence); the data and range run; the figures (`Net profit`, `Total trades`,
`Percent profitable`, `Profit factor`, `Max equity drawdown`) with the path of `_strat.csv` and
`_trade.csv`; which scripts, if any, are hand-maintained and why; what was verified in the
generated code versus assumed; every row added to or changed in `docs/pynecore_vs_pine.md`; and
which agent files received the pine2pyne note (section 5).
## 8. Bundled files
| File | Use |
|------|-----|
| `scripts/pine_first.py` | The flow in one command: `--init`, `--agent-files` (the note of section 5 into `AGENT_RULES.md` / `AGENTS.md` / `CLAUDE.md`, idempotent), `--template {strategy,indicator,library} NAME`, convert `content/<name>.pine` (and `content/lib/**`) when newer or `--force`, notes on `.pine` twins, stale `.py.map`, missing libraries and toml overrides, `--run DATA [-- pyne options]` with the figures; stdlib only |
| `templates/strategy_template.pine` | EMA cross with ATR stop / target, trend filter input, typed `var` state, four titled plots; converts and runs on the demo data |
| `templates/indicator_template.pine` | RSI with bands, `hline`s and `plotshape` markers; converts and runs |
| `templates/library_template.pine` | `library("Helpers")` with two exported functions, the path and import spelling explained in its header |
| `templates/pynecore_vs_pine.md` | The project's `docs/pynecore_vs_pine.md` to create on the first finding: runtime differences, generator problems, not-measured list, where things are (section 4) |
| `references/getting-started.md` | How to write the Pine so it converts and runs: structure, the rules TradingView enforces too, libraries, data, what to verify after generation |
| `references/pine2pyne.md` | The transpiler in full: the local-only rule and the user's exception, installing the right distribution (`pine2pyne` >= 0.2.11, never `opencode-pine2pyne`), every option and where output goes, what a generated file looks like, reading `✓` / `⚠` / `✗` lines, porting by hand, the PyneCore verification checklist, the note for a PyneIDE project's agent files |
| `scripts/check_install.py` | Verify the installed distribution is `pine2pyne` >= 0.2.11 and not `opencode-pine2pyne`; `--fix` repairs (same script as in the `pynecore-pine2pyne` skill) |
Converting, the install rule for `pine2pyne`, reading its messages and verifying the generated
code are documented here in `references/pine2pyne.md` and, with a generic converter helper, in
the `pynecore-pine2pyne` skill (`../pynecore-pine2pyne/SKILL.md`); everything about
the Pyne script once it exists (language, strategy API, backtest reports, Monte Carlo, live) is
the `pynecore-strategy` skill (`../pynecore-strategy/SKILL.md`); the `pyne` command and the
workdir are the `pynecore-cli` skill (`../pynecore-cli/SKILL.md`); PyneIDE is the `pynecore-ide`
skill (`../pynecore-ide/SKILL.md`); the PyneCore documentation is in `../pynecore-docs/docs/`.
Files in this skill
- SKILL.md
- references/getting-started.md
- references/pine2pyne.md
- scripts/check_install.py
- scripts/pine_first.py
- templates/indicator_template.pine
- templates/library_template.pine
- templates/pynecore_vs_pine.md
- templates/strategy_template.pine
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.