openpinescript 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +346 -2
- package/dist/cli.mjs +108686 -0
- package/dist/index.cjs +108670 -0
- package/dist/index.mjs +108624 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/parser/v1/generated/PineV1Lexer.d.ts +66 -0
- package/dist/types/parser/v1/generated/PineV1Parser.d.ts +555 -0
- package/dist/types/parser/v1/generated/PineV1ParserVisitor.d.ts +318 -0
- package/dist/types/parser/v1/index.d.ts +39 -0
- package/dist/types/parser/v2/generated/PineV2Lexer.d.ts +67 -0
- package/dist/types/parser/v2/generated/PineV2Parser.d.ts +568 -0
- package/dist/types/parser/v2/generated/PineV2ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v2/index.d.ts +2 -0
- package/dist/types/parser/v3/generated/PineV3Lexer.d.ts +67 -0
- package/dist/types/parser/v3/generated/PineV3Parser.d.ts +568 -0
- package/dist/types/parser/v3/generated/PineV3ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v3/index.d.ts +2 -0
- package/dist/types/parser/v4/generated/PineV4Lexer.d.ts +86 -0
- package/dist/types/parser/v4/generated/PineV4Parser.d.ts +673 -0
- package/dist/types/parser/v4/generated/PineV4ParserVisitor.d.ts +367 -0
- package/dist/types/parser/v4/index.d.ts +2 -0
- package/dist/types/parser/v5/generated/PineV5Lexer.d.ts +95 -0
- package/dist/types/parser/v5/generated/PineV5Parser.d.ts +964 -0
- package/dist/types/parser/v5/generated/PineV5ParserVisitor.d.ts +521 -0
- package/dist/types/parser/v5/index.d.ts +2 -0
- package/dist/types/parser/v6/generated/PineV6Lexer.d.ts +98 -0
- package/dist/types/parser/v6/generated/PineV6Parser.d.ts +984 -0
- package/dist/types/parser/v6/generated/PineV6ParserVisitor.d.ts +528 -0
- package/dist/types/parser/v6/index.d.ts +2 -0
- package/dist/types/runtime/v1/Series.d.ts +61 -0
- package/dist/types/runtime/v1/broker/Broker.d.ts +325 -0
- package/dist/types/runtime/v1/broker/index.d.ts +158 -0
- package/dist/types/runtime/v1/broker/val.d.ts +28 -0
- package/dist/types/runtime/v1/constDefault.d.ts +11 -0
- package/dist/types/runtime/v1/context.d.ts +1705 -0
- package/dist/types/runtime/v1/footprint.d.ts +32 -0
- package/dist/types/runtime/v1/index.d.ts +7 -0
- package/dist/types/runtime/v1/language-spec.d.ts +12 -0
- package/dist/types/runtime/v1/openTrades.d.ts +12 -0
- package/dist/types/runtime/v1/palette.d.ts +18 -0
- package/dist/types/runtime/v1/session.d.ts +482 -0
- package/dist/types/runtime/v1/sessions.d.ts +31 -0
- package/dist/types/runtime/v1/stateClone.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/alerts.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/arrays.d.ts +133 -0
- package/dist/types/runtime/v1/stdlib/barmerge.d.ts +27 -0
- package/dist/types/runtime/v1/stdlib/barstate.d.ts +79 -0
- package/dist/types/runtime/v1/stdlib/cast.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/chart.d.ts +283 -0
- package/dist/types/runtime/v1/stdlib/color.d.ts +51 -0
- package/dist/types/runtime/v1/stdlib/core.d.ts +162 -0
- package/dist/types/runtime/v1/stdlib/dataset.d.ts +36 -0
- package/dist/types/runtime/v1/stdlib/display.d.ts +50 -0
- package/dist/types/runtime/v1/stdlib/drawings.d.ts +407 -0
- package/dist/types/runtime/v1/stdlib/errors.d.ts +21 -0
- package/dist/types/runtime/v1/stdlib/font.d.ts +20 -0
- package/dist/types/runtime/v1/stdlib/footprint.d.ts +76 -0
- package/dist/types/runtime/v1/stdlib/format.d.ts +57 -0
- package/dist/types/runtime/v1/stdlib/index.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/input.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/inputs.d.ts +60 -0
- package/dist/types/runtime/v1/stdlib/late_members.d.ts +97 -0
- package/dist/types/runtime/v1/stdlib/logging.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/maps.d.ts +55 -0
- package/dist/types/runtime/v1/stdlib/math.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/matrix.d.ts +201 -0
- package/dist/types/runtime/v1/stdlib/metadata.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/mtf.d.ts +15 -0
- package/dist/types/runtime/v1/stdlib/renames.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/renames5.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/renames6.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/request.d.ts +207 -0
- package/dist/types/runtime/v1/stdlib/scale.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/session.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/sort_field.d.ts +12 -0
- package/dist/types/runtime/v1/stdlib/sources.d.ts +24 -0
- package/dist/types/runtime/v1/stdlib/str.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/strategy.d.ts +314 -0
- package/dist/types/runtime/v1/stdlib/syminfo.d.ts +209 -0
- package/dist/types/runtime/v1/stdlib/ta.d.ts +409 -0
- package/dist/types/runtime/v1/stdlib/time.d.ts +158 -0
- package/dist/types/runtime/v1/stdlib/trades.d.ts +108 -0
- package/dist/types/runtime/v1/stdlib/ui.d.ts +196 -0
- package/dist/types/runtime/v1/stdlib/v6_members.d.ts +68 -0
- package/dist/types/runtime/v1/timeframes.d.ts +139 -0
- package/dist/types/runtime/v1/zones.d.ts +30 -0
- package/dist/types/transpiler/common/index.d.ts +51 -0
- package/dist/types/transpiler/common/libraries.d.ts +29 -0
- package/dist/types/transpiler/common/parseErrors.d.ts +38 -0
- package/dist/types/transpiler/common/passes/ScopeAnalysis.d.ts +158 -0
- package/dist/types/transpiler/common/passes/TypeRules.d.ts +26 -0
- package/dist/types/transpiler/common/profiles/index.d.ts +96 -0
- package/dist/types/transpiler/common/version.d.ts +40 -0
- package/dist/types/transpiler/v1/ToJsVisitor.d.ts +720 -0
- package/dist/types/transpiler/v2/ToJsVisitor.d.ts +72 -0
- package/dist/types/transpiler/v3/ToJsVisitor.d.ts +87 -0
- package/dist/types/transpiler/v4/ToJsVisitor.d.ts +263 -0
- package/dist/types/transpiler/v5/ToJsVisitor.d.ts +1101 -0
- package/dist/types/transpiler/v6/ToJsVisitor.d.ts +237 -0
- package/dist/types/transpiler/v6/rules.d.ts +94 -0
- package/dist/types/utils/v2/common.d.ts +4 -0
- package/package.json +92 -4
package/README.md
CHANGED
|
@@ -1,3 +1,347 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# OpenPineScript
|
|
4
|
+
|
|
5
|
+
### Run TradingView Pine Script locally — offline, unlimited, and verified against TradingView itself
|
|
6
|
+
|
|
7
|
+
**Compile Pine Script to JavaScript and execute it on your own OHLCV data.**
|
|
8
|
+
No TradingView account. No cloud. No execution quota. No 500 ms loop timeout.
|
|
9
|
+
|
|
10
|
+
[](docs/common/CONFORMANCE.md)
|
|
11
|
+
[](docs/common/CONFORMANCE.md#testing)
|
|
12
|
+
[](#-supported-pine-script-versions)
|
|
13
|
+
|
|
14
|
+
[](LICENSE)
|
|
15
|
+
[](https://nodejs.org)
|
|
16
|
+
[](https://www.typescriptlang.org/)
|
|
17
|
+
[](docs/common/CONFORMANCE.md#parity-763-real-scripts-from-tradingviews-docs)
|
|
18
|
+
|
|
19
|
+
### [▶ Open Beta: try it in your browser at **zealterminal.com**](https://zealterminal.com) — no install, no CSV
|
|
20
|
+
|
|
21
|
+
[Docs](https://be-thomas.github.io/OpenPineScript/) · [Try it online](#-try-it-online) · [Quick start](#-quick-start) · [Why](#-why-openpinescript) · [Parity](#-verified-against-tradingview-itself) · [Guides](#-documentation) · [FAQ](#-faq)
|
|
22
|
+
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
**OpenPineScript is an open-source Pine Script engine.** It transpiles TradingView
|
|
28
|
+
Pine Script (`.pine`) to JavaScript and runs it against your own candles — so you
|
|
29
|
+
can **backtest a Pine Script strategy offline**, run a Pine indicator in CI,
|
|
30
|
+
convert Pine Script to JavaScript for embedding elsewhere, or batch-test
|
|
31
|
+
thousands of scripts without touching a browser.
|
|
32
|
+
|
|
33
|
+
Pine Script **v1, v2, v3, v4, v5 and v6** are implemented, each with its own
|
|
34
|
+
grammar and its own emitter.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
=== v4-essential-strategies-00.pine — Summary ===
|
|
38
|
+
Bars processed : 506
|
|
39
|
+
Plots recorded : 1
|
|
40
|
+
|
|
41
|
+
Performance:
|
|
42
|
+
Net Profit +$77.60 (+0.08%)
|
|
43
|
+
Total Trades 199
|
|
44
|
+
Win Rate 32.7% (65W / 55L)
|
|
45
|
+
Profit Factor 1.134
|
|
46
|
+
Max Drawdown 0.10%
|
|
47
|
+
Avg Win / Avg Loss $10.10 / $10.52
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
<sub>One of TradingView's own documentation examples, unedited, run locally.</sub>
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🌲 Try it online
|
|
55
|
+
|
|
56
|
+
Not everyone wants to clone a repository to find out whether an engine handles
|
|
57
|
+
their script. **[Zeal Terminal](https://zealterminal.com)** is a charting workspace
|
|
58
|
+
built on OpenPineScript — this engine, compiled to a Web Worker and running
|
|
59
|
+
inside the browser tab.
|
|
60
|
+
|
|
61
|
+
[](https://zealterminal.com)
|
|
62
|
+
|
|
63
|
+
<div align="center">
|
|
64
|
+
|
|
65
|
+
### **[▶ Get Open Beta Access at zealterminal.com](https://zealterminal.com)**
|
|
66
|
+
|
|
67
|
+
<sub>Open beta — free, and open to anyone with a Google account.</sub>
|
|
68
|
+
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
Paste a script, press apply, and watch it draw. The engine runs on your own
|
|
72
|
+
machine, so there is no compile queue and no round trip to wait for — the same
|
|
73
|
+
properties this repository gives you at the command line, with a chart attached.
|
|
74
|
+
|
|
75
|
+
| | |
|
|
76
|
+
|---|---|
|
|
77
|
+
| 💻 **Runs in your browser** | This engine in a Web Worker. Execution is local; nothing is queued on a server. |
|
|
78
|
+
| 📈 **A real chart** | Multi-pane indicators, drawings, a strategy tester, execution logs and a dockable layout. |
|
|
79
|
+
| 🧮 **v1 → v5** | The same five grammars and emitters that are in this repository. |
|
|
80
|
+
| 🆓 **Open Beta, free** | Get Open Beta Access with Google, and the workspace opens. |
|
|
81
|
+
|
|
82
|
+
Zeal Terminal is a separate product and its workspace is proprietary; **the engine
|
|
83
|
+
underneath it is this repository, GPL-3 and public**, so the arithmetic behind
|
|
84
|
+
any backtest it shows you can be read here rather than taken on trust.
|
|
85
|
+
|
|
86
|
+
<sub>Screenshot: Bollinger Bands drawn from the Pine source beside it, on sample data.</sub>
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## ⚡ Quick start
|
|
91
|
+
|
|
92
|
+
Run any Pine script against a CSV of bars, with nothing to install (Node.js 20 or newer):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx openpinescript my_script.pine --data candles.csv
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Use the engine from JavaScript:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install openpinescript
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { Session } from "openpinescript";
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To work on the engine itself, run it from a clone:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
git clone https://github.com/be-thomas/OpenPineScript.git
|
|
112
|
+
cd OpenPineScript
|
|
113
|
+
npm install
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then run a bundled example:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm run opsv2 -- examples/v1/sma_crossover.pine --data mock_data/common/AAPL_mock.csv
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Or explore interactively:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm run replv2
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+

|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 🎯 Why OpenPineScript
|
|
133
|
+
|
|
134
|
+
| | |
|
|
135
|
+
|---|---|
|
|
136
|
+
| 📊 **Numbers you can trust** | 112 indicator, control-flow and broker columns matched **bar for bar** against TradingView's own output. Not against a spec — against the platform. |
|
|
137
|
+
| 🔌 **Completely offline** | Your data, your machine, your loop budget. No account, no quota, no rate limit, no network. |
|
|
138
|
+
| 🗂️ **Six language versions** | v1 → v6, each with its own grammar and emitter, so a v2 script is parsed by a parser that has never heard of `var`. |
|
|
139
|
+
| 🔁 **Pine → JavaScript** | Emit readable JS and embed it anywhere — a worker, a server, a browser, a CI job. |
|
|
140
|
+
| 🤖 **Built for automation** | JSON output, exit codes, input overrides, and a comparison mode that diffs your run against a TradingView export. |
|
|
141
|
+
| 🧪 **3,389 tests** | Differential testing against an independent oracle, a full version matrix, 763 real scripts from TradingView's docs, and the parity suites above. |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 🎖️ Verified against TradingView itself
|
|
146
|
+
|
|
147
|
+
Most engines are tested against a specification or a reference implementation.
|
|
148
|
+
Neither catches an indicator that is subtly and **consistently** wrong.
|
|
149
|
+
|
|
150
|
+
So nine harness scripts were run **inside TradingView**, their per-bar output
|
|
151
|
+
copied back out, and replayed here against the same candles:
|
|
152
|
+
|
|
153
|
+
<div align="center">
|
|
154
|
+
|
|
155
|
+
### **112 columns · ~2,474 bars each · tolerance 1e-6 · all agree**
|
|
156
|
+
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
A further **38 indicators** are anchored to values TradingView's own screener
|
|
160
|
+
computed, from a frozen fixture that runs unattended on every commit.
|
|
161
|
+
|
|
162
|
+
This process found **eleven defects** that every other kind of test had missed —
|
|
163
|
+
including a Parabolic SAR that was the textbook algorithm rather than
|
|
164
|
+
TradingView's, market orders filling a bar early at the wrong price, and a VWAP
|
|
165
|
+
that never reset at session boundaries.
|
|
166
|
+
|
|
167
|
+
> 📖 **[Read the full conformance report →](docs/common/CONFORMANCE.md)**
|
|
168
|
+
> Every harness, every defect, how the data is collected — and an honest account
|
|
169
|
+
> of [what is *not* covered yet](docs/common/CONFORMANCE.md#what-is-not-covered).
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 🗂️ Supported Pine Script versions
|
|
174
|
+
|
|
175
|
+
The `//@version` annotation selects the language version; a script without one is v1.
|
|
176
|
+
|
|
177
|
+
| Version | State | What it adds |
|
|
178
|
+
|---------|-------|--------------|
|
|
179
|
+
| **v1** | ✅ Implemented | The base language |
|
|
180
|
+
| **v2** | ✅ Implemented | `:=` |
|
|
181
|
+
| **v3** | ✅ Implemented | A five-item tightening of v2 |
|
|
182
|
+
| **v4** | ✅ Implemented | `var` / `varip`, arrays, drawing objects, the namespace migration |
|
|
183
|
+
| **v5** | ✅ Implemented | `while`, `switch`, user-defined types, methods, libraries, matrices, maps, Pine Logs, the `ta.*` / `math.*` / `str.*` migration |
|
|
184
|
+
| **v6** | ✅ Implemented | The migration guide's rules — strict bools, lazy `and`/`or`, dynamic `for` bounds, negative array indices, margin enforcement, `strategy.exit()` parameter pairs — plus `once`, multiline strings, `request.footprint()`, text formatting, library constants and `sort_field` |
|
|
185
|
+
|
|
186
|
+
Roughly **270 standard-library names** are implemented, along with the strategy
|
|
187
|
+
broker emulator, multi-timeframe `security()`, and the real-time tick model.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 🛠️ What you can build with it
|
|
192
|
+
|
|
193
|
+
- **Backtest Pine Script strategies offline** on years of your own data, with no execution cap
|
|
194
|
+
- **Run indicators in CI** and fail a build when a signal changes
|
|
195
|
+
- **Convert Pine Script to JavaScript** and embed it in a product
|
|
196
|
+
- **Batch-screen thousands of scripts** in parallel
|
|
197
|
+
- **Diff against TradingView** with `--compare-dir` to measure agreement on your own script
|
|
198
|
+
- **Put it behind a chart** — [zealterminal.com](https://zealterminal.com) is this engine in a browser tab, in open beta, if you want to see that shape working before you build it
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npm run opsv2 -- strategy.pine --data data.csv --out-dir ./results --json
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
> 📖 **[Full CLI reference →](CLI-Usage.md)** — output flags, comparison mode,
|
|
205
|
+
> input overrides, structured output, debug flags.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 📚 Documentation
|
|
210
|
+
|
|
211
|
+
| Doc | What it answers |
|
|
212
|
+
|---|---|
|
|
213
|
+
| **[Conformance report](docs/common/CONFORMANCE.md)** | How the numbers are verified, what that caught, what is not covered |
|
|
214
|
+
| **[CLI usage](CLI-Usage.md)** | Every flag, with worked examples |
|
|
215
|
+
| **[Architecture](docs/common/ARCHITECTURE.md)** | The compile pipeline and the repository layout |
|
|
216
|
+
| **[Golden-data recipe](conformance/common/golden.md)** | How to collect a new TradingView export |
|
|
217
|
+
| **[Integration guide](docs/common/integration/README.md)** | Embedding the engine in a charting UI: plotting, strategies, live ticks |
|
|
218
|
+
| **[Pine versions](docs/common/VERSIONS.md)** | What each version, v1 to v6, changes and where the engine implements it |
|
|
219
|
+
| **[Deliberate omissions](docs/common/CONFORMANCE.md#restrictions-the-engine-does-not-enforce)** | The TradingView limits and checks the engine does not apply |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## ❓ FAQ
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary><b>Is there a chart? Can I see a script actually draw?</b></summary>
|
|
227
|
+
<br>
|
|
228
|
+
|
|
229
|
+
Yes — at **[zealterminal.com](https://zealterminal.com)**. Zeal Terminal is a charting
|
|
230
|
+
workspace that runs this engine in a Web Worker in your browser: paste a script,
|
|
231
|
+
press apply, and it draws. Nothing to install and no CSV to find.
|
|
232
|
+
|
|
233
|
+
The workspace itself is a separate, proprietary product. The engine underneath
|
|
234
|
+
it is this repository, GPL-3 and public.
|
|
235
|
+
</details>
|
|
236
|
+
|
|
237
|
+
<details>
|
|
238
|
+
<summary><b>Can I run Pine Script without a TradingView account?</b></summary>
|
|
239
|
+
<br>
|
|
240
|
+
|
|
241
|
+
Yes. That is the point of the project. OpenPineScript compiles and executes Pine
|
|
242
|
+
Script entirely on your machine, against CSV data you supply. Nothing is sent
|
|
243
|
+
anywhere and no account is involved.
|
|
244
|
+
</details>
|
|
245
|
+
|
|
246
|
+
<details>
|
|
247
|
+
<summary><b>Does it support Pine Script v5?</b></summary>
|
|
248
|
+
<br>
|
|
249
|
+
|
|
250
|
+
Yes — v5 is implemented, including user-defined types, methods, libraries,
|
|
251
|
+
`while`, `switch`, matrices, maps, enums and Pine Logs, along with the `ta.*`,
|
|
252
|
+
`math.*`, `str.*` and `request.*` namespace migration. v1 through v4 are
|
|
253
|
+
implemented too.
|
|
254
|
+
</details>
|
|
255
|
+
|
|
256
|
+
<details>
|
|
257
|
+
<summary><b>Does it support Pine Script v6?</b></summary>
|
|
258
|
+
<br>
|
|
259
|
+
|
|
260
|
+
Yes. v6 has its own grammar and emitter, inheriting from v5's, so adding it did
|
|
261
|
+
not change what any v1–v5 script compiles to. It covers TradingView's v6
|
|
262
|
+
migration guide and the release notes through September 2026.
|
|
263
|
+
|
|
264
|
+
One caveat worth knowing before relying on v6 strategy numbers: the v1–v5
|
|
265
|
+
broker columns are matched against TradingView's own output, and v6's are not
|
|
266
|
+
yet. v6 changes the broker — `strategy.exit()` takes whichever paired level
|
|
267
|
+
triggers first, and margin is enforced by default — and those rules are
|
|
268
|
+
implemented from TradingView's documentation without captured fixtures to check
|
|
269
|
+
them against. The same goes for `request.footprint()`'s Value Area and
|
|
270
|
+
imbalance rules, which the documentation leaves partly unstated.
|
|
271
|
+
</details>
|
|
272
|
+
|
|
273
|
+
<details>
|
|
274
|
+
<summary><b>Will results match TradingView exactly?</b></summary>
|
|
275
|
+
<br>
|
|
276
|
+
|
|
277
|
+
Where it has been measured, yes. 112 columns are compared bar for bar against
|
|
278
|
+
output collected from TradingView, at a relative tolerance of 1e-6, and all of
|
|
279
|
+
them agree. That covers roughly a tenth of the standard library, concentrated in
|
|
280
|
+
`ta.*`, `math.*` and `strategy.*` — the
|
|
281
|
+
[conformance report](docs/common/CONFORMANCE.md#what-is-not-covered) says plainly what
|
|
282
|
+
is not covered.
|
|
283
|
+
|
|
284
|
+
To measure it on *your* script, use `--compare-dir` against a TradingView export.
|
|
285
|
+
</details>
|
|
286
|
+
|
|
287
|
+
<details>
|
|
288
|
+
<summary><b>Can I use it to backtest a strategy?</b></summary>
|
|
289
|
+
<br>
|
|
290
|
+
|
|
291
|
+
Yes. `strategy()` scripts run against a broker emulator that models order
|
|
292
|
+
timing, fill prices, gaps, tick rounding and brackets the way TradingView's
|
|
293
|
+
does — each of those rules measured against TradingView's own backtest output
|
|
294
|
+
rather than assumed.
|
|
295
|
+
</details>
|
|
296
|
+
|
|
297
|
+
<details>
|
|
298
|
+
<summary><b>Is it a Pine Script interpreter or a compiler?</b></summary>
|
|
299
|
+
<br>
|
|
300
|
+
|
|
301
|
+
A compiler. Pine source is parsed by an ANTLR-generated parser into a syntax
|
|
302
|
+
tree, and a version-specific visitor emits JavaScript, which is then executed
|
|
303
|
+
bar by bar against a runtime that provides the standard library.
|
|
304
|
+
</details>
|
|
305
|
+
|
|
306
|
+
<details>
|
|
307
|
+
<summary><b>How do I convert Pine Script to JavaScript?</b></summary>
|
|
308
|
+
<br>
|
|
309
|
+
|
|
310
|
+
`npm run opsv2 -- script.pine --emit-js out.js`, or call `compileScript(src)`
|
|
311
|
+
from `transpiler/common` to get the emitted source back as a string.
|
|
312
|
+
</details>
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## 🤝 Contributing
|
|
317
|
+
|
|
318
|
+
The core is developed by a single author and pull requests are not being
|
|
319
|
+
accepted, but **bug reports and feature requests drive the roadmap**. See
|
|
320
|
+
[CONTRIBUTING.md](CONTRIBUTING.md), the [Code of Conduct](CODE_OF_CONDUCT.md),
|
|
321
|
+
and the [Security Policy](SECURITY.md).
|
|
322
|
+
|
|
323
|
+
Writing a golden-data harness is the single highest-value contribution to the
|
|
324
|
+
project — the [recipe is here](conformance/common/golden.md).
|
|
325
|
+
|
|
326
|
+
## 📄 License
|
|
327
|
+
|
|
328
|
+
GNU GPL-3.0. See [LICENSE](LICENSE).
|
|
329
|
+
|
|
330
|
+
The Pine Script language and TradingView are trademarks of TradingView, Inc.
|
|
331
|
+
This project is not affiliated with or endorsed by TradingView. The examples in
|
|
332
|
+
[`examples/<version>/tradingview-docs/`](examples/common/tradingview-docs/README.md)
|
|
333
|
+
are © TradingView, reproduced verbatim for interoperability testing and not
|
|
334
|
+
covered by the licence above.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
<div align="center">
|
|
339
|
+
|
|
340
|
+
**If this saved you a TradingView quota, a ⭐ helps others find it.**
|
|
341
|
+
|
|
342
|
+
<sub>Keywords: Pine Script, TradingView, Pine Script v5, Pine Script v4, Pine Script compiler,
|
|
343
|
+
Pine Script interpreter, Pine to JavaScript, run Pine Script locally, offline backtesting,
|
|
344
|
+
Pine Script backtest, algorithmic trading, technical analysis library, ANTLR, TypeScript,
|
|
345
|
+
open source trading, trading indicator engine.</sub>
|
|
346
|
+
|
|
347
|
+
</div>
|