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
ספריית Pine
ברוח האמיתית של TradingView, המחבר לפרסם את הקוד של Pine הזה כספרייה בקוד פתוח, כך שמתכנתים אחרים בקהילתנו יעשו שימוש חוזר. כל הכבוד למחבר! ניתן להשתמש בספרייה הזו באופן פרטי או בומים בקוד פתוח, אך השימוש בחוזר בקוד הזה בפרסומים כפוף ל-כללי הבית.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
ספריית Pine
ברוח האמיתית של TradingView, המחבר לפרסם את הקוד של Pine הזה כספרייה בקוד פתוח, כך שמתכנתים אחרים בקהילתנו יעשו שימוש חוזר. כל הכבוד למחבר! ניתן להשתמש בספרייה הזו באופן פרטי או בומים בקוד פתוח, אך השימוש בחוזר בקוד הזה בפרסומים כפוף ל-כללי הבית.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.