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

indicator-market-structure-lines

v0.0.13

Published

OHLCV indicator, adds info about recent highs/lows above/below the current price

Downloads

3

Readme

indicator-market-structure-lines

adds marketStructure field to each candle in an [{open high low close volume}] array, with info about recent highs/lows above/below the current price

experimental, use at your own risk

Installation

npm i indicator-market-structure-lines

Usage

var candles = require('candles-sample-aapl').loadNMinuteCandles(45).slice(100);

var appendRecentMarketStructure = require('indicator-market-structure-lines').appendRecentMarketStructure;

var nPeriods = 9; //default 8
var keepNRecent = 3; //default 3
appendRecentMarketStructure(candles, nPeriods, keepNRecent); //works in-place

//each candle now has a field called .marketStructure with sub-field nPeriods

console.log(candles.slice(-1)[0].marketStructure[nPeriods+'']);

//result format:
// {
//     isChoch: false, //candle is change of character
//     isBos: false,   //candle is break of structure
//     isHigh: undefined, //undefined unless we go back at least nPeriods periods!
//     isLow: undefined,  //undefined unless we go back at least nPeriods periods!
//     recentHighs: [
//         { price: 148.9805, candlesAgo: 13, i: 241, isHigh: true },
//         { price: 151.74, candlesAgo: 47, i: 207, isHigh: true }
//     ],
//     recentLows: [
//         { price: 140.39, candlesAgo: 21, i: 233, isLow: true },
//         { price: 146.9376, candlesAgo: 56, i: 198, isLow: true }
//     ],
//     recentHighsAndLows: [
//         { price: 148.9805, candlesAgo: 13, i: 241, isHigh: true },
//         { price: 140.39, candlesAgo: 21, i: 233, isLow: true },
//         { price: 151.74, candlesAgo: 47, i: 207, isHigh: true },
//         { price: 146.9376, candlesAgo: 56, i: 198, isLow: true }
//     ],
//     structureAbove: [
//         { price: 148.9805, candlesAgo: 13, i: 241, isHigh: true },
//         { price: 151.74, candlesAgo: 47, i: 207, isHigh: true }
//     ],
//     structureBelow: [
//         { price: 140.39, candlesAgo: 21, i: 233, isLow: true },
//         { price: 146.9376, candlesAgo: 56, i: 198, isLow: true }
//     ],
//     structuresCovered: [], //similar format to above, structs that the current candle touches
//     structuresCoveredTotal: 0, //len of above
//     structuresCoveredTotalHighs: 0, //len of above but filtered by highs
//     structuresCoveredTotalLows: 0, //len of above but filtered by lows
//     structuresCoveredScore: 0, //sum of [each in structuresCovered].candlesAgo
//     structuresCoveredScore2: 0,  //sum of [each in structuresCovered].candlesAgo^2
//     marketCharacter: 'bear' //or "bull" --- was the most recent change of character bearish or bullish?
// }

//can also add liquidity sweep info [slow!]

// var LiquiditySweepTracker = require('./index.js').LiquiditySweepTracker;
// LiquiditySweepTracker.addCandles(candles);

//add labels to candles to show liquidity sweeps on chart

// candles=candles.map(function(c,i ){
//     var nextCandle = candles[i+1];
//     if(nextCandle){
//         if(c.buySideLiquiditySwept){ //see also buySideLiquiditySweptRolling
//             if(!nextCandle.buySideLiquiditySwept){
//                 if(c.buySideLiquiditySwept>nPeriods)
//                 c.labelBuy = "B" + c.buySideLiquiditySwept
//             }
//         }
//
//         if(c.sellSideLiquiditySwept){
//             if(!nextCandle.sellSideLiquiditySwept){
//                 if(c.sellSideLiquiditySwept>nPeriods)
//                 c.labelSell = "S" + c.sellSideLiquiditySwept
//             }
//         }
//     }
//     return c;
// });

// the rest of the code just for charting etc...

var {drawChartForCandles,saveChartForCandles} = require('ohlc-chart-simple');

candles = candles.map(function(candle,index){
    //add shifted signal to the graph as an indicator
    var ms = candle.marketStructure[nPeriods+''];
    if(ms.structureAbove.length>0){
        var signalS = ms.structureAbove[0].price;
        candle.indicators = {
            ...candle.indicators,
            "H_LINE": signalS,
            "H_LINE_color": [0,128,0],
            "H_LINE_thickness": 0//ms.marketCharacter == 'bull' ? 2 : 1
        }
    }

    if(ms.structureBelow.length>0){
        var signalS = ms.structureBelow[0].price;
        candle.indicators = {
            ...candle.indicators,
            "L_LINE": signalS,
            "L_LINE_color": [128,0,0],
            "L_LINE_thickness": 0//ms.marketCharacter == 'bear' ? 2 : 1
        }
    }

    return candle;
});

var config = {
    w: Math.floor(1024/2),
    h: Math.floor(700/2),
    profileBucketsTotal: 64,
    profileBucketsWidth: 16,
    volumeBarsHeight: 64,
    bgColor: [255,255,255],

    //alternative to volume profile: arbitrary kernel density histogram
    kdePrices: candles.map(c=>[c.low, 1]), //[value, weight]
    // kdeBandwidthDollars: 0.01,
    kdeBandwidthPercent: 1.00,
    kdeIsGaussian: true, //false == kernel is triangular
    kdeColor: [0,0,255],

    skipDrawOhlcBars: false,
    skipDrawIndicators: false,
    skipDrawLegend: false,
    expandLegendText: false,
    expandTitle: false,
    expandPrice: false,
    skipDrawDate: true,
    skipDrawPrice: false,
    skipDrawPriceBars: false,
    title: "AAPL",
    filename: "./candlestick-chart.png",
}

saveChartForCandles(candles, config);

chart

stonks