QuasarGen Script: the indicator language
QuasarGen Script (QGS) is the language indicators are written in. Files use the .qgs extension, and the language version is declared on the first line: //@version=1. The built-in session volume profile is also defined by a .qgs script through profile.session(...); see the adjacent reference for parameters. Indicator scripts have no network access or permission to place orders. Third-party AI advisers with separate autotrading consent are only a proposed future capability; their orders must pass the same risk-management and cooling checks as manual orders.
The main property of the language is that there is nothing in it to do harm with. No files, no network, no pointers, no system calls: they simply do not exist in the language. Reviewing somebody else's indicator is therefore reading forty lines of formula, not hunting for a backdoor in two thousand lines of C++.
How it is computed
In QGS, every value is a series over bars. The script describes what the value equals on the current bar, and the terminal runs it over the whole history itself, then computes new bars one at a time without recalculating the past.
The past is reached through [k]: close[1] is the previous bar's close. The depth must be a constant — then the memory for history is known before the first bar.
Every node is computed exactly once per bar. That is not an optimisation but a rule: state lives inside the ta.* functions — a window, a running average — and a second call on the same bar would move the window forward.
Both branches of ?: are always computed. Otherwise the history of the branch not taken would tear, and the indicator would depend on which bars happened to be computed.
na means “there is no value”. Until the window fills, the indicator honestly returns na, and the chart draws a gap instead of a zero.
Your first indicator
//@version=1
indicator("Two averages", overlay=true)
length = input.int("Period", 14, 1, 500)
fast = ta.ema(close, length)
slow = ta.sma(close, length * 3)
f = plot(fast, "EMA", color.bull, width=2)
s = plot(slow, "SMA", color.text)
fill(f, s, color.bull, opacity=20)Names may be written in any language — the language works in Unicode. The input.int(...) line does more than set the period: the terminal builds the indicator's settings form out of it, so the form and the script cannot drift apart.
For input.int, input.float, input.bool, input.string, input.color and input.source, group="Arguments" or group="Style" places the setting on the corresponding tab of the terminal's integrated modal. The Visibility tab selects timeframes for each added indicator instance; it is not a script parameter and the terminal stores it separately.
The session volume profile uses profile.session(...). widthPct sets the histogram width as a percentage of the session width. placement=0 anchors it to the left with bars growing right; placement=1 anchors it to the right with bars growing left. showBackground controls the session backdrop. extendPoc, extendVah, and extendVal extend the corresponding levels right until price first touches them. See the reference for the full parameter list and defaults. The profile distributes available OHLCV candle volume over the candle's low…high range; it does not fetch lower-timeframe data specifically for the profile, so it is an approximation rather than an exact trade-by-trade profile.
An indicator in its own pane
//@version=1
indicator("RSI", overlay=false, precision=2)
length = input.int("Period", 14, 2, 200)
value = ta.rsi(close, length)
plot(value, "RSI", color.accent, width=2)
hline(70, "Overbought", color.sell)
hline(30, "Oversold", color.bull)overlay=false means a separate pane under the chart: an oscillator has its own scale, and laying it over prices makes no sense.
Median of a series: `ta.median`
Availability: this function was added to the Quasar source on 15 November 2026. Existing released builds do not have it yet; use this example once a terminal release containing ta.median is available.
Syntax: ta.median(source, length). source is a numeric series such as close or the candle range high - low. length is a constant number or an input.int setting from 1 to 4096. The function sorts the last length values and selects the middle element. It returns na until the window is full, so the plot is absent on the first bars.
//@version=1
indicator("Median candle range", overlay=false)
period = input.int("Bars", 70, 5, 500)
range = high - low
normal = ta.median(range, period)
plot(normal, "Median range", color.accent)Paste the code into Quasar's QGS editor, save it as a .qgs file and add it to the chart as an indicator. For an even window, the upper of the two middle values is chosen: 4, 1, 3, 2 produces 3, not 2.5. Use normal[1] when the current candle must be compared with only previous candles. A dynamic length, zero or a window above 4096 is rejected. Large windows require more work on each bar.
Event memory: `state.capture`
Availability: added to the source on 15 November 2026; existing released builds do not have it yet.
Syntax: state.capture(trigger, source). Both arguments are evaluated on every bar. When trigger is a finite nonzero number, the function saves the current source value and returns it on that bar and subsequent bars until the next event. Before the first event it returns na. Zero and na do not fire an event; the captured source itself may be na. Each call stores only one value of its own; a script rerun reconstructs the result from history.
//@version=1
indicator("Last bullish candle high", overlay=true)
lastHigh = state.capture(close > open, high)
plot(lastHigh, "Last high", color.bull)Paste the example into the QGS editor and add it to a chart. The line appears on the first up candle, then holds that candle's high until the next up candle. The function does not keep a list of zones or know whether the latest input candle has closed. The state.peak function below can track fill for one FVG.
Maximum since an event: `state.peak`
Availability: added to the source on 15 November 2026; existing released builds do not have it yet.
Syntax: state.peak(trigger, source). A finite nonzero trigger starts a new segment and takes the current source as its first maximum. Afterwards the function returns the maximum of all finite source values until the next event. An na source is skipped; if it occurs on the event bar, the result stays na until the first finite value. The result is also na before the first event. Each call stores one maximum and reconstructs it from history on a rerun.
//@version=1
indicator("High since candle turn", overlay=true)
start = close > open and close[1] <= open[1]
peak = state.peak(start, high)
plot(peak, "High since event", color.accent)Paste the code into the QGS editor and add it to a chart. The line begins when a non-up candle is followed by an up candle and rises on new highs; the next such turn resets it. For FVG, the function can accumulate the maximum fraction of a zone overlapped by later candles. The new Market Mechanica source example hides the latest FVG on each side after its configured fill percentage is reached. It does not yet keep all 24 zones or know whether the latest input candle has closed.
Shifting lines and filling
offset in plot shifts the line by bars: forward (+) or back (−). What moves is the position on the chart, not the values — the computation stays tied to its own bar. fill takes two colours: the first when the first line is above the second, the second when it is below. Together that gives the Ichimoku cloud:
tenkan = (ta.highest(high, 9) + ta.lowest(low, 9)) / 2
kijun = (ta.highest(high, 26) + ta.lowest(low, 26)) / 2
spanA = plot((tenkan + kijun) / 2, "Span A", color.bull, offset=26)
spanB = plot((ta.highest(high, 52) + ta.lowest(low, 52)) / 2, "Span B",
color.sell, offset=26)
fill(spanA, spanB, color.bull, color.sell, opacity=16)
plot(close, "Chikou", color.bull, offset=-26)Ichimoku in the terminal is written exactly like that — not an example of how it could be done, but the very script the indicator is drawn by.
Colours
A colour is named by its role, not by its code: color.bull, color.sell, color.text, color.soft, color.accent, color.grid. An indicator then reads the same in the light theme and in the dark one. When an exact colour is needed — color.rgb(41, 98, 255).
What the language does not have yet
The current version has no loops, user-defined functions, recursion, access to files, the network, the machine clock, random numbers, your account or your orders. The language is planned to grow for complex indicators with resource limits and explicit permissions for external services. Those capabilities have not been implemented yet.
The compatibility promise
A script with //@version=1 must compute the same thing a year from now. New capability arrives as a new language version; old versions keep working. That rule outweighs any elegant rewrite.