User Styles & Indicator Settings UI
The BacktestX engine automatically constructs a fully interactive Style Tab for your custom JS and Direct Pine scripts. Users can customize line colors, dynamic per-bar fills, stroke widths, plot styles (Line, Stepline, Histogram, Area, Cross, Circles, Columns, Linebr), histbase, gradients, visibility toggles, and decimal precision without altering code.
Dynamic Style Tab Architecture
When a trader opens the Indicator Settings dialog for a custom script, BacktestX dynamically generates three primary tabs:
- Inputs Tab: Generated dynamically from your
ctx.input()andinput.*calls (including v1.0.6 out-of-order named arguments). - Style Tab: Generated dynamically by inspecting all plot declarations (
ctx.plot,ctx.hline,ctx.fill,ctx.fill_plots,ctx.plotcandle,ctx.plotbar,ctx.plotshape,ctx.plotarrow) — including variable-assigned handles likep1 = plot(...)/h1 = hline(...)passed into gradient fills (color.gradient/top_color/bottom_color) — or an explicitctx.ind.styleSchema. - Pane Routing & Visibility Tab: Direct Pine scripts declaring
overlay=falseautomatically allocate dedicated sub-panes alongside per-timeframe visibility thresholds.
plot() / ctx.plot() or hline() / ctx.hline() (even when assigned to variables and shaded with fill(), per-bar dynamic colors, or histbase) registers controls into the Style Tab schema automatically.
// Automatic registration in the Style Tab:
// 1. Plot registration -> Adds color picker, width selector, and style dropdown (Line, Stepline, Histogram, Columns, Circles, Area)
ctx.plot(sma20, { title: 'Fast SMA (20)', color: '#2962ff', width: 2, style: 'line' });
// 2. Horizontal line registration -> Adds level value, color picker, and stroke style (Solid, Dashed, Dotted)
ctx.hline(70, { title: 'Overbought Level', color: '#ef5350', lineStyle: 'dashed', width: 1 });
// 3. Fill registration (supports p1 = plot(...), h1 = hline(...), & gradient colors)
ctx.fill('upperBand', 'lowerBand', { title: 'Cloud Background', color: '#2962ff', fillOpacity: 0.15 });
Automatic Schema Registration via Plot APIs
During the execution of your indicator, the BacktestX runtime intercepts declarative rendering calls and registers their metadata into the indicator's styleSchema:
| Method Call | Generated Schema Type | Generated UI Controls in Style Tab |
|---|---|---|
| ctx.plot(data, options) | type: 'line' | Checkbox (Visibility), Color Picker, Stroke Width (1-4px), Plot Type Selector (Line, Stepline, Histogram, Cross, Area, Columns, Circles), Precision. |
| ctx.hline(level, options) | type: 'band' | Checkbox (Visibility), Numeric Level Input, Color Picker, Line Style (Solid, Dashed, Dotted), Line Width. |
| ctx.fill(plot1, plot2, options) | type: 'fill' | Checkbox (Visibility), Fill Color Picker, Fill Opacity Slider (0% to 100%). |
| ctx.plotcandle(o, h, l, c, opts) | type: 'candle' / 'group_colors' | Checkboxes & Colors for Up Candle Body, Down Candle Body, Candle Border, and Wick colors. |
| ctx.plotbar(o, h, l, c, opts) | type: 'bar' | Checkboxes & Colors for Up Bar and Down Bar coloring. |
| ctx.plotshape(cond, opts) | type: 'shape' / 'color_only' | Checkbox (Visibility), Tint Color Picker, Marker Location, Shape Type. |
| ctx.plotarrow(series, opts) | type: 'arrow' / 'dual_color' | Checkbox (Visibility), Up Arrow Color, Down Arrow Color. |
Supported Style Schema Types
The Style Tab renderer handles multiple specialized widget schemas. Below are the canonical schema types supported in BacktestX:
1. type: 'line'
Used for time-series plots. Renders a visibility toggle, title, color swatch, stroke width dropdown, plot style selector, and precision dropdown.
{
key: 'plot_0',
title: 'RSI Line',
type: 'line',
defaultColor: '#7e57c2',
defaultWidth: 2,
defaultStyle: 'line', // 'line' | 'stepline' | 'histogram' | 'cross' | 'area' | 'columns' | 'circles'
visible: true
}
2. type: 'band' (Horizontal Line)
Used for static price levels or oscillator thresholds (e.g. Upper Band, Zero Line, Lower Band). Renders an editable price level input, color picker, line style dropdown (Solid, Dashed, Dotted), and width.
{
key: 'upper_band',
title: 'Upper Band',
type: 'band',
defaultLevel: 70,
defaultColor: '#787b86',
defaultLineStyle: 'dashed', // 'solid' | 'dashed' | 'dotted'
defaultWidth: 1,
visible: true
}
3. type: 'fill' (Region Shading)
Used for shaded background channels between two plot lines or bands (e.g., Bollinger Bands cloud, Ichimoku Kumo cloud). Renders color picker and fill opacity percentage control.
{
key: 'bb_fill',
title: 'Bollinger Background',
type: 'fill',
defaultColor: '#2962ff',
defaultOpacity: 0.1, // 0.0 to 1.0 (0% to 100%)
visible: true
}
4. type: 'color_only' / 'shape'
Used for chart markers, breakout signals, and shapes rendered via ctx.plotshape().
{
key: 'buy_signals',
title: 'Buy Breakout Markers',
type: 'color_only',
defaultColor: '#26a69a',
visible: true
}
5. type: 'dual_color' (Bullish & Bearish Swatches)
Used for indicators with conditional 2-color states, such as MACD histogram bars, Supertrend trend lines, or buy/sell signal arrows.
{
key: 'trend_color',
title: 'Trend Direction',
type: 'dual_color',
upColor: '#26a69a',
downColor: '#ef5350',
visible: true
}
Output Values & Precision Formatting
At the bottom of the Style Tab, BacktestX provides global output value toggles and numerical precision controls that apply to the active indicator:
Precision (0–8 Decimals)
Controls the number of decimal places rendered in the indicator legend, hover tooltips, and price scales. Options: Default, 0, 1, 2, 3, 4, 5, 6, 7, 8.
Values in Status Line
Toggles whether real-time scalar values of the indicator (e.g., RSI: 64.21) are displayed in the chart header / legend status line.
Values in Price Scale
Toggles whether a colored value marker tag is displayed on the right-hand Y-axis / price scale.
Indicator Titles & Labels
Toggles the visibility of plot labels and titles in the legend overlay.
Manual Style Schema Definition (ctx.ind.styleSchema)
For advanced custom indicators requiring custom grouped palettes or predefined styles before calculations run, you can explicitly define ctx.ind.styleSchema:
// Define explicit Style Tab schema
ctx.ind.styleSchema = [
{ key: 'macd_line', title: 'MACD Line', type: 'line', defaultColor: '#2962ff', defaultWidth: 2, defaultStyle: 'line' },
{ key: 'signal_line', title: 'Signal Line', type: 'line', defaultColor: '#ff6d00', defaultWidth: 2, defaultStyle: 'line' },
{ key: 'histogram', title: 'Histogram', type: 'line', defaultColor: '#26a69a', defaultWidth: 1, defaultStyle: 'histogram' },
{ key: 'zero_line', title: 'Zero Line', type: 'band', defaultLevel: 0, defaultColor: '#787b86', defaultLineStyle: 'dotted' }
];
// In calculations, use the exact plot keys
ctx.plot(macdValues, { key: 'macd_line', title: 'MACD Line' });
ctx.plot(signalValues, { key: 'signal_line', title: 'Signal Line' });
ctx.plot(histValues, { key: 'histogram', title: 'Histogram', style: 'histogram' });
ctx.hline(0, { key: 'zero_line', title: 'Zero Line' });
Accessing Style Values at Runtime
When users change colors or widths in the Style Tab, the BacktestX runtime exposes these active styles on ctx.style, allowing programmatic inspection if needed:
// Read active user color choice (or fallback to default)
const activeColor = ctx.style?.colors?.['macd_line'] || '#2962ff';
// Read active stroke width
const activeWidth = ctx.style?.widths?.['macd_line'] || 2;
// Read plot visibility toggle
const isVisible = ctx.style?.visible?.['macd_line'] !== false;
Settings Persistence & Default Resetting
Every customization made by the user in the Style Tab is automatically saved in browser local storage keyed by the script's unique name:
// Storage Key Format in LocalStorage:
localStorage.getItem('cl_default_style_custom_MyCustomIndicator');
If a user ever wants to revert modifications back to the original script defaults, they can click the Defaults button at the bottom-left of the settings modal and choose "Reset to Factory Defaults".
Complete Indicator Style Tab Examples
Example: Bollinger Bands with Channel Fill & Basis Line
This script automatically generates 3 plot lines, a shaded background cloud, and precision controls in the Style Tab:
// Define inputs
const length = ctx.input('length', 20, { title: 'Length', type: 'int', min: 1 });
const mult = ctx.input('mult', 2.0, { title: 'StdDev Multiplier', type: 'float', min: 0.1, step: 0.1 });
// Calculations
const src = (ctx.bars || []).map(b => b.close);
const basis = ctx.ta.sma(src, length);
const dev = ctx.ta.stdev(src, length).map(d => d * mult);
const upper = basis.map((b, i) => (b != null && dev[i] != null) ? b + dev[i] : null);
const lower = basis.map((b, i) => (b != null && dev[i] != null) ? b - dev[i] : null);
// Declarative plots (Auto-registered into Style Tab)
const pUpper = ctx.plot(upper, { title: 'Upper Band', color: '#2962ff', width: 1 });
const pBasis = ctx.plot(basis, { title: 'Basis Line', color: '#ff6d00', width: 1.5 });
const pLower = ctx.plot(lower, { title: 'Lower Band', color: '#2962ff', width: 1 });
// Shaded channel fill between upper and lower bands
ctx.fill(pUpper, pLower, { title: 'Background Cloud', color: '#2962ff', fillOpacity: 0.08 });