PineScript Demo

This demo loads and execute native pine script from this file cross-signal.pine, then uses PineTS to execute it and get the results.
The results are then used by QFChart to render the chart.


Loading Data ...

About This Demo - Native Pine Script Execution

What is Pine Script?

Pine Script is TradingView's proprietary scripting language designed for creating custom technical indicators and trading strategies. It provides a simple, intuitive syntax that allows traders to express complex mathematical calculations and conditional logic without needing extensive programming knowledge. Pine Script is widely used by millions of traders worldwide to build, test, and deploy custom trading tools.

PineTS: Pine Script Runtime for JavaScript

PineTS is a groundbreaking JavaScript/TypeScript library that brings Pine Script execution to the web.
PineTS is a runtime transpiler that executes Pine Script code directly in the browser or Node.js environment.
This demo showcases PineTS's ability to:

The Cross Signal Indicator

This demo executes a Cross Signal indicator written in pure Pine Script. The indicator detects when a fast moving average crosses above or below a slow moving average, generating buy and sell signals. Key features:

How This Demo Works

The execution flow demonstrates the full PineTS + QFChart integration:

  1. Load Pine Script - Fetch the cross-signal.pine file via HTTP
  2. Initialize PineTS - Create a PineTS instance with market data provider (Binance)
  3. Execute Script - PineTS transpiles and runs the Pine Script on 500 weekly BTC/USDT candles
  4. Extract Results - Get calculated indicator values and plot data
  5. Initialize QFChart - Create a chart instance with the market data
  6. Render Indicator - Add the Cross Signal plots as an overlay on the price chart

Technical Implementation

Behind the scenes, this demo showcases advanced capabilities:

Benefits of Native Pine Script Execution

Sample Pine Script Code

Here's a simplified version of what the Cross Signal indicator looks like:

//@version=5
indicator("Cross Signal", overlay=true)

// Input parameters
fastLength = input.int(9, "Fast MA Length")
slowLength = input.int(21, "Slow MA Length")

// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)

// Detect crossovers
bullCross = ta.crossover(fastMA, slowMA)
bearCross = ta.crossunder(fastMA, slowMA)

// Plot MAs
plot(fastMA, "Fast MA", color.blue)
plot(slowMA, "Slow MA", color.red)

// Plot signals
plotshape(bullCross, "Buy", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(bearCross, "Sell", shape.triangledown, location.abovebar, color.red, size=size.small)

Use Cases

Getting Started

To execute your own Pine Script files:

// Load Pine Script source
const response = await fetch('your-indicator.pine');
const pineScript = await response.text();

// Execute with PineTS
const pineTS = new PineTS(PineTS.Provider.Binance, 'BTCUSDT', '1d', 500);
const { result, plots, marketData } = await pineTS.run(pineScript);

// Visualize with QFChart
const chart = new QFChart.QFChart(container, { title: 'My Indicator' });
chart.setMarketData(marketData);
chart.addIndicator('My Indicator', plots, { isOverlay: true });

Learn More