npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ohlc-chart-simple

v0.0.1131

Published

simple ohlc candlestick charts with volume profile for Node.js

Downloads

40

Readme

ohlc-chart-simple

simple ohlc candlestick charts with volume profile for Node.js

Installation

npm i ohlc-chart-simple

Usage

var {drawChartForCandles,saveChartForCandles,
    generateRandomCandles, 
    //use these 2 funcs to print candles to console...
    printCandles, printCandlesColored} = require('ohlc-chart-simple');

var candles = [...];

//format of candles [
// {
//     open: 1.0,
//     high: 1.0,
//     low: 1.0,
//     close: 1.0,
//     date: "anything"
// } ...
// ]

candles = candles.map(function(candle){
    //candle.date is arbitrary string used to label current date in upper right corner
    //ex candle.date = moment.unix(candle.timestampUnix).format("YYYY-MM-DD HH:mm");

    //setting candle.title overwrites the graph title. nice for animations.
    //candle.title = "hey";

    //additional lines for indicators can be added by adding .indicators["NAME"], .indicators["NAME_color"], .indicators["NAME_thickness"]
    //in this example we add a thick blue line for candle midPts, and a thin pink line of candle lows-0.1%
    candle.indicators = {
        midPt: (candle.low+candle.high)/2.0,
        midPt_color: [0,0,255], //fields ending with "_color" specific color [default red]
        midPt_thickness: 1, //fields ending with "_thickness" specific line 'radius' [default 2]

        "0.1% lower": candle.low*0.999,
        "0.1% lower_color": [255,0,255], //pink
        "0.1% lower_thickness": 0 //0 gives single-pixel line
    }
    return candle;
});

//config optional; default params shown
var config = {
    w: 1024,
    h: 700,
    rects: [], //rectangles {minPrice,maxPrice,startIndex,endIndex,color,filled,thickness} -- example {minPrice: 140, maxPrice: 145, startIndex:5, endIndex: 15, color: [255,0,0], filled: true, thickness:0}
    rectsBelow: [], //same as rects but drawn BEHIND the bars, price lines, text, etc. 
    lines: [], //draw lines on the chart {startPrice, endPrice, startIndex, endIndex, color: [0,0,0], thickness:0}
    profileBucketsTotal: 32,
    profileBucketsWidth: 64, //set to zero to skip VP render 
    volumeBarsHeight: 32,
    bgColor: [255,255,255],

    //alternative to volume profile: arbitrary kernel density histogram
    //uncommenting these will replace VP with KDE graph of the same width
    // kdePrices: candles.map(c=>[c.low, 1]),
    // kdeBandwidthDollars: 0.00,
    // kdeBandwidthPercent: 1.00,
    // kdeIsGaussian: true, //false == kernel is triangular 
    
    skipDrawOhlcBars: false,
    skipDrawIndicators: false,
    skipDrawLegend: false,
    expandLegendText: true,
    expandTitle: true,
    expandPrice: true,
    skipDrawDate: false,
    skipDrawPrice: false,
    skipDrawPriceBars: false,
    title: "untitled",
    filename: "candlestick-chart.png",
    canvas: null, //reuse existing canvas 
    candlePaddingVerticalDollars: 0.01, //add vertical whitespace to candles, in dollars
}

saveChartForCandles(candles, config);
//var canvas = drawChartForCandles(candles, config); //get pixel canvas with image data from require('pixel-draw')

chart1

note: light blue bar is volume POC, light green bar is VWAP over the range of the chart

chart2

smaller example

chart3

simpler example

chart4

example including rectangle, line, KDE graph [see test.js]

See Also

stonks