NightVision Documentation
website·Indexed 31 days ago
https://nightvision.dev/Documentation for NightVision and NavyJS, featuring a comprehensive suite of built-in technical analysis indicators (such as MACD, RSI, and EMA), overlays, and a Script Engine. Includes detailed API references for Chart API, DataHub API, and the Script Engine standard library for building custom indicators and manipulating financial datasets.
What's inside NightVision
- NightVision is a highly customizable charting library designed for professional traders, specifically optimized for displaying candlestick and time-series data. It is a continuation of the TradingVueJS project, focusing on improved performance and better design decisions. While currently in active development with an evolving API, it provides a vanilla-js API that is compatible with any framework, including Vue, React, and Svelte.
Overview of Navy JS scripting
Navy JS is a scripting system for NightVision that combines a technical analysis (TA) scripting environment (similar to TradingView's Pine Script) with the ability to create custom overlays using the CanvasJS API. It allows for the implementation of unique charting ideas and mathematical functions that go beyond predefined primitives.Overview of NightVision Events system
The Events component is a foundation of the NightVision library, providing a high-performance communication mechanism for components, scripts, and external modules. Unlike standard Svelte or Vue events, these events introduce no delay, which is critical for responsive charting software.let chart = new NightVision() console.log(chart.events)Access and use the NightVision Layout object
TheLayoutobject is the central descriptor for a chart's positions, sizes, and markups. A new Layout object is created every time the chart updates to recalculate grids, scales, precisions, and mapping functions. It is accessible via thechartreference.let chart = new NightVision() console.log(chart.layout)Implement an Area chart overlay
The Area overlay creates a stylized area chart similar to the Apple Stocks app. It expects data as an array of tuples containing a timestamp and a value.// Data format: [<timestamp>, <value>] const data = [ [1625097600000, 150.25], [1625184000000, 155.10], // ... ];Access and use the NightVision MetaHub
The MetaHub is a central repository for properties that specify how elements are rendered. It listens to events emitted by layers and stores information used by layout-building algorithms to adjust the output. You can access the current meta state via thechart.metaproperty.let chart = new NightVision(); console.log(chart.meta);Understand NavyJS Indicator Script core concepts
Indicator scripts use the Script Engine to perform mathematical functions on chart data and generate overlays.
Timeseries (TS): Data is handled as regular JavaScript arrays with
__id__and__len__properties. New elements are added to the beginning of the array, and the array size is limited by the__len__property.Standard Library: Built-in functions like
atr(),bb(),cci(),cmo(),dmi(), andema()are available. These functions can be nested (e.g., using the output of one as the input for another).// Example of nesting built-in functions Spline(sma(atr(close, 14), 20))Understand the role of DataHub in NightVision
DataHub acts as the central container for the main dataset in NightVision. It is responsible for producing theview(the current visible subset of data), listening to internal update events (such as thedisplayflag for overlays), and providing helper functions to simplify data access.let chart = new NightVision(); console.log(chart.hub);Manage chart rendering and scales
NightVision includes a flexible scale system and a layered rendering architecture:
- Scales: Supports mixing different datasets on the same pane, switching between datasets, and moving scales to the left side of the chart.
- Multiple Renderers: Each renderer is an instance of CanvasJS with multiple overlay layers. Renderers can be stacked on top of each other to achieve independent rendering processes.
Access and interact with NightVision core elements
NightVision provides access to its internal components through the main chart wrapper object. Key core elements include:
DataHub: Main data wrapperLayout: Configuration for grids and scalesScripts: NavyJs script collectionMetaHub: Meta information about grids and scalesDataScan: Meta information about the main dataCursor: Current cursor position and valuesEvents: Event Hub
Note that
DataHub,Scripts,MetaHub,DataScan, andEventsare implemented as singletons and can be imported anywhere in the application to facilitate interaction between different chart instances.let chart = new NightVision(); // Access panes via the DataHub let panes = chart.hub.panes(); // Access current cursor position let x = chart.cursor; // Emit an event via the Event Hub chart.events.emit('update-layout');Understand the Nightvision top-level data structure
The Nightvision dataset acts as the central source of truth. It follows a hierarchical structure where the top level contains an array of panes, and each pane contains an array of overlays. To update the chart state using the Low-Level API, you must first modify the dataset and then call the corresponding update method(s).{ // Defines panes (vertical sections of the chart) panes: [ { // Defines overlays (layers of graphics) overlays: [ { name: "…", // Overlay name type: "…", // Overlay type data: […], // Time-series: [[<time>, value, …], …] settings: {…}, // Overlay settings props: {…}, // Overlay props // ... } ], settings: {…}, // Pane settings } ] }Implement VolumeDelta overlay for volume and delta visualization
The VolumeDelta overlay displays volume bars and calculates the delta as the difference between buy volume and sell volume (delta = buyVol - sellVol).