CODESCRIPT

Operators

21 operators. Assignment, comparison, arithmetic and conditional signs. What each one does, with a working example.

!=a b

Asks whether two values differ. It does the same job as `not (a == b)` but reads shorter.

CODESCRIPT
different = close != open
plot(different ? 1 : 0, "different?")

Asks whether two values differ.

%a b

Gives the remainder of a division. Useful for doing something every N bars: when the remainder is zero you have landed on such a bar.

CODESCRIPT
plot(barIndex % 5, "remainder mod five")

Gives the remainder of a division.

*a b

Multiplies two numbers. Used for scaling an indicator by a factor or computing a band width.

CODESCRIPT
plot(atr(14) * 2, "doubled range")

Multiplies two values.

*=ad değer

Multiplies the variable; a short form of `name := name * value`. Used in compounding calculations.

CODESCRIPT
var product = 1.0
product *= 1.01
plot(product, "compound")

Multiplies the variable and writes the result back to it.

+a b

Adds two numbers. On series it adds bar by bar: adding two indicators sums their values on each bar. On text it joins the pieces end to end.

CODESCRIPT
plot(high + low, "high plus low")

Adds two values; joins texts end to end.

+=ad değer

Adds onto the variable; a short form of `name := name + value`. It reads well when accumulating.

CODESCRIPT
var total = 0.0
total += close
plot(total, "accumulation")

Adds to the variable and writes the result back to it.

-a b

Subtracts the right value from the left one. Written before a single value it flips its sign.

CODESCRIPT
plot(high - low, "bar range")

Subtracts the right value from the left one.

-=ad değer

Subtracts from the variable; a short form of `name := name - value`.

CODESCRIPT
var remainder = 1000.0
remainder -= 1
plot(remainder, "falling")

Subtracts from the variable and writes the result back to it.

.nesnealan

Reaches a field of a record or a member of a constant set. It is how you take the parts of an indicator that returns several values; colour and style constants are read the same way.

CODESCRIPT
b = bb(close, 20, 2.0)
plot(b.upper, "upper band")

Reaches a field of a record or a function of an object.

/a b

Divides the left value by the right one. ⚠ When the divisor is zero the result is `na`; when computing a ratio, consider the case where the denominator can be zero.

CODESCRIPT
plot((high + low) / 2, "bar midpoint")

Divides the left value by the right one.

/=ad değer

Divides the variable; a short form of `name := name / value`.

CODESCRIPT
var quotient = 1000.0
quotient /= 1.01
plot(quotient, "falling")

Divides the variable and writes the result back to it.

:koşul ? doğruysa yanlışsa

Separates the two halves of a choice that starts with `?`: on its left the value for a true condition, on its right the value for a false one. It is not used on its own.

CODESCRIPT
plot(close > open ? high : low, "tip by direction")

Separates the two branches of a conditional choice.

:=ad değer

Changes the value of a variable that already exists. It is the only way to update a variable created with `var`; writing `=` would create a new variable and lose the value carried between bars. Increasing a counter or updating a peak is always done with this.

CODESCRIPT
var counter = 0
counter := counter + 1
plot(counter, "bar count")

Changes the value of a variable that already exists.

<a b

Gives true when the left value is smaller than the right one. To accept equality as well, use `<=`.

CODESCRIPT
plot(close < open ? 1 : 0, "down bar")

True when the left value is below the right one.

<=a b

Gives true when the left value is smaller than or equal to the right one. Write it instead of `<` when touching a threshold should also count.

CODESCRIPT
plot(close <= open ? 1 : 0, "down or equal")

True when it is below or equal — the boundary counts.

=ad değer

Gives a value to a variable and creates it for the first time. It is recomputed on every bar and does not carry the previous bar's value. To keep a value across bars, create it with `var` and change it with `:=`. ⚠ It does not test equality — that is `==`.

CODESCRIPT
length = 20
plot(sma(close, length), "average")

Creates the variable for the first time; it is recomputed on every bar.

==a b

Asks whether two values are equal and gives true or false. ⚠ A single `=` assigns while a double `==` asks; mixing them up is a common mistake when writing conditions.

CODESCRIPT
equal = close == open
plot(equal ? 1 : 0, "equal?")

Asks whether two values are equal.

=>seçenek sonuç

Binds an option to its result inside a `switch`. On its left the value to match, on its right the result when it matches. A line with an empty left side runs when no option matched.

CODESCRIPT
direction = close > open ? 1 : -1
text = switch direction {
    1 => "up"
    => "down"
}
plot(close, "price")

Separates a function's body from its header.

>a b

Gives true when the left value is greater than the right one. To accept equality as well, use `>=`.

CODESCRIPT
plot(close > open ? 1 : 0, "up bar")

True when the left value is above the right one.

>=a b

Gives true when the left value is greater than or equal to the right one. Write it instead of `>` when touching a threshold should also count.

CODESCRIPT
plot(close >= open ? 1 : 0, "up or equal")

True when it is above or equal — the boundary counts.

?koşul doğruysa : yanlışsa

Picks one of two values depending on a condition. It is shorter than an `if` block for choosing a single value and can sit right inside a calculation. Chaining them builds several steps. Its second half is separated with `:`.

CODESCRIPT
plot(close > open ? high : low, "tip by direction")

Gives the first value when the condition holds, otherwise the second.