Bias AI -- Indicator Contract¶
Identity¶
| Field | Value |
|---|---|
| Pine Title | "Bias AI" |
| Study Filter | "Bias AI" |
| Overlay | true |
| Timeframe | Any (designed for intraday charts with daily bias) |
Visual Channels¶
| Channel | Signal Role | Required for Strategy |
|---|---|---|
| Tables | Primary -- bias direction and raid status via cell bgcolor | Yes |
| Lines | Primary -- level locations and hit detection via color | Yes |
| Labels | Informational -- bias reasoning (when bias_reason input is ON) |
No |
Reading Approach
The strategy reads table bgcolor + line colors ONLY. Labels are informational and are not required. The interpreter must never depend on bias_reason labels being enabled. They may be turned off by the user at any time.
Table Structure¶
Position¶
Configurable via indicator input. Default: position.bottom_right.
Layout¶
| Row | Column 0 |
|---|---|
(0,0) |
Header: "Bias" |
(0,1) |
"PDH" cell |
(0,2) |
"PDL" cell |
(0,3) |
Success Rate (optional stats row) |
(0,4) |
Close Thru Rate (optional stats row) |
(0,5) |
Sample Size (optional stats row) |
Rows 3-5 are present only when the show_stats input is enabled. They are informational and not required for strategy decisions.
Cell Bgcolor Encoding¶
The two critical cells are (0,1) ("PDH") and (0,2) ("PDL"). Their background colors encode the current bias state and raid status.
| Cell | Bgcolor | Meaning |
|---|---|---|
(0,1) PDH |
before_raid_color |
Bullish bias is active. PDH has not been hit yet. |
(0,1) PDH |
after_raid_color |
PDH has been hit (raided). Bullish target reached. |
(0,1) PDH |
null / no bgcolor |
Bias is not bullish. |
(0,2) PDL |
before_raid_color |
Bearish bias is active. PDL has not been hit yet. |
(0,2) PDL |
after_raid_color |
PDL has been hit (raided). Bearish target reached. |
(0,2) PDL |
null / no bgcolor |
Bias is not bearish. |
Default Colors¶
| Color Variable | Default Value | Meaning |
|---|---|---|
before_raid_color |
Configurable (typically green/teal) | Target not yet reached |
after_raid_color |
Configurable (typically red/orange) | Target has been reached |
Color Configuration
The exact hex values for before_raid_color and after_raid_color are user-configurable in the indicator settings. The interpreter must be configured with the matching values or detect them dynamically by reading the table.
Bias Derivation from Table¶
IF cell(0,1).bgcolor == before_raid_color -> bias = BULLISH (PDH target, not yet hit)
IF cell(0,1).bgcolor == after_raid_color -> bias = BULLISH (PDH target, already hit)
IF cell(0,2).bgcolor == before_raid_color -> bias = BEARISH (PDL target, not yet hit)
IF cell(0,2).bgcolor == after_raid_color -> bias = BEARISH (PDL target, already hit)
IF both cells have null bgcolor -> bias = NEUTRAL
The active bias is determined by which cell has a non-null bgcolor with before_raid_color:
- PDH highlighted with
before_raid_color= Bullish (target is PDH, not yet reached) - PDL highlighted with
before_raid_color= Bearish (target is PDL, not yet reached) - A cell with
after_raid_colorindicates the target was already reached during the session
Lines¶
Level Lines¶
Horizontal lines marking prior day/week highs and lows.
| Level | Line Style | Scope |
|---|---|---|
| PDH (Prior Day High) | Solid | Daily |
| PDL (Prior Day Low) | Solid | Daily |
| PWH (Prior Week High) | Dashed | Weekly |
| PWL (Prior Week Low) | Dashed | Weekly |
Line Color Encoding¶
| Color | Meaning |
|---|---|
before_raid_color |
Level has not been hit. Price has not reached this level today. |
after_raid_color |
Level has been hit. Price reached this level during the current session. |
Line Extension Behavior¶
When the stop_ext input is enabled (default: true), lines stop extending after the level is hit. This means:
- Active (unhit) levels:
extend = extend.right(line continues rightward) - Hit levels:
extend = extend.none(line stops at the bar where price reached it)
Hit Detection¶
A level is considered "hit" when its line color changes from before_raid_color to after_raid_color. In a snapshot reading:
- Read all horizontal lines from the indicator
- Match by price level (y-value) to identify PDH/PDL/PWH/PWL
- Check color to determine hit status
Labels (Optional -- bias_reason Input)¶
When the bias_reason input is enabled, the indicator places labels explaining the bias determination logic. These are not required for strategy operation but are documented here for completeness and debugging.
Label Text Patterns¶
| Label Text | Bias Result | Logic |
|---|---|---|
"Close Above PDH\nBias PDH" |
Bullish (+1) | Prior day closed above PDH, expect continuation |
"Close Below PDL\nBias PDL" |
Bearish (-1) | Prior day closed below PDL, expect continuation |
"Failed to Close Above PDH\nBias PDL" |
Bearish (-1) | Price hit PDH but failed to close above, reversal bias |
"Failed to Close Below PDL\nBias PDH" |
Bullish (+1) | Price hit PDL but failed to close below, reversal bias |
"Close Inside\nBias PDH" |
Bullish (+1) | Closed inside range, bias determined by additional logic |
"Close Inside\nBias PDL" |
Bearish (-1) | Closed inside range, bias determined by additional logic |
"Outside Bar but Closed Inside\nNo Bias" |
Neutral (0) | Outside bar pattern, no directional bias |
Label Structure¶
- Line 1: The reason (what happened with price relative to levels)
- Line 2: The resulting bias direction (
"Bias PDH"= bullish,"Bias PDL"= bearish,"No Bias"= neutral)
The second line is always the definitive bias statement.
State Machine¶
States¶
| State | Value | Description |
|---|---|---|
| BULLISH | +1 |
Bias is toward PDH. Expect price to seek the prior day high. |
| BEARISH | -1 |
Bias is toward PDL. Expect price to seek the prior day low. |
| NEUTRAL | 0 |
No directional bias. Outside bar or insufficient data. |
Transitions¶
+-----------+
+--------->| NEUTRAL |<---------+
| | (0) | |
| +-----+-----+ |
| | |
outside bar bias determined outside bar
| | |
| +-----v-----+ |
| +--->| BULLISH |---+ |
| | | (+1) | | |
| | +-----------+ | |
| | | |
new day bias new day bias |
| | | |
| | +-----------+ | |
| +----| BEARISH |<--+ |
| | (-1) | |
| +-----------+-----------+
Reset¶
- Bias is determined once per day at the start of the new trading day.
- The state persists for the entire trading session until the next daily reset.
- Hit detection (color changes on lines) happens continuously intraday but does not change the bias direction -- it only updates the raid status.
Compound State¶
The full state at any point is a tuple: (bias_direction, pdh_hit, pdl_hit, pwh_hit, pwl_hit)
Example states:
| Bias | PDH Hit | PDL Hit | Interpretation |
|---|---|---|---|
| +1 | false | false | Bullish, target PDH not yet reached |
| +1 | true | false | Bullish, PDH reached (target hit) |
| -1 | false | false | Bearish, target PDL not yet reached |
| -1 | false | true | Bearish, PDL reached (target hit) |
| 0 | false | false | Neutral, no directional play |
Alerts¶
| Alert Condition | Alert Text | Meaning |
|---|---|---|
| Bullish bias determined | "Bias PDH" |
New day bias is bullish (toward PDH) |
| Bearish bias determined | "Bias PDL" |
New day bias is bearish (toward PDL) |
| PDH level hit | "Hit PDH" |
Price reached PDH during session |
| PDL level hit | "Hit PDL" |
Price reached PDL during session |
Parser Rules¶
| # | Channel | Identifier | Meaning | Parser Logic |
|---|---|---|---|---|
| 1 | Table | Cell (0,0) text == "Bias" |
Table identity confirmation | Locate the Bias AI table by header text |
| 2 | Table | Cell (0,1) text == "PDH", bgcolor != null |
Bullish bias state | If bgcolor == before_raid_color -> bullish, target pending. If bgcolor == after_raid_color -> bullish, target hit. |
| 3 | Table | Cell (0,2) text == "PDL", bgcolor != null |
Bearish bias state | If bgcolor == before_raid_color -> bearish, target pending. If bgcolor == after_raid_color -> bearish, target hit. |
| 4 | Table | Both (0,1) and (0,2) bgcolor == null |
Neutral bias | No directional bias for the day |
| 5 | Line | Solid style, color == before_raid_color |
Unhit daily level (PDH or PDL) | y-value gives the price level. Match to known PDH/PDL. |
| 6 | Line | Solid style, color == after_raid_color |
Hit daily level | Level was reached during current session. |
| 7 | Line | Dashed style, color == before_raid_color |
Unhit weekly level (PWH or PWL) | y-value gives price. Dashed distinguishes weekly from daily. |
| 8 | Line | Dashed style, color == after_raid_color |
Hit weekly level | Weekly level was reached. |
| 9 | Line | extend == extend.right |
Level is still active (not yet hit) | Confirms the level has not been reached. |
| 10 | Line | extend == extend.none |
Level was hit, extension stopped | Confirms hit status (when stop_ext enabled). |
| 11 | Label | Text line 2 == "Bias PDH" |
Bullish bias reason | Informational only. Do not depend on for strategy. |
| 12 | Label | Text line 2 == "Bias PDL" |
Bearish bias reason | Informational only. Do not depend on for strategy. |
| 13 | Label | Text line 2 == "No Bias" |
Neutral bias reason | Informational only. |
Edge Cases¶
| Case | Handling |
|---|---|
| Table not found | Indicator not loaded or not visible. Return bias = UNKNOWN. Strategy should not trade. |
| Both PDH and PDL cells have bgcolor | Should not occur. If it does, log a warning and use the cell with before_raid_color (pending target takes precedence over completed target). |
| No lines visible | Levels may be off-screen or indicator is still loading. Bias can still be read from table. Lines are supplementary. |
| Custom colors don't match defaults | Interpreter must be configured with the user's chosen before_raid_color and after_raid_color values. Mismatched colors will cause false NEUTRAL readings. |
bias_reason labels disabled |
Normal operation. Strategy does not depend on labels. |
| Weekend / holiday (no prior day data) | Indicator may show stale data from last trading day. Bias is still valid for the levels shown. |
| Multiple tables on chart | Filter by study_filter "Bias AI" to isolate this indicator's table. |