pinets 0.6.1 → 0.7.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/README.md +146 -75
- package/dist/pinets.min.browser.es.js +117 -0
- package/dist/pinets.min.browser.es.js.map +1 -0
- package/dist/pinets.min.browser.js +96 -16
- package/dist/pinets.min.browser.js.map +1 -0
- package/dist/pinets.min.cjs +96 -15
- package/dist/pinets.min.cjs.map +1 -0
- package/dist/pinets.min.es.js +99 -5
- package/dist/pinets.min.es.js.map +1 -0
- package/dist/types/Context.class.d.ts +3 -25
- package/dist/types/namespaces/Core.d.ts +8 -3
- package/dist/types/namespaces/Plot.helper.d.ts +16 -0
- package/dist/types/namespaces/Plots.d.ts +16 -0
- package/dist/types/namespaces/Types.d.ts +1 -1
- package/dist/types/namespaces/input/utils.d.ts +2 -14
- package/dist/types/namespaces/ta/methods/pivothigh.d.ts +1 -1
- package/dist/types/namespaces/ta/methods/pivotlow.d.ts +1 -1
- package/dist/types/namespaces/utils.d.ts +12 -0
- package/dist/types/transpiler/index.d.ts +1 -1
- package/dist/types/transpiler/pineToJS/ast.d.ts +167 -0
- package/dist/types/transpiler/pineToJS/codegen.d.ts +53 -0
- package/dist/types/transpiler/pineToJS/lexer.d.ts +31 -0
- package/dist/types/transpiler/pineToJS/parser.d.ts +45 -0
- package/dist/types/transpiler/pineToJS/pineToJS.index.d.ts +32 -0
- package/dist/types/transpiler/pineToJS/tokens.d.ts +34 -0
- package/dist/types/transpiler/settings.d.ts +2 -0
- package/dist/types/transpiler/transformers/WrapperTransformer.d.ts +5 -3
- package/dist/types/transpiler/utils/ASTFactory.d.ts +1 -0
- package/dist/types/types/PineTypes.d.ts +19 -15
- package/package.json +24 -5
- package/dist/pinets.dev.browser.js +0 -16515
- package/dist/pinets.dev.cjs +0 -16765
- package/dist/pinets.dev.cjs.map +0 -1
- package/dist/pinets.dev.es.js +0 -9125
- package/dist/pinets.dev.es.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,60 +6,23 @@
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
The current version does not run Pine Script directly, instead it runs a close Javascript equivalent called PineTS.
|
|
9
|
+
**PineTS** is a JavaScript/TypeScript runtime that enables execution of Pine Script indicators in JavaScript environments. It supports two input formats:
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
1. **Native Pine Script v5/v6** _(experimental)_ - Run original Pine Script code directly
|
|
12
|
+
2. **PineTS Syntax** - A JavaScript/TypeScript syntax that closely mirrors Pine Script
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Pine Script API Coverage
|
|
19
|
-
|
|
20
|
-
### Data
|
|
21
|
-
|
|
22
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/syminfo.html)
|
|
23
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/session.html)
|
|
24
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/timeframe.html)
|
|
25
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/barstate.html)
|
|
26
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/ticker.html)
|
|
27
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/builtin.html)
|
|
28
|
-
|
|
29
|
-
### Calculation
|
|
14
|
+
This makes it possible to run Pine Script indicators in Node.js, browsers, and other JavaScript runtimes without modification or with minimal conversion effort.
|
|
30
15
|
|
|
31
|
-
|
|
32
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/math.html)
|
|
33
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/array.html)
|
|
34
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/map.html)
|
|
35
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/matrix.html)
|
|
36
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/request.html)
|
|
37
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/types.html)
|
|
38
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/strategy.html)
|
|
39
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/input.html)
|
|
40
|
-
|
|
41
|
-
### Visualization
|
|
42
|
-
|
|
43
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/color.html)
|
|
44
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/plots.html)
|
|
45
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/chart.html)
|
|
46
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/label.html)
|
|
47
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/line.html)
|
|
48
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/polyline.html)
|
|
49
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/box.html)
|
|
50
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/table.html)
|
|
51
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/linefill.html)
|
|
52
|
-
|
|
53
|
-
### Logging
|
|
16
|
+
> _Disclaimer : PineTS is an independent project and is not affiliated with, endorsed by, or associated with TradingView or Pine Script™. All trademarks and registered trademarks mentioned belong to their respective owners._
|
|
54
17
|
|
|
55
|
-
|
|
56
|
-
[](https://quantforgeorg.github.io/PineTS/api-coverage/str.html)
|
|
18
|
+
## Overview
|
|
57
19
|
|
|
58
|
-
|
|
20
|
+
PineTS is a sophisticated runtime transpiler that converts Pine Script (or PineTS syntax) into executable JavaScript. It preserves the original functionality and behavior while providing robust handling of time-series data processing, technical analysis calculations, and Pine Script's distinctive scoping mechanisms.
|
|
59
21
|
|
|
60
|
-
|
|
22
|
+
### Input Format Support
|
|
61
23
|
|
|
62
|
-
|
|
24
|
+
- **Native Pine Script** _(v0.7.0+, experimental)_: Run original Pine Script v5 and v6 indicators directly. Note that some indicators may fail if they use Pine Script API features not yet implemented in PineTS. Check the [API coverage badges](#pine-script-api-coverage) below to verify compatibility.
|
|
25
|
+
- **PineTS Syntax**: A JavaScript/TypeScript syntax that mirrors Pine Script closely, requiring minimal conversion effort from original Pine Script code.
|
|
63
26
|
|
|
64
27
|
## See it in action
|
|
65
28
|
|
|
@@ -71,14 +34,15 @@ PineTS is used to generate plot data, and tradingview light weight chart is used
|
|
|
71
34
|
|
|
72
35
|
## Key Features
|
|
73
36
|
|
|
74
|
-
- **Pine Script
|
|
37
|
+
- **Native Pine Script Support**: Run original Pine Script v5/v6 code directly _(experimental)_
|
|
38
|
+
- **Dual Input Format**: Support for both native Pine Script and PineTS syntax
|
|
75
39
|
- **High Precision**: Aims for the same precision as Pine Script (up to the 8th digit)
|
|
76
40
|
- **Time-Series Processing**: Handles historical data and series operations
|
|
77
|
-
- **Technical Analysis Functions**: Comprehensive set of TA indicators and calculations
|
|
41
|
+
- **Technical Analysis Functions**: Comprehensive set of 60+ TA indicators and calculations
|
|
78
42
|
- **Mathematical Operations**: Advanced mathematical functions and precision handling
|
|
79
43
|
- **Input Management**: Flexible parameter and input handling system
|
|
80
44
|
- **Context Management**: Maintains proper scoping and variable access rules
|
|
81
|
-
- **Runtime Transpilation**: Converts
|
|
45
|
+
- **Runtime Transpilation**: Converts code to executable JavaScript at runtime without pre-compilation
|
|
82
46
|
|
|
83
47
|
## Core Components
|
|
84
48
|
|
|
@@ -105,9 +69,44 @@ The main class that handles:
|
|
|
105
69
|
npm install pinets
|
|
106
70
|
```
|
|
107
71
|
|
|
108
|
-
## Usage
|
|
72
|
+
## Usage Examples
|
|
73
|
+
|
|
74
|
+
### Option 1: Run Native Pine Script Directly _(Experimental)_
|
|
75
|
+
|
|
76
|
+
Starting with v0.7.0, you can run original Pine Script code directly:
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
import { PineTS, Provider } from 'pinets';
|
|
80
|
+
|
|
81
|
+
// Initialize with market data
|
|
82
|
+
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', 'D', 100);
|
|
83
|
+
|
|
84
|
+
// Run native Pine Script directly
|
|
85
|
+
const pineScriptCode = `
|
|
86
|
+
//@version=5
|
|
87
|
+
indicator('My EMA Cross Strategy')
|
|
88
|
+
|
|
89
|
+
ema9 = ta.ema(close, 9)
|
|
90
|
+
ema18 = ta.ema(close, 18)
|
|
91
|
+
|
|
92
|
+
bull_bias = ema9 > ema18
|
|
93
|
+
bear_bias = ema9 < ema18
|
|
94
|
+
|
|
95
|
+
plot(ema9, title = '9 EMA', color = color.yellow)
|
|
96
|
+
plot(ema18, title = '18 EMA', color = color.red)
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
const { result, plots } = await pineTS.run(pineScriptCode);
|
|
100
|
+
// Access results: result.ema9, result.ema18, result.bull_bias, result.bear_bias
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> **⚠️ Note**: Native Pine Script support is experimental. Some indicators may fail if they use API features not yet implemented. Refer to the [API coverage badges](#pine-script-api-coverage) to check compatibility.
|
|
104
|
+
|
|
105
|
+
### Option 2: Use PineTS Syntax
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
PineTS syntax is a JavaScript/TypeScript version of Pine Script with minimal differences:
|
|
108
|
+
|
|
109
|
+
#### Converting Pine Script to PineTS
|
|
111
110
|
|
|
112
111
|
Original Pine Script:
|
|
113
112
|
|
|
@@ -115,7 +114,7 @@ Original Pine Script:
|
|
|
115
114
|
<tr>
|
|
116
115
|
<td>
|
|
117
116
|
|
|
118
|
-
```
|
|
117
|
+
```pinescript
|
|
119
118
|
/*==[ Original Pine Script ]==*/
|
|
120
119
|
|
|
121
120
|
//@version=5
|
|
@@ -132,6 +131,10 @@ diff_close = close - prev_close;
|
|
|
132
131
|
|
|
133
132
|
_oo = open;
|
|
134
133
|
_oo = math.abs(open[1] - close[2]);
|
|
134
|
+
|
|
135
|
+
// plot ema's
|
|
136
|
+
plot(ema9, title = '9 EMA', color = color.yellow)
|
|
137
|
+
plot(ema18, title = '18 EMA', color = color.red)
|
|
135
138
|
```
|
|
136
139
|
|
|
137
140
|
</td>
|
|
@@ -141,7 +144,7 @@ _oo = math.abs(open[1] - close[2]);
|
|
|
141
144
|
/*==[ Equivalent PineTS ]==*/
|
|
142
145
|
|
|
143
146
|
//
|
|
144
|
-
|
|
147
|
+
indicator('My EMA Cross Strategy');
|
|
145
148
|
|
|
146
149
|
let ema9 = ta.ema(close, 9);
|
|
147
150
|
let ema18 = ta.ema(close, 18);
|
|
@@ -154,6 +157,10 @@ let diff_close = close - prev_close;
|
|
|
154
157
|
|
|
155
158
|
let _oo = open;
|
|
156
159
|
_oo = math.abs(open[1] - close[2]);
|
|
160
|
+
|
|
161
|
+
// plot ema's
|
|
162
|
+
plot(ema9, { title: '9 EMA', color: color.yellow });
|
|
163
|
+
plot(ema18, { title: '18 EMA', color: color.red });
|
|
157
164
|
```
|
|
158
165
|
|
|
159
166
|
</td>
|
|
@@ -191,38 +198,102 @@ const { result } = await pineTS.run((context) => {
|
|
|
191
198
|
|
|
192
199
|
> **📖 For detailed documentation on initialization options, parameters, and advanced usage, see the [Initialization and Usage Guide](https://quantforgeorg.github.io/PineTS/initialization-and-usage/)**
|
|
193
200
|
|
|
194
|
-
## Key Differences
|
|
201
|
+
## Key Differences: PineTS Syntax vs Native Pine Script
|
|
202
|
+
|
|
203
|
+
When using **PineTS syntax** (not native Pine Script), note these differences:
|
|
195
204
|
|
|
196
205
|
1. **Variable Declaration**: Use JavaScript's `const`, `let`, and `var` instead of Pine Script's implicit declaration
|
|
197
206
|
2. **Function Syntax**: JavaScript arrow functions and standard function syntax
|
|
198
|
-
3. **Module System**: Pine Script
|
|
199
|
-
4. **
|
|
200
|
-
5. **
|
|
207
|
+
3. **Module System**: Import Pine Script namespaces from context: `const { ta } = context; const { close, open } = context.data;`
|
|
208
|
+
4. **Object Syntax**: Use JavaScript object notation for parameters: `plot(ema9, { title: '9 EMA', color: color.yellow })`
|
|
209
|
+
5. **Scoping Rules**: Maintains Pine Script's series behavior through runtime transformation
|
|
210
|
+
6. **Return Syntax**: Can return an object with indicator results for easy access in JavaScript
|
|
211
|
+
|
|
212
|
+
When using **Native Pine Script**, write code exactly as you would in TradingView - no conversion needed!
|
|
201
213
|
|
|
202
214
|
## Project Goals
|
|
203
215
|
|
|
204
|
-
PineTS aims for **full coverage** of Pine Script functions and capabilities
|
|
216
|
+
PineTS aims for **full coverage** of Pine Script functions and capabilities to enable seamless execution of Pine Script indicators in JavaScript environments.
|
|
205
217
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
218
|
+
**Current Status (v0.7.0)**:
|
|
219
|
+
|
|
220
|
+
- ✅ **Native Pine Script Support (Experimental)**: Run original Pine Script v5/v6 code directly
|
|
221
|
+
- ✅ **PineTS Runtime Transpiler**: Convert PineTS syntax to executable JavaScript
|
|
222
|
+
- ✅ **Core Pine Script API**: ~75% coverage of built-in functions and variables
|
|
223
|
+
- ✅ **Series and Scope Management**: Full Pine Script semantics preserved
|
|
224
|
+
- ✅ **Technical Analysis**: 60+ indicators and analysis functions
|
|
225
|
+
- ✅ **Mathematical Operations**: Comprehensive math functions
|
|
226
|
+
- ✅ **Data Structures**: Arrays and Matrices (90+ operations)
|
|
227
|
+
- ✅ **Input System**: Dynamic parameter handling
|
|
228
|
+
- ✅ **Plot Data Management**: Multi-series plotting support
|
|
229
|
+
- ✅ **Real-time Execution**: Live data processing capability
|
|
230
|
+
- ✔️🚧 **Market Data Providers**: Binance supported (more coming soon)
|
|
231
|
+
- ✅ **Visualization**: Interactive charting ==> handled in [QFChart](https://github.com/QuantForgeOrg/QFChart)
|
|
232
|
+
- 🚧 **Caching System**: Script and market data optimization (in progress)
|
|
233
|
+
- 🎯 **Strategy Execution**: Backtesting and live trading (planned)
|
|
234
|
+
|
|
235
|
+
> **⚠️ API Coverage**: While PineTS supports native Pine Script execution, not all Pine Script API features are implemented yet. Check the [API coverage badges](#pine-script-api-coverage) below to verify if specific functions are available. Indicators using unimplemented features will fail with descriptive error messages.
|
|
217
236
|
|
|
218
237
|
## Technical Details
|
|
219
238
|
|
|
220
|
-
The library uses a
|
|
239
|
+
The library uses a dual-layer transpilation system:
|
|
240
|
+
|
|
241
|
+
### Pine Script Parser _(v0.7.0+, Experimental)_
|
|
242
|
+
|
|
243
|
+
- Automatically detects Pine Script v5 and v6 code
|
|
244
|
+
- Converts native Pine Script syntax to PineTS intermediate representation
|
|
245
|
+
- Preserves Pine Script semantics and behavior
|
|
246
|
+
|
|
247
|
+
### Runtime Transpiler
|
|
248
|
+
|
|
249
|
+
- Transforms PineTS source (or converted Pine Script) to handle time-series data
|
|
250
|
+
- Manages variable scoping and context
|
|
251
|
+
- Handles array indexing and series operations
|
|
252
|
+
- Provides Pine Script-compatible function calls
|
|
253
|
+
- Executes in real-time without pre-compilation
|
|
254
|
+
==> The resulting code is a low level javascript that allows handling the complex structures and specificities of PineScript
|
|
255
|
+
|
|
256
|
+
### Pine Script API Coverage
|
|
257
|
+
|
|
258
|
+
#### Data
|
|
259
|
+
|
|
260
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/syminfo.html)
|
|
261
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/session.html)
|
|
262
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/timeframe.html)
|
|
263
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/barstate.html)
|
|
264
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/ticker.html)
|
|
265
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/builtin.html)
|
|
266
|
+
|
|
267
|
+
#### Calculation
|
|
221
268
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
269
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/ta.html)
|
|
270
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/math.html)
|
|
271
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/array.html)
|
|
272
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/map.html)
|
|
273
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/matrix.html)
|
|
274
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/request.html)
|
|
275
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/types.html)
|
|
276
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/strategy.html)
|
|
277
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/input.html)
|
|
278
|
+
|
|
279
|
+
#### Visualization
|
|
280
|
+
|
|
281
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/color.html)
|
|
282
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/plots.html)
|
|
283
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/chart.html)
|
|
284
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/label.html)
|
|
285
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/line.html)
|
|
286
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/polyline.html)
|
|
287
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/box.html)
|
|
288
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/table.html)
|
|
289
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/linefill.html)
|
|
290
|
+
|
|
291
|
+
#### Logging
|
|
292
|
+
|
|
293
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/log.html)
|
|
294
|
+
[](https://quantforgeorg.github.io/PineTS/api-coverage/str.html)
|
|
295
|
+
|
|
296
|
+
---
|
|
226
297
|
|
|
227
298
|
## Contributing
|
|
228
299
|
|