> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lipi operators

> Reference for the 22 operators of Lipi v2: -, -=, :=, ! and 18 more, each with its definition and an example.

> [!NOTE]
>
> Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Entries: 22

## `-` (operator)

**Definition**

Subtraction or unary minus. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 - expr1 | -expr0
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close - 10", overlay=true)
// Subtract 10 from the closing price
priceAdjusted = close - 10
// Plot the adjusted price
plot(priceAdjusted, title="Close - 10", color=color.red)
```

## `-=` (operator)

**Definition**

Subtract assignment. Replaces the variable with its current value minus the right-hand expression. Applicable to int and float combinations using the same rules as `-`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<variableIdentifier> -= <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Subtract Assign Example", overlay=true)
offset = close
offset -= open
plot(offset, title="Close minus open", color=color.red)
```

## `:=` (operator)

**Definition**

Reassignment operator. It is used to assign a new value to a previously declared variable.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<existing_variable> := <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Bar Counter", overlay=true)
// Declare a mutable variable
static int barCount = 0
// Increment barCount on each new bar
barCount := barCount + 1
// Plot the bar counter
plot(barCount, title="Bar Count", color=color.blue)
```

## `!` (operator)

**Definition**

Logical NOT. Applicable to boolean expressions: `!x` is true when `x` is false, and false when `x` is true.

It is the symbol spelling of `not`, and the two are the same token to the lexer.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
!expr0 | not expr0
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Logical NOT Example", overlay=true)
// Condition: Close is above the previous close
abovePrevClose = close > close[1]
// Use `!` to invert the condition
bgcolor(!abovePrevClose ? color.red : color.green)
```

## `!=` (operator)

**Definition**

Not equal to. Applicable to expressions of any type. True when its two operands differ.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 != expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Not Equal Example", overlay=true)
// Mark bars whose close differs from the previous close
changed = close != close[1]
bgcolor(changed ? na : color.new(color.gray, 0.3))
```

## `?` (operator)

**Definition**

Ternary conditional operator.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 ? expr1 : expr2
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Ternary Operator Example", overlay=true)
// Define conditions
bullish = close > open
bearish = close < open
// Use ternary operator to set color based on conditions
candleColor = bullish ? color.green : bearish ? color.red : color.gray
// Color the candles
barcolor(candleColor)
```

## `*` (operator)

**Definition**

Multiplication. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 * expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Price Multiplier", overlay=true)
// Multiply close price by 1.05 (5% increase)
priceAdjusted = close * 1.05
// Plot the adjusted price
plot(priceAdjusted, title="5% Higher Price", color=color.blue)
```

## `*=` (operator)

**Definition**

Multiply assignment. Replaces the variable with the product of its current value and the right-hand expression. Applicable to int and float combinations using the same rules as `*`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<variableIdentifier> *= <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Multiply Assign Example", overlay=true)
scale = 1.0
scale *= 1.01
plot(close * scale, title="Scaled close", color=color.blue)
```

## `/` (operator)

**Definition**

Division. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 / expr1
```

**Notes**

* The result is always a float, so `int h = 4 / 2` is rejected. Use `math.floor`, `math.round` or `math.ceil` to get an int.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close / 2", overlay=true)
// Divide the closing price by 2
priceHalved = close / 2
// Plot the halved price
plot(priceHalved, title="Close / 2", color=color.blue)
```

## `/=` (operator)

**Definition**

Divide assignment. Replaces the variable with its current value divided by the right-hand expression. The result is always a float, so the variable must already be a float (or the assignment is rejected).

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<variableIdentifier> /= <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Divide Assign Example", overlay=true)
half = close
half /= 2.0
plot(half, title="Half of close", color=color.gray)
```

## `&&` (operator)

**Definition**

Logical AND. Applicable to boolean expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 && expr1 | expr0 and expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Logical AND Example", overlay=true)
// && is the symbol spelling of and
insideBar = high < high[1] && low > low[1]
bgcolor(insideBar ? color.new(color.blue, 0.2) : na)
```

## `%` (operator)

**Definition**

Modulo: the remainder of dividing the left operand by the right one. Applicable to numerical expressions, ints and floats.

The result is an int when both operands are ints, and a float when either is a float (so `int x = 7.5 % 2` is rejected: use `math.floor`, `math.round` or `math.ceil`). A string operand is rejected. The result has the sign of the left operand: `-7 % 3` is -1, `7 % -3` is 1 and `-7.5 % 2` is -1.5.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 % expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Even or Odd Bars", overlay=true)
// Check if bar index is even or odd
isEvenBar = bar_index % 2 == 0
// Color background based on even or odd
bgcolor(isEvenBar ? color.green : color.red)
```

## `%=` (operator)

**Definition**

Modulo assignment. Replaces the variable with the remainder of dividing its current value by the right-hand expression.

The result follows `%`: a float variable accepts an int or a float operand; an int variable accepts only an int operand, and a float operand is an error that suggests `math.floor`, `math.round` or `math.ceil`. A string variable is rejected.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<variableIdentifier> %= <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Modulo Assign Example", overlay=true)
static int tick = 0
tick += 1
tick %= 2
bgcolor(tick == 0 ? color.new(color.green, 0.2) : na)
```

## `+` (operator)

**Definition**

Addition. Applicable to numerical expressions or strings. A unary plus (`+x`) is accepted.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 + expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Addition Example", overlay=false)
a = 0
b = 5
sum = a + b
plot(sum, title="Sum", color=color.blue)
```

## `+=` (operator)

**Definition**

Add assignment. Replaces the variable with the sum of its current value and the right-hand expression. Works on numbers and on two strings.

The left-hand side may be a dotted field on an object (for example `point.x += 1`) as well as a plain variable. The variable must already exist.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
<variableIdentifier> += <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Add Assign Example", overlay=false)
static int bars = 0
bars += 1
plot(bars, title="Bar counter", color=color.blue)
```

## `<` (operator)

**Definition**

Less than. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 < expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close Below MA", overlay=true)
// Define a 20-period simple moving average
sma20 = talib.sma(close, 20)
// Check if the close price is below the SMA
isBelowMA = close < sma20
// Change background color when the condition is true
bgcolor(isBelowMA ? color.red : na)
```

## `<=` (operator)

**Definition**

Less than or equal to. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 <= expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Low Volume Bars", overlay=true)
// Compute 50-period average volume
avgVolume = talib.sma(volume, 50)
// Check if the current volume is below or equal to average
isLowVolume = volume <= avgVolume
// Highlight bars with low volume
plotshape(isLowVolume, title="Low Volume", location=location.bottom, color=color.blue, shape=shape.triangleup)
```

## `=` (operator)

**Definition**

for assignment.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
[<declaration_type>] [<data_type>] <variable_name> = <expression>
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Assignment Operator Example", overlay=true)
// Assigning values using =
static int myNumber = 10
static float myFloat = 5.5
static string myText = "Hello, Lipi!"
// Reassigning values
myNumber := myNumber + 5
myFloat := myFloat * 2
// Plotting the updated number
plot(myNumber, title="Updated Number", color=color.blue)
```

## `==` (operator)

**Definition**

Equal to. Applicable to expressions of any type.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 == expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Moving Average Crossover", overlay=true)
// Define two moving averages
fastMA = talib.sma(close, 10)
slowMA = talib.sma(close, 20)
// Check if the fast MA is equal to the slow MA
isEqual = fastMA == slowMA
// Plot moving averages
plot(fastMA, title="Fast MA", color=color.blue)
plot(slowMA, title="Slow MA", color=color.red)
```

## `>` (operator)

**Definition**

Greater than. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 > expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Bullish Candle Detector", overlay=true)
 // Check if the current candle is bullish
isBullish = close > open  
// Plot a green background when the candle is bullish
bgcolor(isBullish ? color.green : na)
```

## `>=` (operator)

**Definition**

Greater than or equal to. Applicable to numerical expressions.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 >= expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close >= Moving Average", overlay=true)
// Define a 20-period simple moving average (SMA)
sma20 = talib.sma(close, 20)
// Check if the closing price is greater than or equal to the SMA
isAboveOrEqual = close >= sma20
// Plot the moving average
plot(sma20, title="20-SMA", color=color.blue)
// Change background color when the condition is met
bgcolor(isAboveOrEqual ? color.green : na)
```

## `||` (operator)

**Definition**

It evaluates two Boolean expressions and returns true if at least one of them is true.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
expr0 || expr1 | expr0 or expr1
```

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Logical OR Example", overlay=true)
// || is the symbol spelling of or
gap = open > high[1] || open < low[1]
bgcolor(gap ? color.new(color.orange, 0.2) : na)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.