Skip to content
Nexus Prop LLC

NexuScript 1.5

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).

use

declarationNexuScript 1.5

Gives another indicator a name in this script, with the inputs it should run with, so the script can read its outputs.

Syntax

use name = indicator("id", input = value, ...)
use name = indicator("id@version", ...)

Details

The id is a built-in ("ema", "macd", "psar"), a Nexus library indicator ("kernel-regression"), one of your own saved scripts ("my/Trend filter"), or a paid indicator you have access to. Inputs are passed by name, with the names the indicator's settings use; each is fixed: a value, a price source such as close or hl2, a colour, or one of this script's own inputs. Inputs left out take the indicator's defaults. Read an output with name.output, and its history with name.output[n], inside on bar. Without @version the script follows the indicator's active version. The script receives only the indicator's outputs, bar by bar: never its code. Building on an indicator needs access to it, checked when the script compiles and again whenever it runs, so a script someone shares with you works only when you have access to everything it uses. Each indicator with the same inputs is worked out once per chart and shared, however many scripts use it. Indicators cannot use each other in a loop. A script uses at most 16 indicators.

Errors

  • NS250there is no indicator with that id (or that version), or it gives no outputs
  • NS251the indicator needs access you do not have
  • NS252the indicators would use each other in a loop (this script included)
  • NS211an input is passed without its name, or the indicator has no input with that name
  • NS302an input value changes from bar to bar
  • NS470access to the indicator ended, or its outputs could not be worked out, while the script runs

Example

nexscript 1.5

indicator "MACD agrees", overlay = true

use m = indicator("macd", fast = 12, slow = 26, signal = 9)

on bar
    let rising = m.histogram > m.histogram[1]
    if rising && m.macd > 0
        marker("UP", position = "below", shape = "triangle_up", color = color.green)
    end
end

See also

outputswitchon bar

output

declarationNexuScript 1.5

Declares a value this indicator gives to the scripts that use it, worked out on each bar.

Syntax

output name::Number, title = "Title"
output name::Bool

Details

Assign it in on bar (name = value); each bar starts with it missing (or false for a Bool), so a bar that does not assign it gives no value. A script that uses this indicator reads it as alias.name. An indicator that declares no outputs gives its plots instead, named from their titles in lowercase words joined by _ (the plot "Signal line" is signal_line). An output has no history of its own here: store it with let first. At most 64 outputs.

Errors

  • NS210the type is not Number or Bool
  • NS230the output is assigned in setup
  • NS232the header names a version before 1.5

Example

nexscript 1.5

indicator "Trend state", overlay = true

input length = 21, title = "Length", min = 1

output rising::Bool, title = "Rising"
output average::Number, title = "Average"

on bar
    let avg = ta.ema(close, length)
    average = avg
    rising = avg > avg[1]
    plot("Average", avg, color = rising ? color.green : color.red)
end

See also

usestateplot