pinets 0.6.1 → 0.7.1

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.
Files changed (35) hide show
  1. package/README.md +146 -75
  2. package/dist/pinets.min.browser.es.js +117 -0
  3. package/dist/pinets.min.browser.es.js.map +1 -0
  4. package/dist/pinets.min.browser.js +96 -16
  5. package/dist/pinets.min.browser.js.map +1 -0
  6. package/dist/pinets.min.cjs +96 -15
  7. package/dist/pinets.min.cjs.map +1 -0
  8. package/dist/pinets.min.es.js +99 -5
  9. package/dist/pinets.min.es.js.map +1 -0
  10. package/dist/types/Context.class.d.ts +3 -25
  11. package/dist/types/namespaces/Core.d.ts +8 -3
  12. package/dist/types/namespaces/Plot.helper.d.ts +16 -0
  13. package/dist/types/namespaces/Plots.d.ts +16 -0
  14. package/dist/types/namespaces/Types.d.ts +1 -1
  15. package/dist/types/namespaces/input/utils.d.ts +2 -14
  16. package/dist/types/namespaces/ta/methods/pivothigh.d.ts +1 -1
  17. package/dist/types/namespaces/ta/methods/pivotlow.d.ts +1 -1
  18. package/dist/types/namespaces/utils.d.ts +12 -0
  19. package/dist/types/transpiler/index.d.ts +1 -1
  20. package/dist/types/transpiler/pineToJS/ast.d.ts +167 -0
  21. package/dist/types/transpiler/pineToJS/codegen.d.ts +53 -0
  22. package/dist/types/transpiler/pineToJS/lexer.d.ts +31 -0
  23. package/dist/types/transpiler/pineToJS/parser.d.ts +45 -0
  24. package/dist/types/transpiler/pineToJS/pineToJS.index.d.ts +32 -0
  25. package/dist/types/transpiler/pineToJS/tokens.d.ts +34 -0
  26. package/dist/types/transpiler/settings.d.ts +2 -0
  27. package/dist/types/transpiler/transformers/WrapperTransformer.d.ts +5 -3
  28. package/dist/types/transpiler/utils/ASTFactory.d.ts +1 -0
  29. package/dist/types/types/PineTypes.d.ts +19 -15
  30. package/package.json +24 -5
  31. package/dist/pinets.dev.browser.js +0 -16515
  32. package/dist/pinets.dev.cjs +0 -16765
  33. package/dist/pinets.dev.cjs.map +0 -1
  34. package/dist/pinets.dev.es.js +0 -9125
  35. package/dist/pinets.dev.es.js.map +0 -1
package/README.md CHANGED
@@ -6,60 +6,23 @@
6
6
 
7
7
  ---
8
8
 
9
- This project aims to provide a Javascript/Typescript port for Tradingview's Pine Script.
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
- PineTS makes it possible to migrate Pine Script v5+ indicators to Javascript/Typescript, in order to run them in a Javascript environment.
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
- > _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._
15
-
16
- ---
17
-
18
- ## Pine Script API Coverage
19
-
20
- ### Data
21
-
22
- [![syminfo](./.github/badges/api-syminfo.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/syminfo.html)
23
- [![session](./.github/badges/api-session.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/session.html)
24
- [![timeframe](./.github/badges/api-timeframe.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/timeframe.html)
25
- [![barstate](./.github/badges/api-barstate.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/barstate.html)
26
- [![ticker](./.github/badges/api-ticker.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/ticker.html)
27
- [![builtin](./.github/badges/api-builtin.svg)](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
- [![ta](./.github/badges/api-ta.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/ta.html)
32
- [![math](./.github/badges/api-math.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/math.html)
33
- [![array](./.github/badges/api-array.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/array.html)
34
- [![map](./.github/badges/api-map.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/map.html)
35
- [![matrix](./.github/badges/api-matrix.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/matrix.html)
36
- [![request](./.github/badges/api-request.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/request.html)
37
- [![types](./.github/badges/api-types.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/types.html)
38
- [![strategy](./.github/badges/api-strategy.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/strategy.html)
39
- [![input](./.github/badges/api-input.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/input.html)
40
-
41
- ### Visualization
42
-
43
- [![color](./.github/badges/api-color.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/color.html)
44
- [![plots](./.github/badges/api-plots.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/plots.html)
45
- [![chart](./.github/badges/api-chart.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/chart.html)
46
- [![label](./.github/badges/api-label.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/label.html)
47
- [![line](./.github/badges/api-line.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/line.html)
48
- [![polyline](./.github/badges/api-polyline.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/polyline.html)
49
- [![box](./.github/badges/api-box.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/box.html)
50
- [![table](./.github/badges/api-table.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/table.html)
51
- [![linefill](./.github/badges/api-linefill.svg)](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
- [![log](./.github/badges/api-log.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/log.html)
56
- [![str](./.github/badges/api-str.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/str.html)
18
+ ## Overview
57
19
 
58
- ---
20
+ PineTS is a 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
- ## Overview
22
+ ### Input Format Support
61
23
 
62
- PineTS enables seamless conversion of Pine Script indicators to JavaScript/TypeScript code. 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.
24
+ - **Native Pine Script** _(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 Compatibility**: Supports Pine Script v5+ syntax and functionality
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 PineTS code to executable JavaScript at runtime
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 Example
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
- ### Converting Pine Script to PineTS
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
- ```javascript
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
- //'My EMA Cross Strategy';
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 from Pine Script
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 native types should be imported using syntax like : const ta = context.ta; const {close, open} = context.data;
199
- 4. **Scoping Rules**: Maintains Pine Script's series behavior through runtime transformation
200
- 5. **Return syntax**: PineTS can returns an object with the results of the indicator, allowing you to get the results of the indicator in a single call.
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. The ultimate goal is to enable running **original Pine Script code directly** without manual conversion to PineTS syntax.
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
- - Runtime Transpiler
207
- - Core Pine Script functions and variables
208
- - Series and scope management
209
- - Technical analysis functions
210
- - Mathematical functions
211
- - Input handling
212
- - Plots data handling
213
- - Market data connectors
214
- - Visualization add-ons
215
- - Strategy execution
216
- - Backtesting and simulation
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 runtime transpiler that:
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
+ [![syminfo](./.github/badges/api-syminfo.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/syminfo.html)
261
+ [![session](./.github/badges/api-session.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/session.html)
262
+ [![timeframe](./.github/badges/api-timeframe.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/timeframe.html)
263
+ [![barstate](./.github/badges/api-barstate.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/barstate.html)
264
+ [![ticker](./.github/badges/api-ticker.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/ticker.html)
265
+ [![builtin](./.github/badges/api-builtin.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/builtin.html)
266
+
267
+ #### Calculation
221
268
 
222
- 1. Transforms PineTS code to handle time-series data
223
- 2. Manages variable scoping and context
224
- 3. Handles array indexing and series operations
225
- 4. Provides Pine Script-compatible function calls
269
+ [![ta](./.github/badges/api-ta.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/ta.html)
270
+ [![math](./.github/badges/api-math.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/math.html)
271
+ [![array](./.github/badges/api-array.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/array.html)
272
+ [![map](./.github/badges/api-map.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/map.html)
273
+ [![matrix](./.github/badges/api-matrix.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/matrix.html)
274
+ [![request](./.github/badges/api-request.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/request.html)
275
+ [![types](./.github/badges/api-types.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/types.html)
276
+ [![strategy](./.github/badges/api-strategy.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/strategy.html)
277
+ [![input](./.github/badges/api-input.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/input.html)
278
+
279
+ #### Visualization
280
+
281
+ [![color](./.github/badges/api-color.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/color.html)
282
+ [![plots](./.github/badges/api-plots.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/plots.html)
283
+ [![chart](./.github/badges/api-chart.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/chart.html)
284
+ [![label](./.github/badges/api-label.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/label.html)
285
+ [![line](./.github/badges/api-line.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/line.html)
286
+ [![polyline](./.github/badges/api-polyline.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/polyline.html)
287
+ [![box](./.github/badges/api-box.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/box.html)
288
+ [![table](./.github/badges/api-table.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/table.html)
289
+ [![linefill](./.github/badges/api-linefill.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/linefill.html)
290
+
291
+ #### Logging
292
+
293
+ [![log](./.github/badges/api-log.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/log.html)
294
+ [![str](./.github/badges/api-str.svg)](https://quantforgeorg.github.io/PineTS/api-coverage/str.html)
295
+
296
+ ---
226
297
 
227
298
  ## Contributing
228
299