PINE LIBRARY
已更新 biasHelper

biasHelpers: Core Engine for Bias Analytics against a set of Benchmarks
Overview
The `biasHelper` library is a highly optimized backend engine designed specifically for evaluating, tracking, and aggregating bias analytics across timeframes.
Built on strict Model-View-Controller (MVC) software architecture principles, this library encapsulates all complex mathematical processing, state caching, and string formatting. By offloading these responsibilities, it allows front-end indicators to remain exceptionally lightweight, mathematically pure, and dedicated entirely to UI visualization.
This library features built-in anti-repainting guardrails, deterministic pseudo-random evaluations, and dynamic memory allocation through User-Defined Types (UDTs).
---
Core Architecture & Design Philosophy
This library operates using two primary User-Defined Types (UDTs) that track the lifecycle of a trading session:
1. `SessionInfo`: The primary memory matrix. It tracks OHLC data, prevailing directional bias, Heikin-Ashi extensions, and cumulative hit/close counts.
2. `SessionLines`: The visual array tracker. It orchestrates the projection of structural support/resistance levels and evaluates live price touches against them.
By maintaining state inside these objects rather than utilizing global arrays, the library ensures O(1) time complexity during bar evaluation, resulting in lightning-fast execution even on dense chart histories.
---
Exported Types (UDTs)
`SessionInfo`
The core data structure for tracking session metrics and bias execution.
* **Price Tracking**: `prevHigh`, `prevLow`, `currentHigh`, `currentLow`, `currentOpen`.
* **Heikin-Ashi Anchors**: `prevHaOpen`, `prevHaClose`.
* **State Trackers**: `pushedUp` (bool), `currentBias` (int: 1 = Bullish, -1 = Bearish, 0 = Neutral).
* **Metric Accumulators**: `bullishCount`, `bearishCount`, `hitHighCount`, `hitLowCount`, `closeHighCount`, `closeLowCount`.
`SessionLines`
The spatial data structure for tracking visual levels and live touches.
* Lines: `highLine`, `lowLine`.
* Touch Booleans: `hitHighLine`, `hitLowLine`.
---
Data & State Management
`updateData(infoObj, isNew, pClose, cOpen, cHigh, cLow)`
The standard market structure logic handler. It evaluates historical structural breaks against the previous close to determine the prevailing directional bias without repainting.
* Parameters: Evaluates state using standard OHLC inputs and strictly anchors to `close[1]` (`pClose`) to guarantee real-time parity with historical states.
`updateBenchmarkData(infoObj, isNew, pClose, cOpen, cHigh, cLow, bType, tfSeconds)`
A dynamic routing matrix for alternative bias benchmarks.
* Supported `bType` Routing:
* `"MOM"`: Pure Candlestick Momentum (Close vs. Open).
* `"HA"`: Synthetic Heikin-Ashi Momentum evaluated securely within standard chart data.
* `"ABULL"` / `"ABEAR"`: Static directional evaluations (Always Bullish / Always Bearish).
* `"COIN"`: Deterministic pseudo-random generation. Generates a perfect 50/50 randomized output anchored mathematically to the timestamp and previous close, guaranteeing it never repaints or flickers on live ticks.
* `"DTD"`: Day-to-Day alternating parity based on absolute time intervals.
`processLines(linesObj, infoObj, isNew, tRight, lStyle, currHigh, currLow)`
Draws historical support/resistance barriers and evaluates current price action (`currHigh`, `currLow`) to register touches and successful close-throughs.
---
Math & Aggregation
`calcTrueRate(biasCount, hitCount, closeCount)`
Calculates the *True Close-Through Rate* (Success Rate × Close-Through Rate) while safely handling zero-division scenarios. Returns a standardized float coefficient.
`getTotals(infoObj)`
Extracts aggregated cross-directional totals for condensed dashboard views.
* Returns: A tuple `[totalBias, totalHit, totalClose]`.
---
UI Formatting Utilities
`getTablePos(pos)` & `getTableSize(size)`
Translates string-based user inputs (e.g., `"Top Right"`, `"Normal"`) into native Pine Script structural variables (`position.top_right`, `size.normal`).
`formatResult(hit, biasCount)`
Converts raw integers into a cleanly formatted fractional percentage string (e.g., `"45.2%"`).
`formatPercent(value)`
Converts a raw floating-point coefficient into a polished percentage string.
---
Implementation Example
To utilize this library in your indicator, instantiate the UDTs and pass them through the update loops securely:
Pine Script®
Note to Developers
This library adheres strictly to TradingView's anti-repainting guidelines. When feeding inputs into `updateData` or `updateBenchmarkData`, always utilize the previous bar's close (`close[1]`) for the `pClose` parameter. Live data (`high`, `low`) should exclusively be passed into the `processLines` method to allow real-time touch detection.
Overview
The `biasHelper` library is a highly optimized backend engine designed specifically for evaluating, tracking, and aggregating bias analytics across timeframes.
Built on strict Model-View-Controller (MVC) software architecture principles, this library encapsulates all complex mathematical processing, state caching, and string formatting. By offloading these responsibilities, it allows front-end indicators to remain exceptionally lightweight, mathematically pure, and dedicated entirely to UI visualization.
This library features built-in anti-repainting guardrails, deterministic pseudo-random evaluations, and dynamic memory allocation through User-Defined Types (UDTs).
---
Core Architecture & Design Philosophy
This library operates using two primary User-Defined Types (UDTs) that track the lifecycle of a trading session:
1. `SessionInfo`: The primary memory matrix. It tracks OHLC data, prevailing directional bias, Heikin-Ashi extensions, and cumulative hit/close counts.
2. `SessionLines`: The visual array tracker. It orchestrates the projection of structural support/resistance levels and evaluates live price touches against them.
By maintaining state inside these objects rather than utilizing global arrays, the library ensures O(1) time complexity during bar evaluation, resulting in lightning-fast execution even on dense chart histories.
---
Exported Types (UDTs)
`SessionInfo`
The core data structure for tracking session metrics and bias execution.
* **Price Tracking**: `prevHigh`, `prevLow`, `currentHigh`, `currentLow`, `currentOpen`.
* **Heikin-Ashi Anchors**: `prevHaOpen`, `prevHaClose`.
* **State Trackers**: `pushedUp` (bool), `currentBias` (int: 1 = Bullish, -1 = Bearish, 0 = Neutral).
* **Metric Accumulators**: `bullishCount`, `bearishCount`, `hitHighCount`, `hitLowCount`, `closeHighCount`, `closeLowCount`.
`SessionLines`
The spatial data structure for tracking visual levels and live touches.
* Lines: `highLine`, `lowLine`.
* Touch Booleans: `hitHighLine`, `hitLowLine`.
---
Data & State Management
`updateData(infoObj, isNew, pClose, cOpen, cHigh, cLow)`
The standard market structure logic handler. It evaluates historical structural breaks against the previous close to determine the prevailing directional bias without repainting.
* Parameters: Evaluates state using standard OHLC inputs and strictly anchors to `close[1]` (`pClose`) to guarantee real-time parity with historical states.
`updateBenchmarkData(infoObj, isNew, pClose, cOpen, cHigh, cLow, bType, tfSeconds)`
A dynamic routing matrix for alternative bias benchmarks.
* Supported `bType` Routing:
* `"MOM"`: Pure Candlestick Momentum (Close vs. Open).
* `"HA"`: Synthetic Heikin-Ashi Momentum evaluated securely within standard chart data.
* `"ABULL"` / `"ABEAR"`: Static directional evaluations (Always Bullish / Always Bearish).
* `"COIN"`: Deterministic pseudo-random generation. Generates a perfect 50/50 randomized output anchored mathematically to the timestamp and previous close, guaranteeing it never repaints or flickers on live ticks.
* `"DTD"`: Day-to-Day alternating parity based on absolute time intervals.
`processLines(linesObj, infoObj, isNew, tRight, lStyle, currHigh, currLow)`
Draws historical support/resistance barriers and evaluates current price action (`currHigh`, `currLow`) to register touches and successful close-throughs.
---
Math & Aggregation
`calcTrueRate(biasCount, hitCount, closeCount)`
Calculates the *True Close-Through Rate* (Success Rate × Close-Through Rate) while safely handling zero-division scenarios. Returns a standardized float coefficient.
`getTotals(infoObj)`
Extracts aggregated cross-directional totals for condensed dashboard views.
* Returns: A tuple `[totalBias, totalHit, totalClose]`.
---
UI Formatting Utilities
`getTablePos(pos)` & `getTableSize(size)`
Translates string-based user inputs (e.g., `"Top Right"`, `"Normal"`) into native Pine Script structural variables (`position.top_right`, `size.normal`).
`formatResult(hit, biasCount)`
Converts raw integers into a cleanly formatted fractional percentage string (e.g., `"45.2%"`).
`formatPercent(value)`
Converts a raw floating-point coefficient into a polished percentage string.
---
Implementation Example
To utilize this library in your indicator, instantiate the UDTs and pass them through the update loops securely:
Note to Developers
This library adheres strictly to TradingView's anti-repainting guidelines. When feeding inputs into `updateData` or `updateBenchmarkData`, always utilize the previous bar's close (`close[1]`) for the `pClose` parameter. Live data (`high`, `low`) should exclusively be passed into the `processLines` method to allow real-time touch detection.
版本注释
The `biasHelper` library is a highly optimized backend engine designed specifically for evaluating, tracking, and aggregating bias analytics across timeframes.Built on strict Model-View-Controller (MVC) software architecture principles, this library encapsulates all complex mathematical processing, state caching, and string formatting. By offloading these responsibilities, it allows front-end indicators to remain exceptionally lightweight, mathematically pure, and dedicated entirely to UI visualization.
This library features built-in anti-repainting guardrails, deterministic pseudo-random evaluations, and dynamic memory allocation through User-Defined Types (UDTs).
---
Core Architecture & Design Philosophy
This library operates using two primary User-Defined Types (UDTs) that track the lifecycle of a trading session:
1. `SessionInfo`: The primary memory matrix. It tracks OHLC data, prevailing directional bias, Heikin-Ashi extensions, and cumulative hit/close counts.
2. `SessionLines`: The visual array tracker. It orchestrates the projection of structural support/resistance levels and evaluates live price touches against them.
By maintaining state inside these objects rather than utilizing global arrays, the library ensures O(1) time complexity during bar evaluation, resulting in lightning-fast execution even on dense chart histories.
---
Exported Types (UDTs)
`SessionInfo`
The core data structure for tracking session metrics and bias execution.
* Price Tracking: `prevHigh`, `prevLow`, `currentHigh`, `currentLow`, `currentOpen`.
* Heikin-Ashi Anchors: `prevHaOpen`, `prevHaClose`.
* State Trackers: `pushedUp` (bool), `currentBias` (int: 1 = Bullish, -1 = Bearish, 0 = Neutral).
* Metric Accumulators: `bullishCount`, `bearishCount`, `hitHighCount`, `hitLowCount`, `closeHighCount`, `closeLowCount`.
`SessionLines`
The spatial data structure for tracking visual levels and live touches.
* Lines: `highLine`, `lowLine`.
* Touch Booleans: `hitHighLine`, `hitLowLine`.
---
Data & State Management
`updateData(infoObj, isNew, pClose, cOpen, cHigh, cLow)`
The standard market structure logic handler. It evaluates historical structural breaks against the previous close to determine the prevailing directional bias without repainting.
* Parameters: Evaluates state using standard OHLC inputs and strictly anchors to `close[1]` (`pClose`) to guarantee real-time parity with historical states.
`updateBenchmarkData(infoObj, isNew, pClose, cOpen, cHigh, cLow, bType, tfSeconds)`
A dynamic routing matrix for alternative bias benchmarks.
* Supported `bType` Routing:
* `"MOM"`: Pure Candlestick Momentum (Close vs. Open).
* `"HA"`: Synthetic Heikin-Ashi Momentum evaluated securely within standard chart data.
* `"ABULL"` / `"ABEAR"`: Static directional evaluations (Always Bullish / Always Bearish).
* `"COIN"`: Deterministic pseudo-random generation. Generates a perfect 50/50 randomized output anchored mathematically to the timestamp and previous close, guaranteeing it never repaints or flickers on live ticks.
* `"DTD"`: Day-to-Day alternating parity based on absolute time intervals.
`processLines(linesObj, infoObj, isNew, tRight, lStyle, currHigh, currLow)`
Draws historical support/resistance barriers and evaluates current price action (`currHigh`, `currLow`) to register touches and successful close-throughs.
---
Math & Aggregation
`calcTrueRate(biasCount, hitCount, closeCount)`
Calculates the True Close-Through Rate (Success Rate × Close-Through Rate) while safely handling zero-division scenarios. Returns a standardized float coefficient.
`getTotals(infoObj)`
Extracts aggregated cross-directional totals for condensed dashboard views.
* Returns: A tuple `[totalBias, totalHit, totalClose]`.
---
UI Formatting Utilities
`getTablePos(pos)` & `getTableSize(size)`
Translates string-based user inputs (e.g., `"Top Right"`, `"Normal"`) into native Pine Script structural variables (`position.top_right`, `size.normal`).
`formatResult(hit, biasCount)`
Converts raw integers into a cleanly formatted fractional percentage string (e.g., `"45.2%"`).
`formatPercent(value)`
Converts a raw floating-point coefficient into a polished percentage string.
---
Implementation Example
To utilize this library in your indicator, instantiate the UDTs and pass them through the update loops securely:
Note to Developers
This library adheres strictly to TradingView's anti-repainting guidelines. When feeding inputs into `updateData` or `updateBenchmarkData`, always utilize the previous bar's close (`close[1]`) for the `pClose` parameter. Live data (`high`, `low`) should exclusively be passed into the `processLines` method to allow real-time touch detection.
Pine脚本库
秉承TradingView的精神,作者已将此Pine代码作为开源库发布,以便我们社区的其他Pine程序员可以重用它。向作者致敬!您可以私下或在其他开源出版物中使用此库,但在出版物中重用此代码须遵守网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
Pine脚本库
秉承TradingView的精神,作者已将此Pine代码作为开源库发布,以便我们社区的其他Pine程序员可以重用它。向作者致敬!您可以私下或在其他开源出版物中使用此库,但在出版物中重用此代码须遵守网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。