VibeFox JS Trading — Demo
Quick start
Plain HTML
One-minute bars shown as 5-minute candles with the toolbar, the drawing toolbar, an EMA and an RSI pane; a local timer sends a live tick every half second. Scroll the wheel to zoom, drag to pan, pick a timeframe or a drawing tool.
document.getElementById('app').style.height = '480px';
// bars: { time (ms of the bar start), open, high, low, close, volume }
const bars = VibeFoxJSTrading.generateBars({ count: 1000, interval: 60000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '5m',
toolbar: true,
drawingToolbar: true,
});
chart.addIndicator('ema', { period: 21 });
chart.addIndicator('rsi');
// a live tick extends the last bar or opens a new one
let price = bars[bars.length - 1].close;
setInterval(() => {
price += (Math.random() - 0.5) * 0.15;
chart.addTick({ price, volume: 10 });
}, 500);Core concepts
Bars
Sixty daily bars written in the code ({ time, open, high, low, close, volume }), shown as days and resampled into weeks. Switch the timeframe with the buttons.
const bars = [];
let close = 50;
for (let i = 0; i < 60; i++) {
const open = close;
close = +(open + Math.sin(i / 5) * 1.5 + ((i % 3) - 1) * 0.4).toFixed(2);
bars.push({
time: Date.UTC(2026, 0, 1) + i * 86400000,
open, close,
high: +(Math.max(open, close) + 0.6).toFixed(2),
low: +(Math.min(open, close) - 0.6).toFixed(2),
volume: 1000 + ((i * 37) % 500),
});
}
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'MY BARS', timeframe: '1D' });
const buttons = document.createElement('p');
for (const [label, run] of [
['Days', () => chart.setTimeframe('1D')],
['Weeks', () => chart.setTimeframe('1W')],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);Events
The line above the chart is filled by the events crosshairMove and visibleRangeChange. Move the mouse over the candles, then zoom or pan.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
const out = document.createElement('p');
out.textContent = 'Move the mouse over the chart';
document.getElementById('app').before(out);
const day = (t) => new Date(t).toISOString().slice(0, 16).replace('T', ' ');
chart.on('crosshairMove', (e) => {
if (e.bar) out.textContent = day(e.time) + ' close ' + e.bar.close.toFixed(2) + ' cursor ' + (e.price == null ? '-' : e.price.toFixed(2));
});
chart.on('visibleRangeChange', (e) => {
out.textContent = 'Visible: ' + day(e.timeFrom) + ' to ' + day(e.timeTo);
});Data and real time
Live updates
A local timer stands in for a real-time feed: addTick() every 200 ms, five seconds of market time per tick, so a new minute bar opens every 12 ticks and barClose counts it.
const bars = VibeFoxJSTrading.generateBars({ count: 120, interval: 60000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'LIVE', timeframe: '1m' });
chart.addIndicator('sma', { period: 10 });
const out = document.createElement('p');
document.getElementById('app').before(out);
let price = bars[bars.length - 1].close;
let time = bars[bars.length - 1].time + 60000;
let closed = 0;
chart.on('barClose', () => { closed++; });
setInterval(() => {
price += (Math.random() - 0.48) * 0.12;
time += 5000;
chart.addTick({ price, volume: 5 + Math.random() * 20, time });
out.textContent = 'Last ' + price.toFixed(2) + ', bars closed: ' + closed;
}, 200);Markers
Buy and sell markers at bars, above or below the candles, with text and their own color. A click on a marker writes its text above the chart.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 120, to: bars.length });
chart.setMarkers([
{ time: bars[bars.length - 95].time, shape: 'arrowUp', position: 'below', text: 'Buy' },
{ time: bars[bars.length - 60].time, shape: 'arrowDown', position: 'above', text: 'Sell', color: '#dc2626' },
{ time: bars[bars.length - 40].time, shape: 'circle', position: 'below', text: 'News', color: '#7c3aed' },
{ time: bars[bars.length - 12].time, shape: 'arrowUp', position: 'below', text: 'Buy' },
]);
const out = document.createElement('p');
out.textContent = 'Click a marker';
document.getElementById('app').before(out);
chart.on('markerClick', (e) => { out.textContent = 'Clicked: ' + e.marker.text; });Replay
Replay starts 150 bars before the end and plays the history bar by bar. Pause it, step five bars, resume or stop (all bars come back).
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'REPLAY', timeframe: '1h' });
chart.addIndicator('ema', { period: 20 });
chart.startReplay({ at: bars.length - 150, intervalMs: 300, autoplay: true });
const buttons = document.createElement('p');
for (const [label, run] of [
['Pause', () => chart.pauseReplay()],
['Resume', () => chart.resumeReplay()],
['Step 5', () => chart.stepReplay(5)],
['Restart', () => chart.startReplay({ at: bars.length - 150, intervalMs: 300, autoplay: true })],
['Stop', () => chart.stopReplay()],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);Series and chart types
Series types
Pick any of the 14 series types in the list (SERIES_TYPES): candlestick, OHLC, line, area, baseline, histogram, Heikin Ashi, hollow and volume candles, and the built types.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 150, to: bars.length });
const picker = document.createElement('select');
for (const name of VibeFoxJSTrading.SERIES_TYPES) picker.add(new Option(name));
picker.onchange = () => chart.setSeriesType(picker.value);
document.getElementById('app').before(picker);Built chart types
Renko bricks of 0.5 with wicks, built from the time bars (the x axis is the sequence of bricks). Pick Kagi, Point & Figure, line break or range bars; the line above shows getChartTypeInfo().
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
seriesType: 'renko',
chartTypes: { renko: { boxSize: 0.5, source: 'close', wicks: true } },
});
const info = document.createElement('p');
const show = () => {
const i = chart.getChartTypeInfo();
info.textContent = i.type + ': size ' + (i.size == null ? (i.percent == null ? '-' : i.percent + ' %') : i.size.toFixed(2)) + ', parameters ' + JSON.stringify(i.params);
};
const picker = document.createElement('select');
for (const name of VibeFoxJSTrading.BUILT_TYPES) picker.add(new Option(name));
picker.onchange = () => { chart.setSeriesType(picker.value); show(); };
document.getElementById('app').before(picker);
picker.after(info);
show();Indicators
Adding indicators
A 50-period SMA and Bollinger Bands on the price pane, MACD in its own pane with the values in the pane legend and badges on the price axis. Drag the border between the panes to resize them.
document.getElementById('app').style.height = '460px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.addIndicator('sma', { period: 50 });
chart.addIndicator('bollinger', { period: 20, mult: 2 });
chart.addIndicator('macd');
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });Built-in indicators
Pick any of the 50 built-in indicators in the list; the previous one is removed. Overlays go to the price pane, oscillators to a pane of their own.
document.getElementById('app').style.height = '440px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });
let current = chart.addIndicator('ichimoku');
const names = Object.values(VibeFoxJSTrading.INDICATOR_GROUPS).flat();
const picker = document.createElement('select');
for (const name of names) picker.add(new Option(name));
picker.onchange = () => { chart.removeIndicator(current); current = chart.addIndicator(picker.value); };
document.getElementById('app').before(picker);
picker.value = 'ichimoku';Your own indicators
A registered indicator "Mid line": the 30-bar SMA of (high + low) / 2, drawn in purple on the price pane like a built-in one.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
VibeFoxJSTrading.registerIndicator({
name: 'midline',
label: 'Mid line',
pane: 'overlay', // 'overlay' | 'separate' | 'volume'
params: { period: 10 },
compute(bars, p) {
const mid = bars.map((b) => (b.high + b.low) / 2);
return { plots: [{ key: 'mid', values: VibeFoxJSTrading.sma(mid, p.period), color: '#9333ea', width: 2 }] };
},
});
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.addIndicator('midline', { period: 30 });
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });Drawing tools
Tools
The drawing toolbar with all 48 tools by group; the trend line tool is already active. Click two points on the chart, then pick a Fibonacci, pitchfork or position tool from the toolbar and draw it.
document.getElementById('app').style.height = '460px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h', drawingToolbar: true });
chart.setVisibleRange({ from: bars.length - 150, to: bars.length });
chart.setTool('trendline');Drawings from code
A dashed, locked trend line extended to the right, a Fibonacci retracement with labels, a parallel channel and a text, added with addDrawing(). Zoom or change the timeframe: the anchors are time and price.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 160, to: bars.length });
const a = bars[bars.length - 140], b = bars[bars.length - 30];
const lo = Math.min(...bars.slice(-140).map((x) => x.low));
const hi = Math.max(...bars.slice(-140).map((x) => x.high));
const id = chart.addDrawing({ tool: 'trendline', points: [{ time: a.time, price: a.low }, { time: b.time, price: b.low }],
color: '#2563eb', lineWidth: 2, extendRight: true });
chart.updateDrawing(id, { lineStyle: 'dashed', locked: true });
chart.addDrawing({ tool: 'fib', points: [{ time: a.time, price: lo }, { time: b.time, price: hi }], showLabels: true });
chart.addDrawing({ tool: 'text', points: [{ time: b.time, price: hi }], text: 'Range high', fontSize: 14, bold: true });Editing, selection and undo
A rectangle selected with its properties panel open (showDrawingProperties()). Change its color or line, drag the drawing or its handles, then press Ctrl+Z to undo.
document.getElementById('app').style.height = '440px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 120, to: bars.length });
const a = bars[bars.length - 90], b = bars[bars.length - 40];
chart.addDrawing({ tool: 'hline', points: [{ time: a.time, price: a.close }] });
const id = chart.addDrawing({ tool: 'rect', points: [{ time: a.time, price: a.high }, { time: b.time, price: b.low }],
fill: true, fillOpacity: 0.15 });
chart.selectDrawing(id);
chart.showDrawingProperties(id);Datafeed
Loading and errors
A datafeed whose first loads fail: after the retry the chart shows "Failed to load data" (event dataError). Click Reload to call reloadData().
const memory = new VibeFoxJSTrading.MemoryDatafeed({ symbols: ['DEMO'], latency: 100 });
memory.failNext(2, 'Server is down');
const chart = VibeFoxJSTrading.createTradingChart('#app', {
datafeed: memory,
symbol: 'DEMO',
timeframe: '5m',
datafeedOptions: { retries: 1, retryDelay: 300 },
});
const out = document.createElement('p');
document.getElementById('app').before(out);
chart.on('dataError', (e) => { out.textContent = 'dataError, attempt ' + e.attempt + (e.final ? ' (final)' : ''); });
chart.on('dataLoad', (e) => { out.textContent = 'dataLoad: ' + e.count + ' bars'; });
const buttons = document.createElement('p');
for (const [label, run] of [
['Reload', () => chart.reloadData()],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);MemoryDatafeed
The in-memory datafeed with three random symbols and live ticks every half second. Pick another symbol or timeframe in the toolbar; scroll to the left to load older history.
const memory = new VibeFoxJSTrading.MemoryDatafeed({
symbols: {
BTCUSD: { startPrice: 60000, description: 'Bitcoin', type: 'crypto' },
ETHUSD: { startPrice: 3000, description: 'Ether', type: 'crypto' },
DEMO: { startPrice: 100 },
},
latency: [20, 80],
});
const chart = VibeFoxJSTrading.createTradingChart('#app', {
datafeed: memory,
symbol: 'BTCUSD',
timeframe: '5m',
toolbar: { items: ['symbol', 'timeframes', 'seriesType'], symbols: ['BTCUSD', 'ETHUSD', 'DEMO'] },
});
chart.whenLoaded().then(() => memory.start(500)); // live ticksSymbol comparison
Two other symbols as lines over the main candles; the scale switched to percent, so every series starts at 0 % at the first visible bar. Pan the chart: the start moves with the view.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'MAIN', timeframe: '1h' });
chart.addCompare('ETH', { data: VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000, startPrice: 50, seed: 2 }), color: '#f59e0b' });
chart.addCompare('SPX', { data: VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000, startPrice: 4000, seed: 3 }), color: '#0891b2' });
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });Scales, navigation and navigator
Scales and the visible range
A logarithmic price scale, session break lines and the last 200 bars set with setVisibleRange(). Drag the price scale up or down to zoom the price, double-click the chart to reset both scales.
const bars = VibeFoxJSTrading.generateBars({ count: 2000, interval: 3600000, startPrice: 20, volatility: 0.006 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
priceScale: { mode: 'log' },
timeScale: { sessionBreaks: true, rightOffset: 10 },
});
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });
const picker = document.createElement('select');
for (const name of ['log', 'linear', 'percent']) picker.add(new Option(name));
picker.onchange = () => chart.setPriceScaleMode(picker.value);
document.getElementById('app').before(picker);Navigator and period buttons
The navigator under the chart shows the whole history with the visible range as a window, the period buttons show the last month. Drag or resize the window, or click 5D, 3M or All.
document.getElementById('app').style.height = '460px';
const bars = VibeFoxJSTrading.generateBars({ count: 4000, interval: 3600000, volatility: 0.001 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h', navigator: true, periods: true });
chart.setPeriod('1M');Volume profile
The volume by price levels of the visible range with the point of control. Zoom or pan: the profile is computed again for the new range.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
volumeProfile: { visible: true, bins: 24 },
});
chart.setVisibleRange({ from: bars.length - 200, to: bars.length });Time zones and sessions
Four days of five-minute bars with the New York schedule: the pre- and post-market hours are shaded, dashed lines mark the session starts, VWAP restarts every trading day and the times are in the exchange zone. Pick another time zone in the list.
const bars = VibeFoxJSTrading.generateBars({ count: 1200, interval: 300000, startPrice: 180 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'NYSE DEMO',
timeframe: '15m',
sessions: { preset: 'nyse', extended: true, highlight: true },
timezone: 'exchange',
timeScale: { sessionBreaks: true },
});
chart.addIndicator('vwap');
const picker = document.createElement('select');
for (const name of ['exchange', 'UTC', 'Europe/London', 'Asia/Tokyo']) picker.add(new Option(name));
picker.onchange = () => chart.setTimezone(picker.value);
document.getElementById('app').before(picker);Alerts
Two price alert lines and an alert on the price crossing the SMA, checked on live ticks from a local timer that swings the price; every fired alert is added to the list above the chart. Drag an alert line to another price.
const bars = VibeFoxJSTrading.generateBars({ count: 200, interval: 60000, startPrice: 1.08 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'EURUSD', timeframe: '1m' });
const last = bars[bars.length - 1].close;
const sma = chart.addIndicator('sma', { period: 20 });
chart.addAlert(+(last + 0.004).toFixed(5), { label: 'Resistance' });
chart.addAlert(+(last - 0.004).toFixed(5), { label: 'Support', color: '#dc2626' });
chart.addAlert({ source: 'price', condition: 'crossing', target: { indicator: sma }, frequency: 'oncePerBar',
message: '{symbol}: price crossed SMA at {price}' });
const out = document.createElement('p');
out.textContent = 'Waiting for an alert...';
document.getElementById('app').before(out);
const fired = [];
chart.on('alertTrigger', (e) => {
fired.unshift(new Date().toLocaleTimeString() + ' ' + e.message);
out.textContent = fired.slice(0, 2).join(' | ');
});
// a local stand-in for live data: the price swings around the last close
let k = 0, time = bars[bars.length - 1].time + 60000;
setInterval(() => {
k++;
time += 6000;
const price = last + 0.006 * Math.sin(k / 6) + (Math.random() - 0.5) * 0.001;
chart.addTick({ price: +price.toFixed(5), volume: 5, time });
}, 200);Terminal UI
The ready-made toolbar (symbol, timeframes, series type, indicators, comparison, alerts, undo / redo, settings, snapshot, fullscreen) and the drawing toolbar. Open Indicators to search and add one, or Settings to change colors and scales.
document.getElementById('app').style.height = '480px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'BTCUSD',
timeframe: '1h',
toolbar: {
items: ['symbol', 'timeframes', 'seriesType', '|', 'indicators', 'compare', 'alerts', '|', 'undo', 'redo', '-', 'settings', 'snapshot', 'fullscreen'],
favorites: ['15m', '1h', '4h', '1D'],
symbols: ['BTCUSD', 'ETHUSD'],
},
drawingToolbar: true,
});
chart.addIndicator('ema', { period: 50 });Watchlist and symbol search
A watchlist in two groups with the last price, the change and a sparkline, fed live by an in-memory datafeed. Click a row to switch the chart, or click the symbol in the toolbar to search.
document.getElementById('app').style.height = '460px';
const memory = new VibeFoxJSTrading.MemoryDatafeed({
symbols: {
BTCUSD: { startPrice: 60000, description: 'Bitcoin', type: 'crypto' },
ETHUSD: { startPrice: 3000, description: 'Ether', type: 'crypto' },
AAPL: { startPrice: 230, description: 'Apple', type: 'stock' },
MSFT: { startPrice: 420, description: 'Microsoft', type: 'stock' },
},
});
const chart = VibeFoxJSTrading.createTradingChart('#app', {
datafeed: memory,
symbol: 'BTCUSD',
timeframe: '15m',
toolbar: { items: ['symbol', 'timeframes', '-', 'watchlist'] },
symbolSearch: true,
watchlist: {
groups: [{ title: 'Crypto', symbols: ['BTCUSD', 'ETHUSD'] }, { title: 'Stocks', symbols: ['AAPL', 'MSFT'] }],
columns: ['last', 'changePct', 'spark'],
},
});
chart.whenLoaded().then(() => memory.start(700));Several charts and synchronization
A layout of four charts with one in-memory datafeed: three timeframes of BTCUSD and ETHUSD, the crosshair synchronized by time. Move the mouse over one chart; click a chart to make it active.
document.getElementById('app').style.height = '560px';
const layout = VibeFoxJSTrading.createTradingLayout('#app', {
layout: '4',
datafeed: new VibeFoxJSTrading.MemoryDatafeed({ symbols: ['BTCUSD', 'ETHUSD'] }),
chart: { symbol: 'BTCUSD' },
charts: [{ timeframe: '1m' }, { timeframe: '5m' }, { timeframe: '1h' }, { symbol: 'ETHUSD', timeframe: '5m' }],
sync: { crosshair: true, drawings: true },
});
layout.getChart(2).addIndicator('rsi');Trading from the chart
On the chart
A long position with stop loss and take profit, a buy limit order and a sell stop order, and the depth-of-market ladder; the broker is a small object in the code. Drag an order line to a new price, or click a price in the ladder to place an order.
document.getElementById('app').style.height = '460px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const last = bars[bars.length - 1].close;
const p = (pct) => +(last * (1 + pct / 100)).toFixed(2);
let n = 0;
const broker = { // stands in for your server: accepts every request
placeOrder: (order) => ({ id: 'o' + ++n, status: order.type === 'market' ? 'filled' : 'working' }),
modifyOrder: (id, changes) => changes,
cancelOrder: () => ({ status: 'cancelled' }),
closePosition: () => ({ quantity: 0 }),
modifyPosition: (id, changes) => changes,
};
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
trade: { broker, quantity: 10, tickSize: 0.01, currency: 'USD', dom: true },
});
chart.setVisibleRange({ from: bars.length - 100, to: bars.length });
chart.setPositions([{ id: 'p1', side: 'long', quantity: 10, avgPrice: p(-0.6), sl: p(-1.1), tp: p(1.2) }]);
chart.setOrders([
{ id: 'o1', side: 'buy', type: 'limit', price: p(-0.85), quantity: 5 },
{ id: 'o2', side: 'sell', type: 'stop', stopPrice: p(0.8), quantity: 5 },
]);
const book = { bids: [], asks: [] };
for (let i = 1; i <= 10; i++) {
book.bids.push([+(last - i * 0.01).toFixed(2), 50 + i * 30]);
book.asks.push([+(last + i * 0.01).toFixed(2), 40 + i * 35]);
}
chart.setDepth(book);MockBroker
The in-memory MockBroker fills a market buy at the live price of the chart and keeps the position P&L up to date on every tick. Use Buy / Sell, or the Trade button for the order ticket.
document.getElementById('app').style.height = '460px';
const bars = VibeFoxJSTrading.generateBars({ count: 300, interval: 60000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1m',
toolbar: { items: ['symbol', 'timeframes', '-', 'trade', 'dom'] },
});
const mock = new VibeFoxJSTrading.MockBroker({ latency: 50, symbol: 'DEMO' }).attach(chart);
chart.setOptions({ trade: { broker: mock, quantity: 2, tickSize: 0.01 } });
let price = bars[bars.length - 1].close, time = bars[bars.length - 1].time + 60000;
setInterval(() => {
price += (Math.random() - 0.5) * 0.1;
time += 5000;
chart.addTick({ price, volume: 5, time });
}, 250);
setTimeout(() => chart.placeOrder({ side: 'buy', type: 'market', quantity: 2 }), 300);
const buttons = document.createElement('p');
for (const [label, run] of [
['Buy 2', () => chart.placeOrder({ side: 'buy', type: 'market', quantity: 2 })],
['Sell 2', () => chart.placeOrder({ side: 'sell', type: 'market', quantity: 2 })],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);Backtests and strategies
A strategy
A moving-average crossover strategy run on the bars of the chart: trade markers with labels, the equity and drawdown panes. Open the report with the buttons: summary, trades, monthly results.
document.getElementById('app').style.height = '560px';
const bars = VibeFoxJSTrading.generateBars({ count: 1500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
const smaCross = {
name: 'SMA cross',
params: { fast: 10, slow: 30 },
indicators: (p) => ({ fast: ['sma', { period: p.fast }], slow: ['sma', { period: p.slow }] }),
onBar(ctx) {
if (ctx.crossover('fast', 'slow')) ctx.buy({ percent: 50, slOffset: 2 });
else if (ctx.crossunder('fast', 'slow')) ctx.sell({ percent: 50 });
},
};
chart.addIndicator('sma', { period: 10 });
chart.addIndicator('sma', { period: 30 });
chart.setStrategy(smaCross, { capital: 10000, commission: 0.05, markers: true, equity: true, drawdown: true });
chart.setVisibleRange({ from: bars.length - 250, to: bars.length });
const buttons = document.createElement('p');
for (const [label, run] of [
['Report: summary', () => chart.showBacktestReport('summary')],
['Report: trades', () => chart.showBacktestReport('trades')],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);Export
Click Snapshot: getImage() makes the picture of the chart with the title strip and the OHLCV legend, shown under the chart (exportPNG() downloads the same picture).
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'BTC / USD', timeframe: '1h' });
chart.addIndicator('ema', { period: 20 });
chart.setVisibleRange({ from: bars.length - 120, to: bars.length });
const shot = document.createElement('p');
document.getElementById('app').after(shot);
const snap = () => {
const canvas = chart.getImage({ title: 'BTC / USD', subtitle: true, legend: true });
canvas.style.width = '50%';
canvas.style.border = '1px solid #ccc';
shot.replaceChildren(canvas);
};
const buttons = document.createElement('p');
for (const [label, run] of [
['Snapshot', snap],
]) {
const b = document.createElement('button');
b.textContent = label;
b.onclick = run;
buttons.append(b, ' ');
}
document.getElementById('app').before(buttons);
snap();Rendering and large data
100 000 one-minute bars, all on screen at once; the line above tells the renderer in use (WebGL on a GPU from 5000 visible bars, else canvas 2D). Zoom in with the wheel down to single candles.
const bars = VibeFoxJSTrading.generateBars({ count: 100000, interval: 60000, volatility: 0.001 });
const t0 = performance.now();
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: '100K', timeframe: '1m' });
chart.fitContent();
const out = document.createElement('p');
document.getElementById('app').before(out);
const info = () => {
const r = chart.getRenderInfo();
out.textContent = bars.length + ' bars, created in ' + Math.round(performance.now() - t0) + ' ms, renderer: ' + r.renderer + ' (' + r.reason + ')';
};
info();
chart.on('rendererChange', info);Theming and styling
Themes
Pick a theme in the list above the chart: light, dark, high-contrast and the pack themes of vibefox-js-themes.css (paper, ocean, sunset, graphite-dark).
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h', toolbar: true });
chart.addIndicator('bollinger');
const picker = document.createElement('select');
for (const name of ['light', 'dark', 'high-contrast', 'paper', 'ocean', 'sunset', 'graphite-dark']) picker.add(new Option(name));
picker.onchange = () => chart.setTheme(picker.value);
document.getElementById('app').before(picker);CSS variables
Blue and orange candles, no grid lines and a custom crosshair, set as --vfjs-trading-* CSS variables of this chart element; the canvas redraws when a variable changes.
const app = document.getElementById('app');
app.style.setProperty('--vfjs-trading-candle-up', '#0a7cff');
app.style.setProperty('--vfjs-trading-wick-up', '#0a7cff');
app.style.setProperty('--vfjs-trading-candle-down', '#ff7a00');
app.style.setProperty('--vfjs-trading-wick-down', '#ff7a00');
app.style.setProperty('--vfjs-trading-grid', 'transparent');
app.style.setProperty('--vfjs-trading-crosshair', '#9333ea');
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 120, to: bars.length });Ready-made styles
Pick one of the ready-made styles in the list: classic, terminal (always dark), monochrome, light (always light), or none for the default look.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h', style: 'terminal', toolbar: true });
chart.addIndicator('ema', { period: 20 });
chart.setVisibleRange({ from: bars.length - 120, to: bars.length });
const picker = document.createElement('select');
for (const name of ['none', ...VibeFoxJSTrading.TRADING_STYLES]) picker.add(new Option(name));
picker.onchange = () => chart.setStyle(picker.value === 'none' ? null : picker.value);
document.getElementById('app').before(picker);
picker.value = 'terminal';Density and size
The same chart with --vfjs-size-unit: 1.3px: the toolbar, the axis texts, line widths and markers are larger. Try the compact density in the list.
const app = document.getElementById('app');
app.style.setProperty('--vfjs-size-unit', '1.3px');
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h', toolbar: true });
chart.setVisibleRange({ from: bars.length - 80, to: bars.length });
const picker = document.createElement('select');
for (const name of ['size unit 1.3px', 'normal', 'compact', 'comfortable']) picker.add(new Option(name));
picker.onchange = () => {
app.style.setProperty('--vfjs-size-unit', picker.selectedIndex ? '1px' : '1.3px');
app.dataset.vfjsDensity = picker.selectedIndex ? picker.value : 'normal';
};
document.getElementById('app').before(picker);Localization and RTL
Languages
The chart in Russian: load the language pack vibefox-js-trading.ru.js after the library and set locale: 'ru'. The toolbar, the legend, the month names of the time axis and the indicator names are translated.
document.getElementById('app').style.height = '440px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
locale: 'ru',
toolbar: true,
drawingToolbar: true,
});
chart.addIndicator('rsi');
chart.setVisibleRange({ from: bars.length - 150, to: bars.length });Right-to-left
The option rtl: true: the drawing toolbar is on the right and the toolbar runs from the right, while the chart itself is not mirrored (time runs left to right, the price scale stays on the right).
document.getElementById('app').style.height = '480px';
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', {
data: bars,
symbol: 'DEMO',
timeframe: '1h',
rtl: true,
toolbar: true,
drawingToolbar: true,
});Accessibility
Keyboard
The keyboard bar cursor on a bar (focusBar()); the line above shows what a screen reader hears. Click the chart and press the arrow keys, Home, End, or ↑ / ↓ to zoom.
const bars = VibeFoxJSTrading.generateBars({ count: 500, interval: 3600000 });
const chart = VibeFoxJSTrading.createTradingChart('#app', { data: bars, symbol: 'DEMO', timeframe: '1h' });
chart.setVisibleRange({ from: bars.length - 80, to: bars.length });
const out = document.createElement('p');
document.getElementById('app').before(out);
const read = () => {
const i = chart.getFocusedBar();
out.textContent = i == null ? chart.getSummary().text : chart.describeBar(i);
};
chart.focusBar(bars.length - 20);
read();
document.getElementById('app').addEventListener('keyup', read);