Does not existPine Script v6

bitwise_and

Pine Script has no bitwise operators or bitwise functions at all — here is what to use instead.

Quick answer

No — bitwise_and is not a Pine Script function, and Pine has no bitwise layer of any kind. There is no bitwise_and, bitwise_or or bitwise_xor, and the operators &, |, ^, ~, << and >> are not part of the language in v5 or v6. Writing any of them fails to compile. For true/false flags use the boolean operators and, or and not. For genuine bit manipulation on integers you must compose it yourself from arithmetic — division by powers of two plus math.floor and the % remainder operator.

The exact error

Could not find function or function reference 'bitwise_and'

v5 → v6

Never existed in Pine Script v3, v4, v5 or v6. This is not a migration issue. The confusion usually comes from C, Java, Python or Pine's own boolean and, which reads like a bitwise AND but is strictly boolean.

Why this happens

Pine Script deliberately has no bitwise operators. It is a domain-specific language for series maths, and bit twiddling is outside what it targets, so there is nothing to migrate to and no import that adds it.

The single most common cause of this error is assuming that Pine's and behaves like C's & on integers. It does not. Pine's and, or and not are strictly boolean: they take true/false and return true/false, and they will not operate on integer bits.

If you are packing flags into an integer, the idiomatic Pine answer is to stop packing. Use separate bool variables, or an array<bool>. It is clearer and it compiles.

If you genuinely need to read bit N of an integer, compute it arithmetically: math.floor(value / math.pow(2, n)) % 2 gives you that bit as 0 or 1.

What actually works

//@version=6
bitwise-and-or-xor.pine
//@version=6
indicator("Bit flags without bitwise operators", overlay = false)

// WRONG - none of these exist in Pine Script:
// packed = bitwise_and(flags, 4)
// packed = flags & 4

// RIGHT (1) - for true/false conditions, use boolean operators.
trendUp   = ta.ema(close, 20) > ta.ema(close, 50)
strongRsi = ta.rsi(close, 14) > 55
bothTrue  = trendUp and strongRsi          // boolean AND, not bitwise

// RIGHT (2) - if you really must read bit n of an integer, do it arithmetically.
bitAt(value, n) =>
    math.floor(value / math.pow(2, n)) % 2  // returns 0 or 1

flags = 5                                   // binary 101
plot(bitAt(flags, 0), "bit 0", color = color.green)   // 1
plot(bitAt(flags, 1), "bit 1", color = color.red)     // 0
plot(bothTrue ? 1 : 0, "both", color = color.blue)

Copy and paste into the TradingView Pine Editor, or let TradePilot adapt it to your exact case.

FAQ

bitwise_and — common questions

Does Pine Script have a bitwise_and function?

No. bitwise_and is not a built-in in any Pine Script version, and the & operator is not part of the language either. The compiler rejects it with "Could not find function or function reference 'bitwise_and'".

Can I use & or | in Pine Script?

No. Pine has no bitwise operators at all — &, |, ^, ~, << and >> are all invalid. Use the boolean operators and, or and not, which work on true/false values rather than bits.

Was bitwise support added in Pine Script v6?

No. Pine v6 added many things, but a bitwise layer was not one of them. It has never existed in v3, v4, v5 or v6.

How do I check a single bit of an integer in Pine Script?

Compose it arithmetically: math.floor(value / math.pow(2, n)) % 2 returns bit n as 0 or 1. In most trading scripts, separate bool variables are clearer than packing flags into an integer at all.

More Pine reference

Other functions and errors

Never hit this error again.

TradePilot writes Pine Script v6 that's verified to compile before it reaches you — and if your existing script has this error, Pine Studio fixes it, root cause and all, in one pass. Start with 7 days free on any plan; cancel any time before it ends.

7-day free trial · Cancel anytime · No charge until day 7