PINE LIBRARY
TPOLib

Library "TPOLib"
TPOLib — Classical Time Price Opportunity (TPO) primitives.
Provides tick/row conversion, POC/Value Area calculation, TPO letter encoding,
Initial Balance tracking, and profile shape classification.
Note: Function bodies for f_price_to_tick, f_tick_to_row, f_row_to_price,
f_calc_row_ticks, f_poc_from_vals, f_value_area, and f_find_key_sorted are
copied from TPOSmartMoneyLib/3 (immutable on TradingView). No extraction or
migration - legacy consumers unaffected.
Architecture: L0 (no library dependencies, uses ta.* and math.* primitives only)
f_price_to_tick(p)
Convert price to tick
Parameters:
p (float): Price value
Returns: Tick value
f_tick_to_row(t, row_ticks_in)
Convert tick to row
Parameters:
t (int): Tick value
row_ticks_in (int): Number of ticks per row
Returns: Row index
f_row_to_price(row, row_ticks_in)
Convert row to price (midpoint)
Parameters:
row (int): Row index
row_ticks_in (int): Number of ticks per row
Returns: Price at row midpoint
f_calc_row_ticks(natr_ref, row_gran_mult)
Calculate dynamic row size based on normalized ATR
Parameters:
natr_ref (float): Daily normalized ATR reference value
row_gran_mult (float): Row granularity multiplier
Returns: Number of ticks per row
f_poc_from_vals(keys, vals)
Calculate Point of Control from volume distribution
Parameters:
keys (array<int>): Sorted array of row keys
vals (array<float>): Array of volume values
Returns: POC row key
f_value_area(keys, vals, poc_key, va_pct)
Calculate Value Area from volume distribution
Parameters:
keys (array<int>): Sorted array of row keys
vals (array<float>): Array of volume values
poc_key (int): POC row key
va_pct (float): Value Area percentage (typically 0.70)
Returns: Tuple of [VAL_key, VAH_key]
f_find_key_sorted(keys, target)
Find key in sorted array using binary search
Parameters:
keys (array<int>): Sorted array of keys
target (int): Target key to find
Returns: Index of key, or -1 if not found
f_tpo_letter_idx(bracket_idx)
Get TPO letter for bracket index (A-Z, then AA-AZ, etc.)
Parameters:
bracket_idx (int): Bracket index (0-based)
Returns: Letter string
f_initial_balance_from_brackets(brackets, ib_bracket_count, row_ticks)
Calculate Initial Balance from first N brackets
Parameters:
brackets (array<TPOBracket>): Array of TPOBracket (sorted by time)
ib_bracket_count (int): Number of brackets in IB period (typically 2 for 1hr)
row_ticks (int): Number of ticks per row
Returns: InitialBalance
f_detect_tpo_singles(brackets)
Detect TPO singles (rows with only one TPO print)
Parameters:
brackets (array<TPOBracket>): Array of TPOBracket
Returns: Array of row indices that are singles
f_classify_profile(poc, val, vah, range_low, range_high)
Classify profile shape based on POC position and VA width
Parameters:
poc (int): POC row
val (int): VAL row
vah (int): VAH row
range_low (int): Lowest row in profile
range_high (int): Highest row in profile
Returns: ProfileShape
TPOBracket
TPO bracket (single time period at a price level)
Fields:
letter (series string): Letter identifier (A-Z for 30min brackets in RTH session)
row (series int): Row index (price level)
volume (series float): Volume accumulated in this bracket
ValueArea
Value Area calculation result
Fields:
poc (series int): Point of Control (row with highest volume)
val (series int): Value Area Low (row)
vah (series int): Value Area High (row)
poc_volume (series float): Volume at POC
va_volume (series float): Total volume in Value Area
InitialBalance
Initial Balance (first hour of RTH session)
Fields:
ib_high (series float): Highest price in IB period
ib_low (series float): Lowest price in IB period
ib_range (series float): IB range (high - low)
extended_up (series bool): IB extended upward
extended_down (series bool): IB extended downward
ProfileShape
Profile shape classification
Fields:
shape (series string): "normal", "b_shape", "p_shape", "d_shape", "neutral"
poc_position (series float): POC position relative to range (0.0=low, 1.0=high)
va_width (series float): Value Area width as % of total range
TPOLib — Classical Time Price Opportunity (TPO) primitives.
Provides tick/row conversion, POC/Value Area calculation, TPO letter encoding,
Initial Balance tracking, and profile shape classification.
Note: Function bodies for f_price_to_tick, f_tick_to_row, f_row_to_price,
f_calc_row_ticks, f_poc_from_vals, f_value_area, and f_find_key_sorted are
copied from TPOSmartMoneyLib/3 (immutable on TradingView). No extraction or
migration - legacy consumers unaffected.
Architecture: L0 (no library dependencies, uses ta.* and math.* primitives only)
f_price_to_tick(p)
Convert price to tick
Parameters:
p (float): Price value
Returns: Tick value
f_tick_to_row(t, row_ticks_in)
Convert tick to row
Parameters:
t (int): Tick value
row_ticks_in (int): Number of ticks per row
Returns: Row index
f_row_to_price(row, row_ticks_in)
Convert row to price (midpoint)
Parameters:
row (int): Row index
row_ticks_in (int): Number of ticks per row
Returns: Price at row midpoint
f_calc_row_ticks(natr_ref, row_gran_mult)
Calculate dynamic row size based on normalized ATR
Parameters:
natr_ref (float): Daily normalized ATR reference value
row_gran_mult (float): Row granularity multiplier
Returns: Number of ticks per row
f_poc_from_vals(keys, vals)
Calculate Point of Control from volume distribution
Parameters:
keys (array<int>): Sorted array of row keys
vals (array<float>): Array of volume values
Returns: POC row key
f_value_area(keys, vals, poc_key, va_pct)
Calculate Value Area from volume distribution
Parameters:
keys (array<int>): Sorted array of row keys
vals (array<float>): Array of volume values
poc_key (int): POC row key
va_pct (float): Value Area percentage (typically 0.70)
Returns: Tuple of [VAL_key, VAH_key]
f_find_key_sorted(keys, target)
Find key in sorted array using binary search
Parameters:
keys (array<int>): Sorted array of keys
target (int): Target key to find
Returns: Index of key, or -1 if not found
f_tpo_letter_idx(bracket_idx)
Get TPO letter for bracket index (A-Z, then AA-AZ, etc.)
Parameters:
bracket_idx (int): Bracket index (0-based)
Returns: Letter string
f_initial_balance_from_brackets(brackets, ib_bracket_count, row_ticks)
Calculate Initial Balance from first N brackets
Parameters:
brackets (array<TPOBracket>): Array of TPOBracket (sorted by time)
ib_bracket_count (int): Number of brackets in IB period (typically 2 for 1hr)
row_ticks (int): Number of ticks per row
Returns: InitialBalance
f_detect_tpo_singles(brackets)
Detect TPO singles (rows with only one TPO print)
Parameters:
brackets (array<TPOBracket>): Array of TPOBracket
Returns: Array of row indices that are singles
f_classify_profile(poc, val, vah, range_low, range_high)
Classify profile shape based on POC position and VA width
Parameters:
poc (int): POC row
val (int): VAL row
vah (int): VAH row
range_low (int): Lowest row in profile
range_high (int): Highest row in profile
Returns: ProfileShape
TPOBracket
TPO bracket (single time period at a price level)
Fields:
letter (series string): Letter identifier (A-Z for 30min brackets in RTH session)
row (series int): Row index (price level)
volume (series float): Volume accumulated in this bracket
ValueArea
Value Area calculation result
Fields:
poc (series int): Point of Control (row with highest volume)
val (series int): Value Area Low (row)
vah (series int): Value Area High (row)
poc_volume (series float): Volume at POC
va_volume (series float): Total volume in Value Area
InitialBalance
Initial Balance (first hour of RTH session)
Fields:
ib_high (series float): Highest price in IB period
ib_low (series float): Lowest price in IB period
ib_range (series float): IB range (high - low)
extended_up (series bool): IB extended upward
extended_down (series bool): IB extended downward
ProfileShape
Profile shape classification
Fields:
shape (series string): "normal", "b_shape", "p_shape", "d_shape", "neutral"
poc_position (series float): POC position relative to range (0.0=low, 1.0=high)
va_width (series float): Value Area width as % of total range
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.