Skip to main content

Configuration

Exports

NameKindDescription
WidgetIccandleComponentChart overlay + results iframe
WidgetIccandlePropsTypeProps for WidgetIccandle
WidgetIccandleChartRefsTypeRefs for highlight bars / generated-candle studies
WidgetLanguageTypeSupported locale codes
withPlayChartFunctionWraps a TradingView datafeed for replay bar injection
getCustomIndicatorsFunctionReturns iC Candle custom indicators (generated candles)
getGeneratedCandlesMaskColorFunctionTheme-aware mask color for generated candles

WidgetIccandle props

PropTypeRequiredDescription
chartWidgetIChartingLibraryWidget | nullYesLive TradingView widget (null until ready).
childrenReactNode | ((chartRefs) => ReactNode)YesChart UI, or render prop receiving WidgetIccandleChartRefs.
theme"light" | "dark" | "system"NoScanner chrome + iframe theme. "system" follows prefers-color-scheme.
languageWidgetLanguageNoUI + iframe locale. One of: en, zh, vi, th, ko, ja, mn, ru. Defaults to en.
onCloseResult() => voidNoCalled when the embed posts close-result.
iframeLoadedbooleanNoWhen false, disables scan / track actions until the results iframe is ready. Defaults to enabled behavior in the scanner.

IChartingLibraryWidget must be imported from your Charting Library typings — this package does not re-export TradingView types.

WidgetIccandleChartRefs

FieldDescription
highlightBarsRefBars used for highlight / selection overlays
generatedCandlesBackgroundStudyIdRefStudy id for the generated-candles background indicator
generatedCandlesStudyIdRefStudy id for the generated-candles indicator

withPlayChart(datafeed)

Required for chart replay / predict. Wraps your TradingView datafeed’s subscribeBars so the widget can:

  1. Inject replay bars into the live tick stream when the embed posts play-chart or replay.
  2. Block live ticks while playback is active, so real-time updates do not overwrite predicted candles.

Signature

withPlayChart(datafeed: IBasicDataFeed): IBasicDataFeed
ArgumentTypeDescription
datafeedIBasicDataFeedReady datafeed instance (must expose onReady).

Usage

import { withPlayChart } from "@iccandle/reactjs-widget";

datafeed: withPlayChart(myDatafeed),

Notes

  • The returned object is still a normal datafeed; only subscribeBars is wrapped.
  • Pair with getCustomIndicators — without both, replay / predict overlays will not work.

getCustomIndicators(theme?)

Registers iC Candle’s custom studies used to draw generated / predicted candles on top of the main series. Returns a Promise of TradingView CustomIndicator[] for custom_indicators_getter.

Signature

getCustomIndicators(theme?: "light" | "dark"): Promise<readonly CustomIndicator[]>
ArgumentTypeDefaultDescription
theme"light" | "dark""light"Pane mask color so predicted bars hide the underlying series. Must match the chart theme.

Studies returned

Study nameRole
Generated Candles Background - By iC CandleHidden mask layer that paints over real bars at predicted timestamps.
Generated Candles - By iC CandleVisible OHLC overlay (bullish #00dfb9 / bearish #ffb84d) for predicted candles.

WidgetIccandle creates and drives these studies via chartRefs (generatedCandlesBackgroundStudyIdRef, generatedCandlesStudyIdRef) when the embed sends replay / predict data.

Usage

import { getCustomIndicators } from "@iccandle/reactjs-widget";

const options: ChartingLibraryWidgetOptions = {
// ...
datafeed: withPlayChart(yourDatafeed),
custom_indicators_getter: () => getCustomIndicators("light"),
};

Keep getCustomIndicators(theme) in sync with the chart widget theme (and preferably with WidgetIccandle’s theme prop). Use getGeneratedCandlesMaskColor(theme) if you need the same mask color elsewhere (#ffffff light / #131722 dark).

Together with withPlayChart

HelperJob
withPlayChartLets the widget push bars into the datafeed and mute live ticks during playback.
getCustomIndicatorsDraws the predicted candle visuals (mask + colored OHLC) as custom studies.

Both are required for replay / predict from the results iframe.

Auth and storage

KeyPurpose
iccandle_tokenBearer token for scan cache, pattern tracker, and related APIs. Set by the embed via sign-in-success.
search-filterScanner advanced options (symbols, top_k, period, probability).
tv:selected-news-eventsJSON array of news events used as timescale marks.
tv:clicked-news-eventLast clicked calendar event for mark highlighting.
tv:latest-symbolLast chart symbol (used by the demo app / fallbacks).

postMessage bridge

Messages are accepted only from the results origin (https://embed-iccandle-app.iccandle.ai).

DirectionType / actionEffect
Embed → parentplay-chartInject / clear replay candles on the chart
Embed → parentloadingToggle scanner loading UI
Embed → parentsign-in-successPersist iccandle_token from payload.id_token
Embed → parentclose-resultClears play state; calls onCloseResult
Embed → parentpattern_selected / custom_pattern_selectedDraw date range for the compared pattern
Embed → parentclear_pattern_selected / clear_custom_pattern_selectedRemove pattern date range
Embed → parenteventClickedCenter chart, draw event line, show mark
Embed → parentreplayStart / stop event replay candles
Embed → parentback / back-to-similar-eventsClear event line / replay
Embed → parentnav-clickHide scanner on /news; restore otherwise
Parent → embedparent-originHost origin for Stripe return
Parent → embedpayment-successRefresh subscription after checkout

Optional: timescale marks (news/events)

If your datafeed implements getTimescaleMarks, surface stored events as marks:

getTimescaleMarks: async (
symbolInfo,
from,
to,
onResult,
) => {
const marks = [];
try {
const allNewsEvents = JSON.parse(
localStorage.getItem("tv:selected-news-events") || "[]",
);

allNewsEvents?.forEach(({ id, timestamp, event_name, currency }) => {
if (!id || !Number.isFinite(timestamp) || timestamp <= 0) return;
if (marks.some((m) => String(m.id) === String(id))) return;

marks.push({
id,
time: timestamp / 1000,
color: "green",
label: event_name.slice(0, 1) || "N",
tooltip: [event_name],
...(currency ? { imageUrl: `/images/symbols/${currency}.svg` } : {}),
showLabelWhenImageLoaded: true,
});
});
} catch {
/* ignore */
}
onResult(marks);
};

Adjust paths and types to match your app and TradingView typings.

Theming

Scanner UI uses CSS variables on .iccandle-selector-widget:

  • --iccandle-primary
  • --iccandle-primary-gradient-end
  • --iccandle-background
  • --iccandle-border
  • --iccandle-text
  • --iccandle-secondary
  • --iccandle-font

Light and dark defaults live in the bundled stylesheet. The theme prop toggles the .iccandle-dark class and is forwarded to the iframe.

Behavior summary

  • Subscribes to chart readiness, resolution, symbol changes, and drawing events.
  • Manages a date_range multipoint drawing so the user can adjust the bar window (default: 25 bars).
  • Posts candles to https://scan-service.iccandle.ai/cacheCandle, then navigates the results iframe with query params (ws, tk, et, symbol, tf, cid, filters, theme).
  • Hosts the results iframe at https://embed-iccandle-app.iccandle.ai and syncs via postMessage.

License

MIT. TradingView Charting Library is subject to its own license from TradingView.