Skip to content
EliteChart

findNearestBar

Documentation


Documentation / @elitechart/core / findNearestBar

code
function findNearestBar(bars, target): Bar | null;

Defined in: magnet/magnet.ts:109

Binary-search for the bar whose time is closest to target. Returns null when bars is empty.

Parameters

bars

readonly Bar[]

target

TimestampMs

Returns

Bar | null

Example

code
import { findNearestBar, asTimestampMs } from '@elitechart/core';
const b = findNearestBar(bars, asTimestampMs(Date.now()));