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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cmike444/supply-and-demand-zones

v1.0.8

Published

A library for identifying supply and demand zones in candlestick data.

Readme

Supply and Demand Zones

A TypeScript library for identifying supply and demand zones in candlestick data. This library is designed for use in financial and trading applications, providing tools to analyze candlestick patterns and detect key market zones.

Features

  • Identify supply zones (e.g., Rally-Base-Drop, Drop-Base-Drop patterns).
  • Identify demand zones (e.g., Drop-Base-Rally, Rally-Base-Rally patterns).
  • Analyze candlestick data with utility functions for:
    • Calculating candle body size and range.
    • Determining bullish, bearish, decisive, and indecisive candles.
    • Detecting explosive candles.
  • Fully written in TypeScript with type definitions for strong typing.
  • Includes enums and constants for candlestick analysis.

Installation

Install the library via npm:

npm install supply-and-demand-zones

Usage

Importing the Library

You can import the library functions, types, and constants into your project:

import { identifyZones, candleBody, isBullishCandle, CandleType, DEFAULT_THRESHOLD } from 'supply-and-demand-zones';

Example: Identifying Supply and Demand Zones

import { identifyZones } from 'supply-and-demand-zones';

const candles = [
  { timestamp: 1, open: 100, high: 110, low: 95, close: 105 },
  { timestamp: 2, open: 105, high: 115, low: 100, close: 110 },
  { timestamp: 3, open: 110, high: 120, low: 105, close: 115 },
  // Add more candlestick data here...
];

const { supplyZones, demandZones } = identifyZones(candles);

console.log('Supply Zones:', supplyZones);
console.log('Demand Zones:', demandZones);

Example: Utility Functions

Calculate Candle Body Size

import { candleBody } from 'supply-and-demand-zones';

const candle = { timestamp: 1, open: 100, high: 110, low: 95, close: 105 };
console.log('Candle Body Size:', candleBody(candle)); // Output: 5

Check if a Candle is Bullish

import { isBullishCandle } from 'supply-and-demand-zones';

const candle = { timestamp: 1, open: 100, high: 110, low: 95, close: 105 };
console.log('Is Bullish:', isBullishCandle(candle)); // Output: true

Check if a Candle is Decisive

import { isDecisiveCandle } from 'supply-and-demand-zones';

const candle = { timestamp: 1, open: 100, high: 110, low: 95, close: 105 };
console.log('Is Decisive:', isDecisiveCandle(candle)); // Output depends on the threshold

Detect Explosive Candles

import { isExplosiveCandle } from 'supply-and-demand-zones';

const candle = { timestamp: 1, open: 100, high: 150, low: 95, close: 145 };
console.log('Is Explosive:', isExplosiveCandle(candle)); // Output: true

Example: Using Enums and Constants

Candle Types

import { CandleType } from 'supply-and-demand-zones';

console.log(CandleType.Bullish); // Output: 'Bullish'
console.log(CandleType.Bearish); // Output: 'Bearish'

Default Threshold

import { DEFAULT_THRESHOLD } from 'supply-and-demand-zones';

console.log('Default Threshold:', DEFAULT_THRESHOLD); // Output: 0.5

API Reference

Functions

identifyZones(candles: Candle[]): { supplyZones: SupplyZone[], demandZones: DemandZone[] }

Identifies supply and demand zones in an array of candlestick data.

  • Parameters:
    • candles: An array of Candle objects.
  • Returns:
    • An object containing supplyZones and demandZones.

candleBody(candle: Candle): number

Calculates the body size of a candlestick.

  • Parameters:
    • candle: A Candle object.
  • Returns:
    • The absolute difference between the close and open prices.

isBullishCandle(candle: Candle): boolean

Determines if a candlestick is bullish.

  • Parameters:
    • candle: A Candle object.
  • Returns:
    • true if the close price is greater than the open price, otherwise false.

isDecisiveCandle(candle: Candle, threshold?: number): boolean

Determines if a candlestick is decisive based on a threshold.

  • Parameters:
    • candle: A Candle object.
    • threshold: A number representing the minimum body size as a percentage of the total range (default: 0.5).
  • Returns:
    • true if the body size exceeds the threshold, otherwise false.

isExplosiveCandle(candle: Candle): boolean

Determines if a candlestick is explosive based on its range.

  • Parameters:
    • candle: A Candle object.
  • Returns:
    • true if the range exceeds a predefined threshold, otherwise false.

Types

Candle

Represents a single candlestick.

  • Properties:
    • timestamp: The time of the candlestick.
    • open: The opening price.
    • high: The highest price.
    • low: The lowest price.
    • close: The closing price.

SupplyZone

Represents a supply zone.

  • Properties:
    • start: The starting timestamp of the zone.
    • end: The ending timestamp of the zone.
    • priceRange: The price range of the zone.

DemandZone

Represents a demand zone.

  • Properties:
    • start: The starting timestamp of the zone.
    • end: The ending timestamp of the zone.
    • priceRange: The price range of the zone.

Enums

CandleType

Defines the type of a candlestick.

  • Values:
    • Bullish: Represents a bullish candlestick.
    • Bearish: Represents a bearish candlestick.

Constants

DEFAULT_THRESHOLD

The default threshold for determining decisive candles.

  • Value: 0.5

Contributing

Contributions are welcome! If you have ideas for improvements or new features, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.