pinets 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/README.md ADDED
@@ -0,0 +1,158 @@
1
+ This project aims to provide a Javascript/Typescript port for Tradingview's Pine Script.
2
+ The current version does not run Pine Script directly, instead it runs a close Javascript equivalent called PineTS.
3
+
4
+ PineTS makes it possible to migrate Pine Script v5+ indicators to Javascript/Typescript, in order to run them in a Javascript environment.
5
+
6
+ ## Disclaimer
7
+
8
+ 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.
9
+
10
+ ## Overview
11
+
12
+ 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.
13
+
14
+ ## Key Features
15
+
16
+ - **Pine Script Compatibility**: Supports Pine Script v5+ syntax and functionality
17
+ - **Time-Series Processing**: Handles historical data and series operations
18
+ - **Technical Analysis Functions**: Comprehensive set of TA indicators and calculations
19
+ - **Mathematical Operations**: Advanced mathematical functions and precision handling
20
+ - **Input Management**: Flexible parameter and input handling system
21
+ - **Context Management**: Maintains proper scoping and variable access rules
22
+ - **Runtime Transpilation**: Converts PineTS code to executable JavaScript at runtime
23
+
24
+ ## Core Components
25
+
26
+ ### PineTS Class
27
+
28
+ The main class that handles:
29
+
30
+ - Market data management
31
+ - Series calculations
32
+ - Built-in variables (open, high, low, close, volume, etc.)
33
+ - Runtime execution context
34
+
35
+ ### Namespaces
36
+
37
+ - **Core**: Essential Pine Script functionality and base operations
38
+ - **TechnicalAnalysis**: Comprehensive set of technical indicators and analysis functions
39
+ - **PineMath**: Mathematical operations and precision handling
40
+ - **Input**: Parameter and input management system
41
+ - **Syminfo**: Symbol information and market data helpers
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ npm install github:alaa-eddine/PineTS
47
+ ```
48
+
49
+ ## Usage Example
50
+
51
+ ### Converting Pine Script to PineTS
52
+
53
+ Original Pine Script:
54
+
55
+ ```javascript
56
+ //@version=5
57
+ indicator('My EMA Cross Strategy');
58
+
59
+ ema9 = ta.ema(close, 9);
60
+ ema18 = ta.ema(close, 18);
61
+
62
+ bull_bias = ema9 > ema18;
63
+ bear_bias = ema9 < ema18;
64
+
65
+ prev_close = close[1];
66
+ diff_close = close - prev_close;
67
+
68
+ _oo = open;
69
+ _oo = math.abs(open[1] - close[2]);
70
+ ```
71
+
72
+ Equivalent PineTS code:
73
+
74
+ ```javascript
75
+ const ema9 = ta.ema(close, 9);
76
+ const ema18 = ta.ema(close, 18);
77
+
78
+ const bull_bias = ema9 > ema18;
79
+ const bear_bias = ema9 < ema18;
80
+
81
+ const prev_close = close[1];
82
+ const diff_close = close - prev_close;
83
+
84
+ let _oo = open;
85
+ _oo = math.abs(open[1] - close[2]);
86
+ ```
87
+
88
+ ### Running PineTS Code
89
+
90
+ ```javascript
91
+ import { PineTS, Providers } from 'pinets';
92
+
93
+ // Initialize with market data
94
+
95
+ const pineTS = new PineTS(Providers.Binance, 'BTCUSDT', 'D', 100);
96
+
97
+ // Run your indicator
98
+ const { result } = await pineTS.run((context) => {
99
+ const ta = context.ta;
100
+ const math = context.math;
101
+ const { close, open } = context.data;
102
+
103
+ const ema9 = ta.ema(close, 9);
104
+ const ema18 = ta.ema(close, 18);
105
+
106
+ const bull_bias = ema9 > ema18;
107
+ const bear_bias = ema9 < ema18;
108
+
109
+ const prev_close = close[1];
110
+ const diff_close = close - prev_close;
111
+
112
+ let _oo = open;
113
+ _oo = math.abs(open[1] - close[2]);
114
+ });
115
+ ```
116
+
117
+ ## Key Differences from Pine Script
118
+
119
+ 1. **Variable Declaration**: Use JavaScript's `const`, `let`, and `var` instead of Pine Script's implicit declaration
120
+ 2. **Function Syntax**: JavaScript arrow functions and standard function syntax
121
+ 3. **Module System**: Pine Script native types should be imported using syntax like : const ta = context.ta; const {close, open} = context.data;
122
+ 4. **Scoping Rules**: Maintains Pine Script's series behavior through runtime transformation
123
+ 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.
124
+
125
+ ## Project Goals
126
+
127
+ - Runtime Transpiler
128
+ - Core Pine Script functions and variables
129
+ - Series and scope management
130
+ - Technical analysis functions
131
+ - Mathematical functions
132
+ - Input handling
133
+ - Plots data handling
134
+ - Market data connectors
135
+ - Visualization add-ons
136
+ - Strategy execution
137
+ - Backtesting and simulation
138
+
139
+ ## Technical Details
140
+
141
+ The library uses a runtime transpiler that:
142
+
143
+ 1. Transforms PineTS code to handle time-series data
144
+ 2. Manages variable scoping and context
145
+ 3. Handles array indexing and series operations
146
+ 4. Provides Pine Script-compatible function calls
147
+
148
+ ## Contributing
149
+
150
+ Contributions are welcome! Please feel free to submit pull requests, create issues, or suggest improvements.
151
+
152
+ ## License
153
+
154
+ This project is open-source and available under the AGPL License.
155
+
156
+ ## Disclaimer
157
+
158
+ 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.