@cmike444/supply-and-demand-zones
v1.0.8
Published
A library for identifying supply and demand zones in candlestick data.
Maintainers
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-zonesUsage
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: 5Check 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: trueCheck 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 thresholdDetect 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: trueExample: 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.5API Reference
Functions
identifyZones(candles: Candle[]): { supplyZones: SupplyZone[], demandZones: DemandZone[] }
Identifies supply and demand zones in an array of candlestick data.
- Parameters:
candles: An array ofCandleobjects.
- Returns:
- An object containing
supplyZonesanddemandZones.
- An object containing
candleBody(candle: Candle): number
Calculates the body size of a candlestick.
- Parameters:
candle: ACandleobject.
- Returns:
- The absolute difference between the
closeandopenprices.
- The absolute difference between the
isBullishCandle(candle: Candle): boolean
Determines if a candlestick is bullish.
- Parameters:
candle: ACandleobject.
- Returns:
trueif thecloseprice is greater than theopenprice, otherwisefalse.
isDecisiveCandle(candle: Candle, threshold?: number): boolean
Determines if a candlestick is decisive based on a threshold.
- Parameters:
candle: ACandleobject.threshold: A number representing the minimum body size as a percentage of the total range (default:0.5).
- Returns:
trueif the body size exceeds the threshold, otherwisefalse.
isExplosiveCandle(candle: Candle): boolean
Determines if a candlestick is explosive based on its range.
- Parameters:
candle: ACandleobject.
- Returns:
trueif the range exceeds a predefined threshold, otherwisefalse.
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.
