Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt

Use this file to discover all available pages before exploring further.

The @backtest-kit/pinets package lets you run TradingView Pine Script strategies directly inside Node.js using the PineTS runtime. If you have a working TradingView strategy — whether a custom indicator, a breakout system, or a multi-condition entry script — you can load the .pine file directly and use its plot() outputs as trading signals in backtest-kit without rewriting a single line of Pine Script logic. The translation from TradingView to backtest-kit is a mapping step, not a rewrite.

Key Features

Pine Script v5/v6

Native TradingView syntax with 1:1 compatibility via the PineTS runtime. No transpilation, no manual porting.

60+ Built-In Indicators

SMA, EMA, RSI, MACD, Bollinger Bands, ATR, Stochastic, and 53+ more TradingView built-ins are available out of the box.

File or Code Input

Load a .pine file from disk or pass a Pine Script code string directly — whichever fits your workflow.

Plot Extraction

Flexible mapping from Pine plot() and plotshape() outputs to structured backtest-kit signal fields.

Cached Execution

Memoized file reads for repeated strategy runs. The .pine file is read and parsed once, then cached for the duration of the backtest.
@backtest-kit/pinets works inside backtest-kit’s AsyncLocalStorage temporal context. Candle data passed to the Pine Script runtime is always aligned to the current backtest timestamp — look-ahead bias is structurally impossible.

Getting Started

1

Install the package and its peers

npm install @backtest-kit/pinets pinets backtest-kit
2

Place your .pine file in the project

Copy your TradingView .pine file into your project directory, for example:
my-project/
  content/
    my_strategy.pine
  strategy.ts
3

Load the Pine file and extract signals in getSignal

import path from 'path';
import { runPine } from '@backtest-kit/pinets';
import { addStrategySchema, getCandles } from 'backtest-kit';

addStrategySchema({
  strategyName: 'pine-strategy',
  interval: '1h',
  riskName: 'demo',
  getSignal: async (symbol) => {
    // Fetch the candles for this strategy's timeframe
    const candles = await getCandles(symbol, '1h', 200);

    // Run the Pine Script file against the candle data
    const result = await runPine({
      file: path.resolve('./content/my_strategy.pine'),
      candles,
    });

    // Map the Pine plot() outputs to a backtest-kit signal
    // result.plots contains all named plot() values from the script
    const lastBar = result.plots[result.plots.length - 1];

    if (lastBar.longSignal) {
      return {
        position: 'long',
        priceOpen: lastBar.entryPrice,
        priceTakeProfit: lastBar.takeProfit,
        priceStopLoss: lastBar.stopLoss,
      };
    }

    return null;
  },
});

Loading Pine Script from a Code String

If you prefer not to use a file on disk, pass the Pine Script source as a string directly:
import { runPine } from '@backtest-kit/pinets';

const pineCode = `
//@version=5
indicator("My Signal", overlay=true)

fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)

longSignal = ta.crossover(fastMA, slowMA)
plot(longSignal ? 1 : 0, title="Long Signal")
`;

const result = await runPine({
  code: pineCode,
  candles,
});

Supported Built-In Indicators

@backtest-kit/pinets supports all 60+ TradingView built-in functions via PineTS, including:
SMA, EMA, WMA, DEMA, TEMA, RMA, RSI, MACD, Stochastic, Bollinger Bands, ATR, ADX, CCI, DMI, Donchian Channels, Keltner Channels, VWAP, and many more — any function available in Pine Script v5/v6 that does not require a live broker connection works directly.

Use Case: Pine Script Range Breakout

The backtest-kit reference implementation includes a working example that loads a btc_dec2025_range.pine file on 1h candles, extracts Bollinger Band boundaries, range breakout signals, and volume spike confirmations — all wired into a live backtest with full PNL reporting. See the Dec 2025 strategy example for a complete walkthrough.

Build docs developers (and LLMs) love