Shadow-to-Body Ratio
Install and import#
npm install fintech-algorithmsimport { shadowToBodyRatio } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/shadow-to-body-ratio";Signature#
shadowToBodyRatio(inputs)Decomposes one OHLC candle and reports raw and tick-stabilized shadow-to-body ratios without hiding the zero-body case.
Parameters#
| Name | Type | Notes |
|---|---|---|
inputs | { candle: { open: number; high: number; low: number; close: number }; tick_size: number } | Record containing candle and positive tick_size fields as defined by the topic data contract. |
Returns#
{ state, body, upper_shadow, lower_shadow, range, tick_size, effective_body, upper_to_body, lower_to_body, upper_to_effective_body, lower_to_effective_body, upper_to_range, lower_to_range, dominant_shadow, dominant_shadow_ratio }
One diagnostic record. state is calculated for a nonzero body and zero-body when raw body ratios are undefined; no positional series is returned.
Errors#
- When the candle is invalid or tick_size is not positive — throws
Complexity: time O(1),
space O(1).
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
{
"candle": {
"open": 100,
"high": 105,
"low": 97,
"close": 102
},
"tick_size": 0.1
}Call#
shadowToBodyRatio(inputs)Returns#
object with 15 fields: state, body, upper_shadow, lower_shadow, range, tick_size, effective_body, upper_to_body, …
{
"state": "calculated",
"body": 2,
"upper_shadow": 3,
"lower_shadow": 3,
"range": 8,
"tick_size": 0.1,
"effective_body": 2,
"upper_to_body": 1.5,
"lower_to_body": 1.5,
"upper_to_effective_body": 1.5,
"lower_to_effective_body": 1.5,
"upper_to_range": 0.375,
"lower_to_range": 0.375,
"dominant_shadow": "balanced"
}Showing 14 of 15 fields.
Other exports#
This module also exports
calculate, gapClassification, trendContextFilter, doji, dragonflyDoji, gravestoneDoji, marubozu, spinningTop, hammer, hangingMan, invertedHammer, shootingStar, bullishEngulfing, bearishEngulfing, bullishHarami, bearishHarami, piercingLine, darkCloudCover, tweezerTop, tweezerBottom. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams#
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Chart Types: Candlestick, Line, Bar — CME Group
- Candlestick chart — Nasdaq
- Candlestick Settings — TA-Lib project
- Evidence boundary