EliteChart supports two alert kinds:
- Price alerts — fire when the symbol's price crosses, touches,
or stays inside a range.
- Anchored alerts — fire when the price reaches a
drawing-anchored level (a trend line, a Fibonacci level, etc.).
Alerts live in useChartStore.alerts, surface in the
right-sidebar Alerts panel, and emit a
custom event when their condition matches.
Quick example
'use client';
import { useEffect } from 'react';
import { EliteChart, useChartStore } from '@elitechart/elitechart';
import '@elitechart/elitechart/styles.css';
export default function Page() {
useEffect(() => {
useChartStore.getState().addAlert({
id: 'btc-70k',
kind: 'price',
symbol: 'BTCUSD',
condition: 'crosses-up',
price: 70_000,
message: 'BTC crossed 70k',
});
return useChartStore.subscribe((state, prev) => {
const fired = state.alertFired;
if (fired !== null && fired !== prev.alertFired) {
console.log('Alert fired:', fired);
}
});
}, []);
return <EliteChart symbol="BTCUSD" timeframe="1h" />;
}
How it works
Each alert is a record:
interface Alert {
readonly id: string;
readonly kind: 'price' | 'anchored';
readonly symbol: string;
readonly condition:
| 'crosses-up' | 'crosses-down' | 'touches'
| 'enters-range' | 'exits-range';
readonly price?: number; // for kind: 'price'
readonly drawingId?: string; // for kind: 'anchored'
readonly message: string;
readonly armed: boolean;
}
The chart watches every incoming Bar from the datafeed against
every armed alert. On a match it sets alertFired = alertId, which
your subscribe-handler picks up. The alert auto-disarms after firing
(prevents a single crossing firing repeatedly).
Variations
Anchored alert — fire when price touches a horizontal line
const drawingId = 'support-line';
useChartStore.getState().addAlert({
id: 'support-test',
kind: 'anchored',
drawingId,
symbol: 'BTCUSD',
condition: 'touches',
message: 'Support tested',
});
Re-arm an alert after firing
useChartStore.getState().patchAlert('btc-70k', { armed: true });
API
| Action | Method |
|---|
| Add | useChartStore.addAlert(alert) |
| Patch | useChartStore.patchAlert(id, patch) |
| Remove | useChartStore.removeAlert(id) |
| Read fire events | subscribe to useChartStore.alertFired |