Description: When you need more space for your data you can use bitwise operations. For example if you are creating an Order Block indicator and you have multiple types then you can define variables for each type with only one bit set like these: const int TYPE_OB = 1 const int TYPE_HH = 2 const int TYPE_LH = 4 const int TYPE_HL = 8 const int TYPE_LL = 16 const int TYPE_BOS = 32 const int TYPE_CHOCH = 64
bitwise_shift_left(x, y) bitwise_shift_left(): Bitwise left shift: x << y Parameters: x (int) y (int) Returns: : The left operand’s value is moved toward left by the number of bits specified by the right operand.
bitwise_shift_right(x, y) bitwise_shift_right(): Bitwise right shift: x >> y Parameters: x (int) y (int) Returns: : The left operand’s value is moved toward right by the number of bits specified by the right operand.
bitwise_and(x, y) bitwise_and(): Bitwise AND: x & y Parameters: x (int) y (int) Returns: : Result bit 1, if both operand bits are 1; otherwise results bit 0.
bitwise_or(x, y) bitwise_or(): Bitwise OR: x | y Parameters: x (int) y (int) Returns: : Result bit 1, if any of the operand bit is 1; otherwise results bit 0.
bitwise_xor(x, y) bitwise_xor(): Bitwise (exclusive OR) XOR: x ^ y Parameters: x (int) y (int) Returns: : Result bit 1, if any of the operand bit is 1 but not both, otherwise results bit 0.
logical_xor(x, y) logical_xor(): Logical (exclusive OR) XOR: x xor y Parameters: x (bool) y (bool) Returns: : Result true, if any of the operand bit are different, otherwise results bit 0.
bit_check(x, y) bit_check(): Bitwise Checks the specified bit Parameters: x (int) y (int) Returns: : Returns True if the bit is set.
bit_set(x, y) bit_set(): Bitwise Sets the specified bit Parameters: x (int) y (int) Returns: : Returns a value with the bit set.
bit_clear(x, y) bit_clear(): Bitwise Clears the specified bit Parameters: x (int) y (int) Returns: : Returns a value with the bit cleared.
bit_flip(x, y) bit_flip(): Bitwise Inverts the specified bit Parameters: x (int) y (int) Returns: : Returns a value with the bit inverted.
bitmask_check(x, mask) bitmask_check(): Bitwise Checks the specified Mask Parameters: x (int) mask (int) Returns: : Returns True if the mask is set.
bitmask_set(x, mask) bitmask_set(): Bitwise Sets the specified Mask Parameters: x (int) mask (int) Returns: : Returns a value with the mask set.
bitmask_clear(x, mask) bitmask_clear(): Bitwise Clears the specified Mask Parameters: x (int) mask (int) Returns: : Returns a value with the mask cleared.
bitmask_flip(x, mask) bitmask_flip(): Inverts the specified Mask Parameters: x (int) mask (int) Returns: : Returns a value with the mask inverted.
math_bit_check(x, y) math_bit_check(): Fast arithmetic bitwise Checks the specified Mask Parameters: x (int) y (int) Returns: : Returns True if the mask is set.
math_bit_set(x, y) math_bit_set(): Fast arithmetic bitwise Sets the specified bit Parameters: x (int) y (int) Returns: : Returns a value with the bit set.
math_bit_clear(x, y) math_bit_clear(): Fast arithmetic bitwise Clears the specified bit Parameters: x (int) y (int) Returns: : Returns a value with the bit cleared.
math_bitmask_check(x, y) math_bitmask_check(): Fast arithmetic bitwise Checks the specified Mask Parameters: x (int) y (int) Returns: : Returns True if the mask is set.
math_bitmask_set(x, y) math_bitmask_set(): Fast arithmetic bitwise Sets the specified Mask Parameters: x (int) y (int) Returns: : Returns a value with the mask set.
math_bitmask_clear(x, y) math_bitmask_clear(): Fast arithmetic bitwise Clears the specified Mask Parameters: x (int) y (int) Returns: : Returns a value with the mask cleared.
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.