Skip to content
EliteChart

snapToOhlc

Documentation


Documentation / @elitechart/core / snapToOhlc

code
function snapToOhlc(
   bars, 
   pointerTime, 
   pointerPrice, 
   mode, 
   pixelDistance, 
   snapPixels?): MagnetResult;

Defined in: magnet/magnet.ts:55

Snap a pointer (time, price) to the nearest OHLC value.

pixelDistance(priceA, priceB) converts a price delta to pixel distance so the 'weak' threshold can be compared in screen space. The chart passes a closure around its viewport.

Parameters

bars

readonly Bar[]

pointerTime

TimestampMs

pointerPrice

Price

mode

MagnetMode

pixelDistance

(priceA, priceB) => number

snapPixels?

number = 10

Returns

MagnetResult

Example

code
import { snapToOhlc } from '@elitechart/core';
const r = snapToOhlc(bars, t, p, 'strong', (a, b) => Math.abs(vp.priceToY(a as never) - vp.priceToY(b as never)));
setCrosshairPrice(r.price);