Why bitwise_and and & fail as built-ins
TradingView lists arithmetic, comparison, logical, assignment, ternary, and history operators; it does not list &, |, ^, ~, <<, or >> as Pine operators. A standalone v6 call to bitwise_and(6, 3), without a local definition or import, also fails syntax validation. Changing only the version directive is not a fix. A library can export its own similarly named function, but that name is not a Pine built-in.
- If the operands are conditions, combine the boolean expressions with and or or.
- If the operands are packed integers, preserve the bit positions and width when porting the algorithm.
- For an imported helper, inspect the library author, version, alias, exported name, and supported numeric range.
| Task | Approach | Constraint |
|---|---|---|
| Combine two conditions | conditionA and conditionB | Boolean result; does not inspect integer bits |
| Store a few named flags | Separate bool variables or bool fields in a UDT | A UDT is not automatically displayed in the Data Window |
| Store indexed flags | array<bool> | Collection indexing and state management apply |
| Keep an integer mask | Bounded arithmetic helper below | Unsigned 16-bit values only |