Keywords
24 keywords. The language's own words — conditions, loops, variable declaration. What each one does, with a working example.
Gives true when both conditions are true. Use it to narrow a signal down: when the trend is up and the volume is high. If either condition is false, the result is false.
A boolean that is true only when both boolean expressions are true.
Note
The logical AND connective (a language keyword, not a function). Combines two conditions; works bar-by-bar over series. Used to fold several filters into a single condition.
plot(iff(close > open and rsi(close, 14) > 50, 1, 0))
Plots 1 when the candle is up and RSI is above 50, otherwise 0.
The false value. Write it directly as the result of a condition or to switch a setting off.
The boolean constant that is always false.
Note
The boolean false literal (a language keyword). Used as a checkbox default or to temporarily switch off a branch.
plot(iff(false, close, open))
Since the condition is always false, open is plotted.
A place with no value. An indicator is `na` on the first bars while it cannot be computed yet, and a drawing is `na` on bars where it should not appear. Ask whether a value is empty with `na(x)`, and put a number in its place with `nz(x, 0)`. ⚠ Any arithmetic involving `na` yields `na`.
The empty value meaning "no value".
Note
The special value marking missing/undefined data (a language keyword). Warm-up empty bar results are na; also used to intentionally leave a value empty or create a gap in a plot. The na() function tests whether a value is na.
plot(iff(barIndex < 20, na, close))
Leaves the first 20 bars empty (na) and plots price afterwards.
Flips a condition: true becomes false and false becomes true. It lets you write conditions the way you think of them — "when this is not the case".
The negation of a boolean expression (true↔false).
Note
The logical NOT operator (a language keyword). Inverts a condition; works bar-by-bar over series.
plot(iff(not (close < open), 1, 0))
Plots 1 when the candle is not down (i.e. up/equal).
Gives true when at least one of two conditions is true. Use it to gather several acceptable cases into one condition. If both are false, the result is false.
A boolean that is true when at least one of the two boolean expressions is true.
Note
The logical OR connective (a language keyword). The result is true when either condition holds; works bar-by-bar over series.
plot(iff(close > open or volume > sma(volume, 20), 1, 0))
Plots 1 when it is an up candle or volume is above its average.
The true value. Write it directly as the result of a condition or to switch a setting on.
The boolean constant that is always true.
Note
The boolean true literal (a language keyword). Used as a checkbox default or to temporarily pin a condition on.
plot(iff(true, close, open))
Since the condition is always true, close is plotted.
Ends the loop right where it is; the remaining turns do not run. Use it when you have found what you were looking for and there is no reason to keep going. It breaks only the current loop, leaving an outer loop running.
counter = 0 for i = 0 to 100 { if i > 4 { break } counter := counter + 1 } plot(counter, "stopped at five")
Leaves the loop once the target is found, skipping the remaining turns.
Sets the step of the counter in a `for` loop. Without it the counter goes one by one. `for i = 0 to 10 by 2` gives 0, 2, 4, 6, 8, 10 — useful for scanning every second bar.
total = 0.0 for i = 0 to 10 by 2 { total := total + close[i] } plot(total, "every second bar")
Steps the counter by two: 0, 2, 4, 6, 8, 10.
Cuts the current turn short and moves on to the next one. When you want to skip certain items, writing the condition with `if` and calling `continue` reads better than wrapping the whole body in an `if`.
counter = 0 for i = 0 to 9 { if i % 2 == 0 { continue } counter := counter + 1 } plot(counter, "odd numbers")
Skips that turn without ending the loop.
elifif ... { ... } koşul { ... }
Tries another condition when the previous one did not match. You can chain as many as you need; the first match runs and the rest are skipped. Adding `else` at the end gives the branch that runs when none of them matched.
direction = 0 if close > open { direction := 1 } elif close < open { direction := -1 } plot(direction, "direction")
Tests a second condition; it is checked when the first one fails.
Gives the lines that run when the `if` condition turns out false. It never stands alone; it always follows an `if` block. When there are further conditions, list them with `elif` and keep `else` last: it runs when none of the ones above matched.
direction = 0 if close > open { direction := 1 } else { direction := -1 } plot(direction, "direction")
Shows the branch that runs when the condition fails: the direction becomes +1 or -1.
Defines a limited set of options by name. For things that take one of a few values — a direction, a state, a kind — you carry the name instead of a number or a string: a typo is easy to spot and the reader does not have to guess what the value means.
enum Direction { UP DOWN } y = close > open ? Direction.YUKARI : Direction.ASAGI plot(close, "price")
Names a fixed set of options.
Defines your own function: a name, the values it takes, and what it does inside the curly braces. When the same calculation repeats in several places, writing it once with `fn` and calling it by name shortens the code and lets you fix it in one place. Send the result back with `return`.
fn average(a, b) { return (a + b) / 2 } plot(average(high, low), "middle")
Defines your own function and uses it on the chart.
for i = başlangıç to bitiş [by adım] { ... }
Runs the same lines again and again while increasing a counter from a start to an end. Use it when you know the number of turns in advance — scanning the last ten bars, walking through an array. `to` sets where the counter goes, `by` sets the step. When the number of turns is not known, `while` fits better.
total = 0.0 for i = 0 to 4 { total := total + close[i] } plot(total / 5, "five-bar average") // stepping by two: for i = 0 to 10 by 2 { ... }
Sums the last five closes and plots their average; the comment shows the stepped form.
Runs the lines inside the curly braces when a condition is true, and skips them when it is false. Use it when a drawing or a calculation should happen only on certain bars. Add `else` for what happens when the condition is false, `elif` for a third possibility. To pick a single value, `?` is shorter.
direction = 0 if close > open { direction := 1 } elif close < open { direction := -1 } else { direction := 0 } plot(direction, "direction")
Plots 1 on an up bar, -1 on a down bar, 0 when equal — all three branches in one example.
Walks through the items of an array in order; each turn hands you the item itself, so you do not have to work out its position. You can write it without knowing how many items the array holds — the loop stops when the array ends.
d = arrayNewFloat() arrayPush(d, close) arrayPush(d, open) total = 0.0 for value in d { total := total + value } plot(total, "array sum")
Walks through every item of the array.
method ad(Tip alıcı, ...) { ... }
Adds a function to a type; its first value is an object of that type and the function is called as `object.name()`. Instead of repeating the same calculation for every object of that type, you write it once. It also keeps the code tidy because it reads together with the type itself.
type Box { float lower = na float upper = na } method height(Box k) { return k.ust - k.alt } kk = Box.new(low, high) plot(kk.yukseklik(), "height")
Attaches a function to a type; it is called with a dot.
Sends the function's result back and ends the function right there. Lines below it do not run, so it also serves as an early exit tied to a condition. It belongs only inside an `fn` or `method` body, not in the main code.
fn doubled(x) { return x * 2 } plot(doubled(close), "doubled")
Sets the value the function gives back.
switch değer { seçenek => sonuç }
Compares a value against the options in order and gives the result of the first match. It gathers in one place what would otherwise be a stack of `if` checks on the same value. Write a final line with no option for the cases that match nothing — it runs when none of the others did.
direction = close > open ? 1 : close < open ? -1 : 0 text = switch direction { 1 => "up" -1 => "down" => "horizontal" } plot(close, "price")
Separates several possible states of one value in a single structure.
In a `for` loop it says how far the counter goes, and that value is included: `for i = 0 to 4` runs five turns (0, 1, 2, 3, 4). The end value need not be a constant; a computed number works too.
total = 0.0 for i = 0 to 9 { total := total + close[i] } plot(total / 10, "ten-bar total")
Says where the counter stops; the end value is included.
type Ad { tip alan = varsayılan }
Defines your own type so that values belonging together travel as one record. Each field gets a type and a starting value. After defining it you create instances with `Ad.new(...)` and reach the fields as `object.field`. Handy when you want to carry a zone, a signal or a level as a single piece.
type Point { int bar = 0 float price = na } n = Point.new(barIndex, close) plot(n.fiyat, "point")
Defines your own record type, keeping its fields together.
Creates the variable on the first bar only and carries its value to the following bars. A variable written without `var` is recomputed from scratch on every bar; use `var` to keep a counter, remember a peak, or hold a state across bars. Once created, change its value with `:=`, not `=`.
var counter = 0 counter := counter + 1 plot(counter, "bar count")
The counter is not reset on each bar; it accumulates across bars.
Creates the variable once like `var`, but changes made within the bar are kept as well. On a live chart the value keeps accumulating with every price update before the bar closes, whereas `var` waits for the bar to close. Useful for counters that follow intrabar movement.
varip highest = high if high > highest { highest := high } plot(highest, "peak")
The value survives intrabar updates as well, and is not reset on a new bar.
Repeats the same lines as long as the condition stays true. Use it when the number of turns is not known in advance; when it is, `for` fits better. ⚠ Without a line inside that changes the condition the loop never ends — the `sayac := sayac + 1` line in the example is there for exactly that.
counter = 0 while counter < 3 { counter := counter + 1 } plot(counter, "counter")
Loops while the condition holds; the number of turns is not known in advance.