Control
Chart API (onReady)
onReady gives you an object to control the chart from your own code and UI.
"use client";
import { useRef } from "react";
import { FxChart } from "@fx-charting/max";
export function TradingScreen() {
const chart = useRef(null);
return (
<>
<button onClick={() => chart.current.setSymbol("XAUUSD")}>Gold</button>
<button onClick={() => chart.current.addIndicator("ema", { length: 50 })}>EMA 50</button>
<FxChart onReady={(api) => (chart.current = api)} />
</>
);
}| Method | Description |
|---|---|
setSymbol(name) | Load a symbol on the active chart (returns its info). |
setInterval(i) / setChartType(t) / setTheme(t) | Change the view. |
setSettings(patch) | e.g. { timezone: "Europe/London", showBid: true, upColor: "#26a69a" } |
addIndicator(type, params?) → id | "rsi", "ema", "macd", "bb", … (see Indicators). |
updateIndicator(id, patch) / removeIndicator(id) | Change or remove one. |
getState() | { symbol, interval, chartType, theme, indicators, settings, layout } |
getBars() | Bars of the active chart. |
screenshot(type?) | PNG (or other type) data URL of the chart. |
placeOrder(order) → error | null | Max: { side, type, lots, price?, sl?, tp? } on the active symbol. |
closePosition(id) / closeAll(symbol?) / cancelOrder(id) / modifyPosition(id, { sl, tp }) | Max. |
getPositions() / getOrders() / getHistory() | Max: the account. |
runScript({ code, language, name, inputs }) / stopScript() | Max: run MQL5 or Pine Script. |
togglePanel(name) | watchlist, alerts, trading, dataWindow, experts. |
▶ Live example — buttons calling the API