Skip to content

Commit adeae2c

Browse files
committed
documentation update
1 parent 23e5d0d commit adeae2c

File tree

1 file changed

+63
-13
lines changed

1 file changed

+63
-13
lines changed

docs/getting-started.md

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,62 @@ permalink: /getting-started/
77

88
# Getting Started with PineTS
99

10-
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.
10+
PineTS is a JavaScript/TypeScript runtime that enables execution of Pine Script indicators in JavaScript environments. It supports two input formats:
11+
12+
1. **Native Pine Script v5/v6** _(experimental)_ - Run original Pine Script code directly
13+
2. **PineTS Syntax** - A JavaScript/TypeScript syntax that closely mirrors Pine Script
14+
15+
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.
1116

1217
## Installation
1318

1419
```bash
1520
npm install pinets
1621
```
1722

18-
## Usage Example
23+
## Usage Examples
24+
25+
### Option 1: Run Native Pine Script Directly _(Experimental)_
26+
27+
Starting with v0.7.0, you can run original Pine Script code directly without conversion:
28+
29+
```javascript
30+
import { PineTS, Provider } from 'pinets';
31+
32+
// Initialize with market data
33+
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', 'D', 100);
34+
35+
// Run native Pine Script directly - no conversion needed!
36+
const pineScriptCode = `
37+
//@version=5
38+
indicator('My EMA Cross Strategy')
39+
40+
ema9 = ta.ema(close, 9)
41+
ema18 = ta.ema(close, 18)
42+
43+
bull_bias = ema9 > ema18
44+
bear_bias = ema9 < ema18
1945
20-
### Converting Pine Script to PineTS
46+
prev_close = close[1]
47+
diff_close = close - prev_close
48+
49+
plot(ema9, title = '9 EMA', color = color.yellow)
50+
plot(ema18, title = '18 EMA', color = color.red)
51+
`;
52+
53+
const { result, plots } = await pineTS.run(pineScriptCode);
54+
// Access results: result.ema9, result.ema18, result.bull_bias, result.bear_bias
55+
```
56+
57+
> **⚠️ Note**: Native Pine Script support is experimental. Some indicators may fail if they use API features not yet implemented. Check the [API Coverage](../api-coverage/) pages to verify compatibility.
58+
59+
---
60+
61+
### Option 2: Use PineTS Syntax
62+
63+
If you prefer or need more control, you can use PineTS syntax, which is a JavaScript/TypeScript version with minimal differences from Pine Script.
64+
65+
#### Converting Pine Script to PineTS
2166

2267
Original Pine Script:
2368

@@ -38,7 +83,7 @@ _oo = open;
3883
_oo = math.abs(open[1] - close[2]);
3984
```
4085

41-
Equivalent PineTS code:
86+
Equivalent PineTS syntax:
4287

4388
```javascript
4489
const ema9 = ta.ema(close, 9);
@@ -54,13 +99,13 @@ let _oo = open;
5499
_oo = math.abs(open[1] - close[2]);
55100
```
56101

57-
### Running PineTS Code
102+
#### Running PineTS Syntax Code
58103

59104
```javascript
60-
import { PineTS, Providers } from 'pinets';
105+
import { PineTS, Provider } from 'pinets';
61106

62107
// Initialize with market data
63-
const pineTS = new PineTS(Providers.Binance, 'BTCUSDT', 'D', 100);
108+
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', 'D', 100);
64109

65110
// Run your indicator
66111
const { result } = await pineTS.run((context) => {
@@ -87,10 +132,10 @@ const { result } = await pineTS.run((context) => {
87132
For processing large datasets efficiently or streaming live market data, use pagination:
88133

89134
```javascript
90-
import { PineTS, Providers } from 'pinets';
135+
import { PineTS, Provider } from 'pinets';
91136

92137
// Initialize with a provider for live streaming capability
93-
const pineTS = new PineTS(Providers.Binance, 'BTCUSDT', '1h');
138+
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', '1h');
94139

95140
// Process 200 candles in pages of 50
96141
const iterator = pineTS.run(
@@ -121,13 +166,18 @@ for await (const page of iterator) {
121166

122167
📖 **For complete pagination documentation and advanced examples, see [Pagination & Live Streaming](../pagination/).**
123168

124-
## Key Differences from Pine Script
169+
## Key Differences: PineTS Syntax vs Native Pine Script
170+
171+
When using **PineTS syntax** (Option 2), note these differences from native Pine Script:
125172

126173
1. **Variable Declaration**: Use JavaScript's `const`, `let`, and `var` instead of Pine Script's implicit declaration
127174
2. **Function Syntax**: JavaScript arrow functions and standard function syntax
128-
3. **Module System**: Pine Script native types should be imported using syntax like: `const ta = context.ta; const {close, open} = context.data;`
129-
4. **Scoping Rules**: Maintains Pine Script's series behavior through runtime transformation
130-
5. **Return syntax**: PineTS can return an object with the results of the indicator, allowing you to get the results of the indicator in a single call.
175+
3. **Module System**: Import Pine Script namespaces from context: `const { ta, math } = context; const { close, open } = context.data;`
176+
4. **Object Syntax**: Use JavaScript object notation for parameters: `plot(value, { title: 'My Plot', color: color.yellow })`
177+
5. **Scoping Rules**: Maintains Pine Script's series behavior through runtime transformation
178+
6. **Return Syntax**: Can return an object with indicator results for easy access in JavaScript
179+
180+
When using **Native Pine Script** (Option 1), write code exactly as you would in TradingView - no conversion needed!
131181

132182
## Core Components
133183

0 commit comments

Comments
 (0)