NexuScript 1.5
NexuScript syntax reference.
Every keyword, operator, type, built-in value and function of NexuScript 1.5, with its parameters, what it returns, how it treats missing values, the errors it can raise and an example you can paste into the script editor.
How to read an entry
- Syntax shows each parameter as
name::Type.= valueis the default when you leave it out;automaticmeans the function picks a sensible value for you. A parameter marked fixed must be the same on every bar (a number, an input or a constant). - Give arguments by position or by name:
plot("Fast", fast, color = color.blue). Positional ones come first. - NexuScript 1.N is the version that added the name. A script that uses it starts with
nexscript 1.Nor later. - Times are milliseconds since 1970-01-01 UTC unless an entry says otherwise. Error codes such as
NS420are listed under each entry and explained in full where the script editor shows them.
Script structure
The header, the declaration, settings and the block that runs on every bar.
Statements and control flow
Variables, decisions, loops and functions.
elseif and else branches.forRepeats a block over a range of numbers or over the items of an array.breakLeaves the innermost loop at once.continueSkips to the next turn of the innermost loop.returnLeaves a function with a value, or ends this bar's run early in on bar.=Assigns a new value to a variable or an array item.switchRuns the block of the first case that matches a value, or the else block when none does.Operators
Arithmetic, comparison, logic and text. Operators bind from the loosest (? :) to the tightest (^, then calls and [ ]).
ta or color, or a named part of a tuple.Types and literals
Every value has one of these types. There are no hidden conversions.
true or false.StringText, written in double quotes.ColorA colour with its transparency, or no colour.ArrayAn ordered list of values of one type, counted from 1.tupleA fixed group of values, plain (a, b) or named (fast = f, slow = s).missingThe number that is not there: a gap, or a value not worked out yet.trueThe Bool value for yes.falseThe Bool value for no.IntMakes an input a whole-number setting, whatever the default is written like.FloatMakes an input a number-with-decimals setting.SymbolMakes an input a symbol setting; empty text means the chart's own symbol.TimeframeMakes an input a timeframe dropdown.structDeclares a record type: a named group of typed fields, built with the type's name like a function.Bar values
The prices, volume and time of the bar being run, and where it sits in the chart.
Time and sessions
Bar times, the exchange and chart time zones, sessions, the trading day and countdowns.
3:05.clock.trading_dayThe trading day the bar belongs to, as a number such as 20261030.clock.chart_zoneThe name of the time zone the chart displays.clock.exchange_zoneThe name of the time zone of the exchange the symbol trades on.clock.formatWrites a time as text in a pattern you choose, such as 2026-10-30 09:30.clock.wallSplits a time into its year, month, day, hour, minute, second and weekday on a zone's clock.clock.timeBuilds a time from a date and a time of day on a zone's clock.clock.offsetHow many minutes a zone's clock is ahead of UTC at a given time.session.is_openTests whether the symbol's trading session is open on the chart clock.session.open_timeWhen the current trading session opened, or when the next one opens while it is closed.session.close_timeWhen the current trading session closes, or when the next one closes while it is closed.session.to_openHow long until the next trading session opens.session.to_closeHow long is left until the current trading session closes.Symbol and timeframe
Facts about the chart's symbol and bar size. Fixed for a run, so they may be read in setup.
NQZ6.symbol.rootThe product code of the chart's symbol without the contract month, such as NQ.symbol.exchangeThe exchange the chart's symbol trades on, such as CME.symbol.descriptionThe full name of the chart's symbol, such as E-mini Nasdaq-100.symbol.tickThe smallest step the price can move, such as 0.25 for NQ.symbol.point_valueHow much money a move of 1.0 in price is worth on one contract.symbol.qty_stepThe smallest step an order size can take.symbol.timezoneThe time zone of the exchange the symbol trades on.symbol.sessionThe trading hours of the symbol, as a time window.timeframe.nameThe chart's bar size, written as text.timeframe.secondsHow long one bar of the chart lasts, in seconds.timeframe.intradayTests whether the chart's bars are shorter than one day.symbol.contractThe contract shown on the chart, such as NQZ6.symbol.asset_classWhat kind of market the symbol is: futures or perpetuals.symbol.tick_valueHow much money one tick is worth on one contract.symbol.currencyThe currency the symbol's prices and money values are in, such as USD.symbol.min_qtyThe smallest order size allowed.symbol.expiryWhen the chart's contract expires.symbol.rollWhen trading is expected to move from the chart's contract to the next one.symbol.funding_hoursHow many hours pass between a perpetual's funding payments.Math
Numbers. Every function returns missing when an input is missing, unless it says otherwise.
atan(y, x).roundRounds a number to a whole number or to a number of decimals.round_to_tickRounds a price to the nearest price the symbol can trade at.minThe smallest of two or more numbers.maxThe largest of two or more numbers.clampKeeps a number between a lower and an upper limit.modThe remainder after dividing, always with the sign of the divisor.ismissingTests whether a number is missing.isfiniteTests whether a number is an ordinary number: not missing and not infinite.coalesceThe first of its arguments that is not missing.Text
Building and searching text.
Arrays
Ordered lists. Indexes start at 1.
Technical analysis
Averages, oscillators and signals. Each call keeps its own memory, so it must run on every bar (the call-site rule).
length values.ta.emaThe exponential moving average, which follows recent prices more closely than a simple average.ta.rmaWilder's moving average, a slower exponential average used inside RSI and ATR.ta.wmaThe weighted moving average, where newer values count more.ta.vwmaThe volume-weighted moving average: bars with more volume count more.ta.linregThe value of the best straight line through the last length values, at the newest bar.ta.highestThe highest of the last length values, this bar included.ta.lowestThe lowest of the last length values, this bar included.ta.since_highestHow many bars ago the highest of the last length values was.ta.since_lowestHow many bars ago the lowest of the last length values was.ta.stdevHow spread out the last length values are (the standard deviation).ta.mean_devThe average distance of the last length values from their mean.ta.sumThe total of the last length values.ta.rocThe rate of change: how many percent x moved over length bars.ta.percent_rankWhere x stands against the previous length values, from 0 to 100.ta.rsiThe Relative Strength Index, a 0 to 100 measure of how strong recent gains are against recent losses.ta.swmaA short smoothing over the last four values, with the middle two counted twice.ta.cumsumA running total of every value since the first bar.ta.changeHow much x changed since length bars ago.ta.atrThe Average True Range: how far price typically moves per bar.ta.stochThe stochastic oscillator: where x sits inside the high to low range of the last length bars.ta.macdThe MACD: the gap between a fast and a slow EMA, with a signal line and a histogram.ta.bandsBands around a moving average, set a number of standard deviations above and below it.ta.crossoverTrue on the bar where a moves from at or below b to above it.ta.crossunderTrue on the bar where a moves from at or above b to below it.ta.crossTrue on the bar where a crosses b in either direction.ta.bars_sinceHow many bars ago a condition was last true.ta.value_whenThe value x had the last time a condition was true.ta.cciThe Commodity Channel Index: how far x is from its mean, in units of its mean deviation.ta.mfiThe Money Flow Index: a 0 to 100 measure of buying against selling pressure, weighted by volume.ta.almaThe Arnaud Legoux moving average: a Gaussian-weighted average that can lean towards the newest bars.ta.pivot_highA swing high: the value right bars ago when it is above the left values before it and the right values after it.ta.pivot_lowA swing low: the value right bars ago when it is below the left values before it and the right values after it.ta.fill_missingThe latest value of x that was not missing: gaps are filled with the value before them.ta.demaThe double exponential moving average, which lags less than ta.ema.ta.temaThe triple exponential moving average, which lags even less than ta.dema.ta.t3Tillson's T3: a very smooth average built from six exponential averages.ta.psarThe Parabolic SAR: a trailing stop that follows the trend and speeds up as it runs.ta.cummaxThe highest value x has had so far on the chart.ta.cumminThe lowest value x has had so far on the chart.ml.lorentzian_knnA nearest-neighbour vote: how the bars whose features looked most like this bar's were labelled.Other timeframes and symbols
Reading a higher timeframe or another symbol, always through the chart's own data.
Using other indicators
Reading the outputs of another indicator, never its code: built-ins, Nexus library indicators, your own scripts, and indicators you have access to (NexuScript 1.5).
Colors
Named colours, custom colours, transparency and gradients.
"#22c55e".color.rgbA colour from its red, green and blue amounts, with an optional opacity.color.fadeMakes a colour more see-through by a percentage.color.alphaSets the opacity of a colour to an exact amount.color.greenThe named colour green, #22c55e.color.redThe named colour red, #ef4444.color.blueThe named colour blue, #3b82f6.color.orangeThe named colour orange, #ff9800.color.yellowThe named colour yellow, #eab308.color.purpleThe named colour purple, #7e57c2.color.tealThe named colour teal, #26a69a.color.grayThe named colour gray, #787b86.color.whiteThe named colour white, #ffffff.color.blackThe named colour black, #000000.color.noneNo colour at all, so nothing is drawn.color.mixBlends two colours together.color.gradientPicks a colour for a value on a scale between two colours.Plotting and drawing
Plots, shading, lines, boxes, labels, markers, tables and the chart's own candles.
Order flow
Volume at each price inside a bar, and the order book.
Alerts and output
Telling the trader something happened.
Strategies
Order calls and reads, in strategy scripts only. An order call only records what the script asks for; backtests read it, nothing is sent.