畫線觸發與警示

開源圖表引擎

畫線觸發與警示

會動作的畫線(以回放 K 線模擬)。價格向上穿越橘色趨勢線時觸發一次買進,每根收盤越過虛線水平線的 K 線都會發出警示;兩者都顯示為一則提示和該價格上的一個標記。可以拖曳任一條線:移動後的線會重新判斷價格在哪一側,所以把線拖過價格不會觸發。引擎不傳送任何資料。

Apache-2.0

畫線觸發與警示:執行與交易檢討範例

createLineTrigger · drawings.add('trend_line') · tradeMarkers · position: 'atPrice'

程式碼
import { FerroChart } from '@ferrochart/core';
import { tradeMarkers } from '@ferrochart/core/trading';
import { createLineTrigger } from '@ferrochart/core/trading-trigger';

const canvas = document.querySelector('canvas');
// Market data: the synthetic FerroChart demo API. Use your own feed.
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const bars = await fetch('/api/bars?symbol=BTCUSD&interval=15m&count=400').then((r) => r.json());
// Bar replay with setData and update: all but the last 40 bars, then each
// step() moves the forming bar a little; it closes on its 4th tick. At the end
// of the data the replay starts over (restart() resets the example).
const n = bars.time.length, START = n - 40, TICKS = 4;
const head = (k) => Object.fromEntries(Object.entries(bars).map(([key, v]) => [key, v.slice(0, k)]));
const candles = chart.addCandlestickSeries();
candles.setData(head(START));
let next = START, tick = 0, forming = null;
function step() {
  if (next === n) { next = START; candles.setData(head(START)); restart(); }
  const i = next, t = ++tick, closed = t === TICKS, o = bars.open[i];
  const noise = (Math.random() - 0.5) * (bars.high[i] - bars.low[i]) * 0.5;
  const price = closed ? bars.close[i] : Math.round((o + (bars.close[i] - o) * t / TICKS + noise) * 10) / 10;
  if (t === 1) forming = { time: bars.time[i], open: o, high: o, low: o };
  forming = { ...forming, high: Math.max(forming.high, price), low: Math.min(forming.low, price), close: price, volume: bars.volume[i] * t / TICKS };
  candles.update(forming);
  if (closed) { next++; tick = 0; }
  return { time: bars.time[i], price, closed };
}
chart.setVisibleLogicalRange(START - (canvas.clientWidth < 480 ? 30 : 60), n + 3);
// Paper simulation: the breakout "buys" in this page and the alert is a note
// in the page; nothing is sent anywhere.
const at = (i) => bars.time[i], from = START - 40;
// Drawn where the replayed bars will cross them: a falling resistance line
// above the last bars, and a level in the middle of the closes.
const closes = bars.close.slice(from);
const resistance = chart.drawings.add({ kind: 'trend_line', style: { line: '#ffb547', lineWidth: 2 }, anchors: [
  { time: at(START - 1), price: Math.max(...bars.high.slice(START - 8, START)) * 1.002 },
  { time: at(n - 1), price: Math.min(...bars.close.slice(START)) }] });
const level = chart.drawings.add({ kind: 'horizontal_line', style: { line: '#9b8cff', lineDash: 'dashed' }, anchors: [
  { time: at(START - 1), price: Math.round((Math.min(...closes) + Math.max(...closes)) / 2) }] });

const ui = (tag, css, parent = canvas.parentElement) => parent.appendChild(Object.assign(document.createElement(tag), { style: css }));
const box = ui('div', 'position:absolute;left:12px;top:10px;right:84px;display:flex;flex-direction:column;align-items:flex-start;gap:6px;z-index:2;pointer-events:none');
function toast(text, color) {
  const t = ui('div', `font:500 12px system-ui;color:#e8ecf4;background:rgba(30,34,45,.95);border-left:3px solid ${color};border-radius:5px;padding:6px 10px`, box);
  t.textContent = text;
  t.dataset.at = Date.now();
  while (box.children.length > 3) box.firstChild.remove();
}
const fills = [], alerts = [];
const show = () => candles.setMarkers([...tradeMarkers(fills, { times: bars.time }), ...alerts].sort((a, b) => a.time - b.time));

let breakout, crossing;
function arm() {
  breakout?.destroy();
  crossing?.destroy();
  // An order, once: the price crosses up through the resistance.
  breakout = createLineTrigger(chart, resistance, { mode: 'crossUp', onTrigger({ time, price }) {
    fills.push({ time, price, quantity: 0.1, side: 'buy' });
    show();
    toast(`Breakout: paper buy 0.1 at ${price.toFixed(1)}`, '#26a69a');
  } });
  // An alert, every time a bar closes on the other side of the level.
  crossing = createLineTrigger(chart, level, { mode: 'close', once: false, onTrigger({ time, price, line }) {
    alerts.push({ time, position: 'atPrice', price, shape: 'circle', size: 8, color: '#9b8cff' });
    show();
    toast(`Alert: closed ${price > line ? 'above' : 'below'} ${line.toFixed(0)}`, '#9b8cff');
  } });
}
arm();
const feed = ({ time, price, closed }) => { breakout.update(time, price); crossing.update(time, price, closed); };
for (let i = from; i < START; i++) feed({ time: at(i), price: bars.close[i], closed: true });

function restart() { fills.length = alerts.length = 0; show(); arm(); }
const timer = setInterval(() => {
  feed(step());
  for (const t of [...box.children]) if (Date.now() - t.dataset.at > 5000) t.remove();
}, 600);

// The page calls this before it destroys the chart.
const stop = () => { clearInterval(timer); breakout.destroy(); crossing.destroy(); box.remove(); };

為逐筆等級的資料而生。

Apple M4 Max · Chrome + WebGPU

在瀏覽器中載入 100 萬根 K 線並繪出第一個畫面

WASM · WebGPU

原生載入 1,000 萬根 K 線,含多層級細節金字塔

原生 Rust

平移、縮放與即時串流時每個畫面的堆積記憶體配置次數

穩定狀態

WebAssembly 套件大小(gzip)

包含全部功能

瀏覽器數據:Google Chrome + WebGPU;1,000 萬根 K 線的載入為原生 Rust。長條表示各項數據相對於目標的比例:載入 300 毫秒、零配置、套件 1.5 MB。

範例

320 個範例,
涵蓋 20 個應用情境。

每個範例都是 FerroChart 在你的瀏覽器中即時渲染的圖表,並附上原始碼。所有資料均為模擬資料。

K 線回放
即時串流
K 線 + 成交量
01

價格走勢

28 個範例 →

適用於任何市場的 K 線、棒線與折線,即時串流更新。

深度熱力圖
Delta 足跡圖
足跡圖
04

訂單流

20 個範例 →

足跡圖、深度熱力圖與市場輪廓,走 compute shader 路徑。

隱含波動率 · 基差
多空比 · CVD
資金費率 · 未平倉量 · 清算
06

加密貨幣衍生性商品

15 個範例 →

資金費率、未平倉量、清算與基差,顯示在價格下方的窗格中。

風險逆轉 · 蝶式
到期前的預期波動
隱含與實現波動率 · IV Rank
12

選擇權與波動率

18 個範例 →

隱含波動率與實現波動率對照、偏斜、預期波動幅度與造市商曝險的時間變化。

同步回撤
水下曲線 · 最大回撤
權益曲線 · 回撤
16

投資組合、風險與量化

24 個範例 →

權益曲線、回撤、滾動統計、因子研究與風險檢查。

分組柱狀圖
堆疊柱狀圖
100% 堆疊區域圖
19

自訂系列與外掛

11 個範例 →

堆疊、分組、箱形與筆刷選取系列:在同一個 GPU 影格上疊加圖層外掛。

瀏覽全部 20 個應用情境

價格走勢

K 線類型與轉換

技術分析

訂單流

執行與交易檢討

加密貨幣衍生性商品

鏈上資料

DeFi 與 AMM

迷因幣與錢包

股票與基本面

中國 A 股

選擇權與波動率

利率、外匯與總體經濟

期貨與大宗商品

基金與 ETF

投資組合、風險與量化

私募市場與個人理財

預測市場

自訂系列與外掛

實驗室與旗艦範例

特色

為行情資料而設計。

01

跨平台渲染

同一個 Rust 核心:瀏覽器中使用 WebGPU 與 WebGL2 後端,原生應用程式透過 wgpu 在 Metal、Vulkan 與 DirectX 12 上執行,伺服器上則使用 CPU 渲染器。黃金影像測試確保各後端輸出一致。

02

效能與資料量無關

K 線資料常駐 GPU,座標轉換在著色器中完成,平移與縮放只需更新少量 uniform。多層級細節金字塔讓數千萬根 K 線依然流暢。

03

30 個內建指標

從 SMA 到一目均衡表的均線、通道與震盪指標。每個 tick 增量更新,並以參考資料測試。

04

29 種繪圖工具

趨勢線、通道、費波那契工具、叉子線、江恩角度線、型態、艾略特波浪、區間、部位與文字,支援復原與重做。繪圖與圖表狀態可序列化為 JSON。

05

多圖連動

同步群組可在多個圖表之間連動十字游標與可見範圍。

06

易於擴充

自訂系列、圖層與繪圖工具的外掛介面。提供 JavaScript、Rust 與 Python 繫結,以及供 C#、C++、Qt 與 Flutter 使用的 C ABI。

開始使用

每種語言,同一套 API。

所有繫結都遵循同一模型:建立圖表、加入系列、設定資料、加入指標。資料以欄的形式傳入,可以是型別化陣列、Rust 切片或 DataFrame。

  • JavaScript 與 TypeScript
  • Rust
  • Python 與 Jupyter
  • C、C#、C++
閱讀文件
main.js
$ npm install @ferrochart/core
import { FerroChart } from '@ferrochart/core';

const chart = await FerroChart.create(canvas, { theme: 'dark' });
const candles = chart.addCandlestickSeries();
chart.addVolumeSeries(candles);
candles.setData(bars); // [{ time, open, high, low, close, volume }, ...]
chart.addIndicator(candles, 'ema', { n: 20 });
chart.addIndicator(candles, 'macd'); // in a new pane

FerroChart

每一個市場。
每一塊螢幕。
同一個引擎。

以 Apache-2.0 開源,從瀏覽器到交易桌。