CandlePressure_UtilitiesCandlePressure_Utilities is a lightweight Pine library for converting raw OHLC candle structure into a normalized candle-pressure score, buy/sell percentage estimates, oscillator output, and compact display helpers.
The library is designed for scripts that want a reusable candle-pressure layer without rebuilding the same CLV/body/wick math every time.
It centralizes the pieces that commonly repeat across pressure-based scripts:
• close-location value / CLV calculation
• candle body dominance
• upper-vs-lower wick imbalance
• deadzone-filtered wick pressure
• normalized pressure output from -1 to +1
• buy/sell percentage conversion
• pressure oscillator conversion from -100 to +100
• alternate body/wick buy-sell allocation
• compact volume and relative-volume formatting
• table/label size and table-position helpers
• small percent and black/white text helpers
On the example chart, the pressure candles, pressure oscillator, buy/sell split, CLV/body/wick breakdown, alternate body/wick comparison, and compact table values are all materially driven by this library.
This library is intentionally focused on pure candle structure. It does not confirm trend, detect pivots, calculate RSI/DMI/ATR context, decide trade direction, or choose final signal logic for the calling script. Those layers remain script-level decisions.
➖Quick Start➖
Import the library near the top of your script in global scope, alongside any other imports, before calling its helpers.
Typical placement:
//@version=6
indicator(...) or strategy(...)
import MYNAMEISBRANDON/CandlePressure_Utilities/1 as cp
Replace /1 with the latest published version if a newer version is available.
The main helper for most scripts is candlePressureMetrics(), which returns:
• pressure
• buyPct
• sellPct
Example:
= cp.candlePressureMetrics(
open,
high,
low,
close,
volume)
string splitText = cp.fmtBuySellSplit(
buyPct,
sellPct,
volume)
float pressureOsc = cp.pressureOsc(
pressure)
The library uses standard OHLCV argument order:
open, high, low, close, volume
➖What The Library Measures➖
The default candle-pressure model uses:
• Wick Deadzone = 0.02
• CLV Weight = 0.55
• Body Weight = 0.30
• Wick Weight = 0.15
CLV measures where the close finished inside the candle range. Body contribution measures open-to-close directional dominance. Wick contribution measures lower-wick vs upper-wick imbalance.
The final pressure score is a weighted blend of those components, normalized from -1 to +1.
That pressure score can then be converted into buy/sell percentage estimates, a -100 to +100 pressure oscillator, candle-overlay colors, table values, labels, or dashboard outputs.
➖Function Reference➖
These helpers are grouped by purpose.
Most scripts will only need:
• candlePressureMetrics()
• fmtBuySellSplit()
• pressureOsc()
More advanced scripts can use the full component helpers for tables, tooltips, debug output, or custom pressure models.
➖Model + Math Helpers➖
modelDefaults()
Returns the default candle-pressure model values used by this library.
Returns:
Wick deadzone, CLV weight, body weight, wick weight
clamp(v, lo, hi)
Restricts a value between a lower and upper bound.
Parameters:
v (float): Input value
lo (float): Lower bound
hi (float): Upper bound
Returns:
Clamped value
safeDiv(numerator, denominator, fallback)
Safely divides two values and returns the fallback when division is not valid.
Parameters:
numerator (float): Numerator value
denominator (float): Denominator value
fallback (float): Value returned when division is unsafe
Returns:
numerator / denominator, or fallback when unsafe
➖Display + UI Helpers➖
fmtCompact(val, sigFigs, naText)
Formats large values into compact display text such as 1.5k, 2.4m, or 1.2b.
Parameters:
val (float): Value to format
sigFigs (simple int): Significant figures to keep
naText (simple string): Text returned when val is na
Returns:
Compact formatted string
fmtBuySellSplit(buyPct, sellPct, volumeValue)
Formats buy/sell percentages into rounded split text such as 62/38.
Parameters:
buyPct (float): Buy percentage
sellPct (float): Sell percentage
volumeValue (float): Volume value used to handle missing or no-volume bars
Returns:
Formatted buy/sell split text
contrastText(bg)
Chooses black or white text based on background brightness.
Parameters:
bg (color): Background color
Returns:
Readable contrast text color
stripLeadingZero(txt)
Removes the leading zero from decimal text.
Parameters:
txt (string): Input text
Returns:
Adjusted text, such as 0.25 -> .25 or -0.25 -> -.25
fmtRelVol(val, naText)
Formats relative volume with two decimals and strips the leading zero.
Parameters:
val (float): Relative volume value
naText (string): Text returned when val is na
Returns:
Formatted relative-volume text
pctChange(currentValue, baseValue)
Returns the percent change from a base value.
Parameters:
currentValue (float): Current or projected value
baseValue (float): Comparison baseline
Returns:
Percent change
fmtPctWhole(val, naText)
Formats a percent value as rounded whole-percent text.
Parameters:
val (float): Percent value
naText (string): Text returned when val is na
Returns:
Rounded percent string
pctInt(pct)
Rounds and clamps a percentage into 0–100 integer form.
Parameters:
pct (float): Percent value
Returns:
Integer percent from 0 to 100
pctIntVol(pct, volumeValue)
Rounds and clamps a percentage into 0–100 integer form, returning 0 on no-volume bars.
Parameters:
pct (float): Percent value
volumeValue (float): Volume value
Returns:
Integer percent from 0 to 100
tableTextSize(sizeText)
Converts user-facing table-size text into Pine table text-size enums.
Parameters:
sizeText (string): Size text. Expected values: "Tiny", "Small", "Normal", or "Large"
Returns:
Pine table text-size enum
labelSize(sizeText)
Converts user-facing label-size text into Pine label-size enums.
Parameters:
sizeText (string): Size text. Expected values: "Tiny", "Small", "Normal", "Large", or "Huge"
Returns:
Pine label-size enum
tablePos(posText)
Converts user-facing table-position text into Pine table position enums.
Parameters:
posText (string): Table position text
Returns:
Pine table position enum
bw(useBlack)
Returns black text when the condition is true, otherwise white.
Parameters:
useBlack (bool): Whether black text should be used
Returns:
Black or white text color
➖Candle Pressure Helpers➖
candlePressurePartsFull(openValue, highValue, lowValue, closeValue, wickDeadzone, weightClv, weightBody, weightWick)
Converts OHLC candle structure into the full normalized pressure component set.
Parameters:
openValue (float): Candle open
highValue (float): Candle high
lowValue (float): Candle low
closeValue (float): Candle close
wickDeadzone (float): Wick imbalance threshold below which wick contribution is forced to 0
weightClv (float): Weight assigned to the CLV component
weightBody (float): Weight assigned to the body component
weightWick (float): Weight assigned to the wick component
Returns:
CLV, body % of range, signed body term, raw wick imbalance, deadzoned wick imbalance, final pressure
Note:
wickDeadzone, weightClv, weightBody, and weightWick are optional. If omitted, the library uses its default model:
Wick Deadzone 0.02 / CLV 0.55 / Body 0.30 / Wick 0.15
candlePressureParts(openValue, highValue, lowValue, closeValue, wickDeadzone, weightClv, weightBody, weightWick)
Converts OHLC candle structure into the compact pressure component set.
Parameters:
openValue (float): Candle open
highValue (float): Candle high
lowValue (float): Candle low
closeValue (float): Candle close
wickDeadzone (float): Wick imbalance threshold below which wick contribution is forced to 0
weightClv (float): Weight assigned to the CLV component
weightBody (float): Weight assigned to the body component
weightWick (float): Weight assigned to the wick component
Returns:
CLV, body % of range, raw wick imbalance, deadzoned wick imbalance, final pressure
Note:
wickDeadzone, weightClv, weightBody, and weightWick are optional. If omitted, the library uses its default model:
Wick Deadzone 0.02 / CLV 0.55 / Body 0.30 / Wick 0.15
pressureToBuySell(pressure, volumeValue)
Converts normalized pressure into buy/sell percentages.
Parameters:
pressure (float): Candle pressure in the -1..+1 range
volumeValue (float): Volume value used to handle missing or no-volume bars
Returns:
Buy %, Sell %
pressureOsc(pressure)
Converts normalized pressure into a -100..+100 oscillator value.
Parameters:
pressure (float): Candle pressure in the -1..+1 range
Returns:
Pressure oscillator value
candlePressureMetrics(openValue, highValue, lowValue, closeValue, volumeValue, wickDeadzone, weightClv, weightBody, weightWick)
One-call convenience wrapper for scripts that need final pressure, buy %, and sell %.
Parameters:
openValue (float): Candle open
highValue (float): Candle high
lowValue (float): Candle low
closeValue (float): Candle close
volumeValue (float): Volume value used to handle missing or no-volume bars
wickDeadzone (float): Wick imbalance threshold below which wick contribution is forced to 0
weightClv (float): Weight assigned to the CLV component
weightBody (float): Weight assigned to the body component
weightWick (float): Weight assigned to the wick component
Returns:
Pressure, Buy %, Sell %
Note:
wickDeadzone, weightClv, weightBody, and weightWick are optional. If omitted, the library uses its default model:
Wick Deadzone 0.02 / CLV 0.55 / Body 0.30 / Wick 0.15
bodyWickRateBuyPct(openValue, highValue, lowValue, closeValue)
Returns an alternate buy percentage using body/wick structure only.
Parameters:
openValue (float): Candle open
highValue (float): Candle high
lowValue (float): Candle low
closeValue (float): Candle close
Returns:
Buy percentage
bodyWickRateBuySell(openValue, highValue, lowValue, closeValue, volumeValue)
Returns alternate body/wick buy and sell percentages.
Parameters:
openValue (float): Candle open
highValue (float): Candle high
lowValue (float): Candle low
closeValue (float): Candle close
volumeValue (float): Volume value used to handle missing or no-volume bars
Returns:
Buy %, Sell %
➖Important Notes➖
Candle Pressure is not order flow.
The buy/sell split produced by this library is an estimate derived from candle structure. It is not true bid/ask volume, footprint data, or exchange-level order flow.
The pressure model is intentionally pure OHLC structure:
• CLV measures where the close finished inside the candle range.
• Body contribution measures open-to-close directional dominance.
• Wick contribution measures lower-wick vs upper-wick imbalance.
• Final pressure is a weighted blend of those components.
Momentum filters such as RSI, DMI, ATR, trend state, relative volume, or multi-timeframe context should be added by the calling script when needed.
This library provides the reusable candle-pressure foundation only.
➖Release Notes➖
v1
Initial release of CandlePressure_Utilities.
This release provides a focused candle-pressure utility layer for Pine scripts that need reusable OHLC pressure calculations, buy/sell percentage estimates, pressure oscillator output, compact display formatting, and small table/label helper functions.
Included in this release:
• default candle-pressure model values
• safe math helpers
• compact number formatting
• buy/sell split formatting
• relative-volume formatting
• table/label size and table-position helpers
• percent and bias display helpers
• full candle-pressure component output
• compact candle-pressure component output
• pressure-to-buy/sell conversion
• pressure oscillator conversion
• alternate body/wick buy-sell allocation
The library is designed to stay focused on reusable candle-pressure mechanics. It does not decide trend, trade direction, signal confirmation, pivot structure, RSI/DMI filters, ATR filters, or final color logic. Calling scripts remain responsible for their own signal model and visual interpretation.
مكتبة Pine Script®






















