PineTS

raw JSON →
0.9.13 verified Fri May 01 auth: no javascript

PineTS is an open-source transpiler and runtime that executes Pine Script (TradingView's indicator language) in Node.js, browsers, and other JavaScript runtimes. Version 0.9.13 is the latest stable release, with active development and biweekly releases. Key differentiators include 1:1 syntax compatibility with Pine Script v5, support for multiple data providers (Binance, CSV, custom), and full TypeScript types. Unlike alternatives (e.g., pine-js), PineTS is a full runtime with a built-in transpiler and provider abstraction, enabling off-platform execution of indicators and strategies for backtesting, alerts, and ML pipelines.

error Error: Cannot find module 'pinets'
cause Package not installed or wrong import path.
fix
Run 'npm install pinets' and ensure you're using ESM imports.
error TypeError: Provider.Binance is undefined
cause Provider enum not imported correctly.
fix
Use 'import { Provider } from 'pinets'' and access Provider.Binance.
error SyntaxError: Unexpected token 'export'
cause Using CommonJS require on an ESM-only package.
fix
Switch to ES module syntax or add 'type': 'module' in package.json.
error PineScriptError: line X: ... (Pine script compilation error)
cause Pine Script syntax error (e.g., missing //@version=5).
fix
Check Pine Script code for errors and ensure version pragma is included.
breaking Provider enum changed in v0.8.0: old string-based provider names (e.g., 'binance') no longer accepted. Use Provider.Binance.
fix Replace provider strings with enum values: Provider.Binance, Provider.BinanceFutures, etc.
breaking run() method returns object with `plots` key instead of array since v0.9.0.
fix Access plots via plots['name'] instead of destructuring from array.
deprecated Using require('pinets') is deprecated as of v0.9.0. Package is ESM-only moving forward.
fix Switch to ES module imports: import { PineTS } from 'pinets'.
gotcha Pine Script strings must use backticks or escaped quotes inside JavaScript strings. Template literals work best.
fix Use backticks for multi-line Pine code to avoid escaping issues.
gotcha Data fetched from Binance may have gaps; ensure at least 100 bars for reliable indicator calculations.
fix Request extra bars (e.g., 200) to account for missing data or warmup.
gotcha Plot data is returned as arrays with the same length as the requested bar count; first elements may be NaN due to indicator warmup.
fix Filter out NaN values or slice after warmup period (e.g., plots['SMA 20'].data.slice(20)).
npm install pinets
yarn add pinets
pnpm add pinets

Initializes PineTS with Binance BTCUSDT 1h data and runs a simple EMA cross Pine Script, logging the first 5 values of each plot.

import { PineTS, Provider } from 'pinets';

const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', '1h', 100);

async function main() {
  const { plots } = await pineTS.run(`
    //@version=5
    indicator("EMA Cross")
    plot(ta.ema(close, 9), "Fast", color.blue)
    plot(ta.ema(close, 21), "Slow", color.red)
  `);

  console.log('Fast EMA:', plots['Fast'].data.slice(0, 5));
  console.log('Slow EMA:', plots['Slow'].data.slice(0, 5));
}

main().catch(console.error);