NexuScript 1.5
Build your own indicators with NexuScript.
NexuScript is the Nexus language for your own chart indicators. Write a short script, press Run, and the chart draws what it computes: lines, bands, levels, markers, shapes, tables and alerts.
A script cannot reach the network or your files, and it stops on its own if it runs too long. A script you get from someone else can only draw on your chart.
Getting started
- Open the Scripts panel and press New. Pick Blank or one of the examples.
- Change the script, then press Run. The indicator goes on the chart, and every chart that already uses it updates. Run does not save.
- Press Save to keep the script. It stays in the indicator list under My scripts, and the last 10 saved versions are under Versions.
- Press Reference to look anything up. It opens beside the editor on the name under your cursor (put the cursor on
ta.emaand press it), and you can search by name or by a few words such asmoving averageorsession. Every keyword, value and function is there with its settings, what it gives back, what happens with missing values, and an example you can paste. The same reference is the Syntax tab of the docs page.
While you type, the editor colours the script and numbers its lines. A line with a mistake has its number in red: point at the number to read the problem. When a script fails to run, the status line under the editor gives the line and column, for example line 7:15: closee is not defined; did you mean close?.
The settings a script declares with input appear in the indicator's settings, like those of any built-in indicator.
A first script
nexscript 1
indicator "RSI with levels", short = "RSI"
input length = 14, title = "Length", min = 1, max = 500
input src = close, title = "Source"
level "Overbought", 70, color = color.red
level "Oversold", 30, color = color.green
on bar
let rsi = ta.rsi(src, length)
plot("RSI", rsi, color = rsi >= 70 ? color.red : color.blue, width = 2)
if rsi >= 70
background(color.fade(color.red, 90))
end
endEverything before on bar is the setup: it runs once. The on bar ... end block runs once for every bar, oldest first, and again for the newest bar each time its price changes.
The guide
Reference chapters
? :) to the tightest (^, then calls and [ ]).19 entriesTypes and literalsEvery value has one of these types. There are no hidden conversions.14 entriesBar valuesThe prices, volume and time of the bar being run, and where it sits in the chart.16 entriesTime and sessionsBar times, the exchange and chart time zones, sessions, the trading day and countdowns.26 entriesSymbol and timeframeFacts about the chart's symbol and bar size. Fixed for a run, so they may be read in setup.20 entriesMathNumbers. Every function returns missing when an input is missing, unless it says otherwise.27 entriesTextBuilding and searching text.9 entriesArraysOrdered lists. Indexes start at 1.11 entriesTechnical analysisAverages, oscillators and signals. Each call keeps its own memory, so it must run on every bar (the call-site rule).42 entriesOther timeframes and symbolsReading a higher timeframe or another symbol, always through the chart's own data.1 entryUsing other indicatorsReading 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).2 entriesColorsNamed colours, custom colours, transparency and gradients.17 entriesPlotting and drawingPlots, shading, lines, boxes, labels, markers, tables and the chart's own candles.15 entriesOrder flowVolume at each price inside a bar, and the order book.2 entriesAlerts and outputTelling the trader something happened.2 entriesStrategiesOrder calls and reads, in strategy scripts only. An order call only records what the script asks for; backtests read it, nothing is sent.17 entries