ライントリガーとアラート

オープンソースのチャートエンジン

ライントリガーとアラート

動作する描画ライン(再生した足でのシミュレーション)。オレンジのトレンドラインを上抜けると一度だけ買いが発動し、破線の水平ラインをまたいで終値が確定した足ごとにアラートが出ます。どちらもメッセージとその価格のマーカーで表示されます。ラインはドラッグできます。動かしたラインは価格がどちら側にあるかを取り直すため、価格の上までドラッグしても発動しません。エンジンは何も送信しません。

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 万本の足を読み込み、最初のフレームを描画

WASM · WebGPU

ネイティブで 1,000 万本の足を読み込み(LOD ピラミッド構築を含む)

ネイティブ Rust

パン、ズーム、ストリーミング中のフレームあたりのヒープアロケーション

定常状態

WebAssembly パッケージのサイズ(gzip)

全機能込み

ブラウザの数値は Google Chrome + WebGPU、1,000 万本の読み込みはネイティブ Rust での計測です。バーは各数値の目標に対する割合を示します(読み込み 300 ms、アロケーションなし、パッケージ 1.5 MB)。

サンプル

320 のサンプル、
20 のユースケース。

どのサンプルも FerroChart がブラウザ上でリアルタイムに描画するチャートで、ソースコード付きです。データはすべて合成データです。

バーリプレイ
リアルタイムストリーム
ローソク足と出来高
01

プライスアクション

28 件のサンプル →

あらゆる市場のローソク足、バー、ラインをリアルタイムでストリーミング表示します。

板のヒートマップ
デルタフットプリント
フットプリント
04

オーダーフロー

20 件のサンプル →

フットプリント、板のヒートマップ、マーケットプロファイルをコンピュートシェーダーで描画します。

インプライド・ボラティリティ・ベーシス
ロング/ショート比率・CVD
資金調達率・建玉・清算
06

暗号資産デリバティブ

15 件のサンプル →

資金調達率、建玉、清算、ベーシスを価格の下のペインに表示します。

リスクリバーサル・バタフライ
満期までの予想変動幅
インプライド対実現ボラティリティ・IVランク
12

オプションとボラティリティ

18 件のサンプル →

インプライド対実現ボラティリティ、スキュー、予想変動幅、ディーラーのエクスポージャーを時系列で表示します。

同時ドローダウン
アンダーウォーターカーブ・最大ドローダウン
資産曲線・ドローダウン
16

ポートフォリオ・リスク・クオンツ

24 件のサンプル →

資産曲線、ドローダウン、ローリング統計、ファクターリサーチ、リスクチェックを扱います。

グループ縦棒
積み上げ縦棒
100%積み上げエリア
19

カスタムシリーズとプラグイン

11 件のサンプル →

積み上げ、グループ、箱ひげ、ブラシ選択のシリーズを、同じGPUフレーム上のレイヤープラグインで描画します。

20 のユースケースをすべて見る

プライスアクション

足の種類と変換

テクニカル分析

オーダーフロー

執行とトレードレビュー

暗号資産デリバティブ

オンチェーン

DeFiとAMM

ミームコインとウォレット

株式とファンダメンタルズ

中国A株

オプションとボラティリティ

金利・為替・マクロ

先物とコモディティ

ファンドとETF

ポートフォリオ・リスク・クオンツ

プライベート市場と個人の資産管理

予測市場

カスタムシリーズとプラグイン

ラボとフラッグシップ

特長

市場データのための設計。

01

クロスプラットフォームの描画

ひとつの Rust コアで、ブラウザでは WebGPU と WebGL2、ネイティブアプリでは wgpu により Metal、Vulkan、DirectX 12、サーバーでは CPU レンダラーを使います。ゴールデンイメージテストで各バックエンドの出力を揃えています。

02

データ量に左右されない性能

足のデータは GPU 上に置かれ、座標変換はシェーダーで行うため、パンやズームでは少数の uniform を更新するだけです。LOD ピラミッドにより数千万本の足でも軽快に動きます。

03

30 の組み込みインジケーター

SMA から一目均衡表まで、移動平均、チャネル、オシレーター。値はティックごとにインクリメンタルに更新され、参照データでテストされています。

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 のオープンソース。ブラウザからトレーディングデスクまで。