PineTS is a JavaScript/TypeScript runtime that enables execution of Pine Script indicators in JavaScript environments. It supports two input formats:
- Native Pine Script v5/v6 (experimental) - Run original Pine Script code directly
- PineTS Syntax - A JavaScript/TypeScript syntax that closely mirrors Pine Script
This makes it possible to run Pine Script indicators in Node.js, browsers, and other JavaScript runtimes without modification or with minimal conversion effort.
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.
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.
- 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 below to verify compatibility.
- PineTS Syntax: A JavaScript/TypeScript syntax that mirrors Pine Script closely, requiring minimal conversion effort from original Pine Script code.
Bellow are two ports of Pine Script indicators running in the browser. PineTS is used to generate plot data, and tradingview light weight chart is used to display the plot.
- Native Pine Script Support: Run original Pine Script v5/v6 code directly (experimental)
- Dual Input Format: Support for both native Pine Script and PineTS syntax
- High Precision: Aims for the same precision as Pine Script (up to the 8th digit)
- Time-Series Processing: Handles historical data and series operations
- Technical Analysis Functions: Comprehensive set of 60+ TA indicators and calculations
- Mathematical Operations: Advanced mathematical functions and precision handling
- Input Management: Flexible parameter and input handling system
- Context Management: Maintains proper scoping and variable access rules
- Runtime Transpilation: Converts code to executable JavaScript at runtime without pre-compilation
The main class that handles:
- Market data management
- Series calculations
- Built-in variables (open, high, low, close, volume, etc.)
- Runtime execution context
- Core: Essential Pine Script functionality and base operations
- TechnicalAnalysis: Comprehensive set of technical indicators and analysis functions
- PineMath: Mathematical operations and precision handling
- Input: Parameter and input management system
- Syminfo: Symbol information and market data helpers
npm install pinetsStarting with v0.7.0, you can run original Pine Script code directly:
import { PineTS, Provider } from 'pinets';
// Initialize with market data
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', 'D', 100);
// Run native Pine Script directly
const pineScriptCode = `
//@version=5
indicator('My EMA Cross Strategy')
ema9 = ta.ema(close, 9)
ema18 = ta.ema(close, 18)
bull_bias = ema9 > ema18
bear_bias = ema9 < ema18
plot(ema9, title = '9 EMA', color = color.yellow)
plot(ema18, title = '18 EMA', color = color.red)
`;
const { plots } = await pineTS.run(pineScriptCode);
//access ema9 and ema18 plots data
β οΈ 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 to check compatibility.
PineTS syntax is a JavaScript/TypeScript version of Pine Script with minimal differences:
Original Pine Script:
|
/*==[ Equivalent PineTS ]==*/
//
indicator('My EMA Cross Strategy');
let ema9 = ta.ema(close, 9);
let ema18 = ta.ema(close, 18);
let bull_bias = ema9 > ema18;
let bear_bias = ema9 < ema18;
let prev_close = close[1];
let diff_close = close - prev_close;
let _oo = open;
_oo = math.abs(open[1] - close[2]);
// plot ema's
plot(ema9, { title: '9 EMA', color: color.yellow });
plot(ema18, { title: '18 EMA', color: color.red }); |
import { PineTS, Provider } from 'pinets';
// Initialize with market data
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', 'D', 100);
// Run your indicator
const { result } = await pineTS.run((context) => {
const { ta, math } = context;
const { close, open } = context.data;
let ema9 = ta.ema(close, 9);
let ema18 = ta.ema(close, 18);
let bull_bias = ema9 > ema18;
let bear_bias = ema9 < ema18;
let prev_close = close[1];
let diff_close = close - prev_close;
let _oo = open;
_oo = math.abs(open[1] - close[2]);
return { ema9, ema18, bull_bias, bear_bias };
});π For detailed documentation on initialization options, parameters, and advanced usage, see the Initialization and Usage Guide
When using PineTS syntax (not native Pine Script), note these differences:
- Variable Declaration: Use JavaScript's
const,let, andvarinstead of Pine Script's implicit declaration - Function Syntax: JavaScript arrow functions and standard function syntax
- Module System: Import Pine Script namespaces from context:
const { ta } = context; const { close, open } = context.data; - Object Syntax: Use JavaScript object notation for parameters:
plot(ema9, { title: '9 EMA', color: color.yellow }) - Scoping Rules: Maintains Pine Script's series behavior through runtime transformation
- Return Syntax: Can return an object with indicator results for easy access in JavaScript
When using Native Pine Script, write code exactly as you would in TradingView - no conversion needed!
PineTS aims for full coverage of Pine Script functions and capabilities to enable seamless execution of Pine Script indicators in JavaScript environments.
Current Status (v0.7.0):
- β Native Pine Script Support (Experimental): Run original Pine Script v5/v6 code directly
- β PineTS Runtime Transpiler: Convert PineTS syntax to executable JavaScript
- β Core Pine Script API: ~75% coverage of built-in functions and variables
- β Series and Scope Management: Full Pine Script semantics preserved
- β Technical Analysis: 60+ indicators and analysis functions
- β Mathematical Operations: Comprehensive math functions
- β Data Structures: Arrays and Matrices (90+ operations)
- β Input System: Dynamic parameter handling
- β Plot Data Management: Multi-series plotting support
- β Real-time Execution: Live data processing capability
- βοΈπ§ Market Data Providers: Binance supported (more coming soon)
- β Visualization: Interactive charting ==> handled in QFChart
- π§ Caching System: Script and market data optimization (in progress)
- π― Strategy Execution: Backtesting and live trading (planned)
β οΈ API Coverage: While PineTS supports native Pine Script execution, not all Pine Script API features are implemented yet. Check the API coverage badges below to verify if specific functions are available. Indicators using unimplemented features will fail with descriptive error messages.
The library uses a dual-layer transpilation system:
- Automatically detects Pine Script v5 and v6 code
- Converts native Pine Script syntax to PineTS intermediate representation
- Preserves Pine Script semantics and behavior
- Transforms PineTS source (or converted Pine Script) to handle time-series data
- Manages variable scoping and context
- Handles array indexing and series operations
- Provides Pine Script-compatible function calls
- Executes in real-time without pre-compilation ==> The resulting code is a low level javascript that allows handling the complex structures and specificities of PineScript
Contributions are welcome! Please feel free to submit pull requests, create issues, or suggest improvements.
This project is open-source and available under the AGPL License.
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.