New Script Modes & Starter Templates
Accelerate your algorithmic development with BacktestX's interactive "New Script" Chooser, built-in Templates menu (including the v1.0.6 pine_ema Direct Pine Script + Logs starter), and native .pine / .pinescript / .js file import & export.
Launching the New Script Dialog & Pine Mode
To start a new indicator or backtest in either JavaScript or Direct Pine Script Mode:
Click "New" or Choose a Starter Template
Click "New" (Ctrl+Alt+N) to choose from Custom Indicator, Strategy Backtesting, or 169+ Library / Blank Canvas, or select Pine Script: EMA Cross + Logs (pine_ema) from the Templates dropdown.
Direct Pine Execution, .pine File I/O & Sub-Pane Routing
Any tab containing //@version=, indicator(...), or strategy(...) switches langModeBtn to Auto · Pine automatically (or toggle explicitly via Mode · Pine / Mode · JS). Setting overlay=false spawns a dedicated lower chart pane, and scripts export/import with .pine and .pinescript extensions.
Mode 1: Custom Indicator Template
Designed for plotting overlays, moving averages, bands, and custom oscillators directly on the HTML5 chart canvas.
Included Features:
- Direct canvas coordinate helpers (
ctx.priceToY,ctx.barToX). - Viewport boundary destructuring (
startIndex,endIndex,candleSlot). - Fast MA (9) & Slow MA (21) dual line calculation logic.
- RSI filter condition and high-performance canvas line stroke loops.
// Extract bars and visible bounds
const bars = ctx.bars;
const bounds = ctx.bounds;
const { startIndex, endIndex, numVisible, candleSlot } = bounds;
if (!bars || bars.length < 20) return;
// Render Moving Average on Canvas
ctx.strokeStyle = '#2962ff';
ctx.lineWidth = 2;
ctx.beginPath();
for (let i = startIndex; i <= endIndex; i++) {
const x = ctx.barToX(i);
const y = ctx.priceToY(bars[i].close);
if (i === startIndex) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
Mode 2: Strategy Backtesting Template
Built for quantitative traders running systematic simulations in the BacktestX Strategy Tester terminal.
Included Features:
- Dynamic ATR Trailing Stop and Profit Target calculations.
- Position sizing and Capital management via
ctx.strategy.initial_capital. - Simulated order execution with
ctx.strategy.entry&ctx.strategy.exit. - Custom metrics injection via
ctx.strategy.setMetric.
// Configure Initial Capital & Risk
ctx.strategy.initial_capital(10000, 'USD');
const fast = ctx.ta.ema(ctx.close, 9);
const slow = ctx.ta.ema(ctx.close, 21);
const atr = ctx.ta.atr(14);
// Enter Long Position on Golden Cross
if (ctx.ta.crossover(fast, slow)) {
const stopPrice = ctx.close[0] - (atr[0] * 1.5);
const targetPrice = ctx.close[0] + (atr[0] * 3.0);
ctx.strategy.entry('Long', 'buy', 1);
ctx.strategy.exit('Exit Long', 'Long', { stop: stopPrice, limit: targetPrice });
}
Mode 3: 169+ Indicator Library & Blank Canvas
The quickest way to learn BacktestX scripting is by studying real, production-ready indicator algorithms.
Open-Source Library (169+)
Clicking the Library option opens a searchable indicator browser. Select any built-in study (e.g. Supertrend, Bollinger Bands, EMA Ribbon, VWAP, Ichimoku, Stochastic RSI) to populate the editor with full source code.
Blank Canvas
Start from a completely clean slate with zero boilerplate comments or starter variables for experienced developers building proprietary tools from scratch.
Workflow & Safety Integration
Integrated with Version History
When spawning a new template, your existing editor code is automatically preserved in the Script Version History timeline. You can toggle between experimental templates and previous revisions at any time without losing a single line.