FuturaDevelopers

Syntax

Variables, types, operators and control flow in NeuroScript.

NeuroScript uses indentation to delimit blocks (like Python, without : or {}). Every script starts with the version line and the indicator declaration — see First steps for the full anatomy.

Comments

// line comment — everything after // is ignored
length = input.int(14, "Length") // also works at the end of a line

Variables

Declare with = and reassign with :=:

avg = ta.sma(close, 20) // declares
avg := ta.sma(close, 50) // reassigns (the variable already exists)

The type is inferred from the value, but you can declare it explicitly:

int period = 14
float factor = 2.0
active = true   // inferred bool
text = "RSI"  // inferred string

Language types: int, float, bool, string, color. Market values like close are series (series<float>) — a sequence with one value per candle (see Market data).

var and varip — state across candles

By default a variable is recomputed on every candle. Use var to initialize once and keep the value across candles:

var contador = 0
contador := contador + 1 // accumulates across the chart

varip is similar, but the value also persists across ticks within the same candle (intrabar).

Operators

CategoryOperators
Arithmetic+ - * / %
Comparison== != < > <= >=
Logicaland or not
Ternarycondition ? valueIfTrue : valueIfFalse
Historyseries[n] — value from n candles back
variacao = close - close[1]                   // history: previous candle
isUp = close > open and volume > 0            // logical
col = close >= open ? color.green : color.red // ternary

Control flow

if / else

Blocks by indentation — no : (Python) and no {} (C):

tendencia = 0
if close > open
    tendencia := 1
else
    tendencia := -1

for

Numeric loop with to (optional step with by, e.g. for i = 0 to 100 by 10):

soma = 0.0
for i = 0 to 9
    soma := soma + close[i] // sum of the last 10 closes

To iterate over an array, use for ... in:

valores = array.from(1, 2, 3)
total = 0
for v in valores
    total := total + v

while

i = 0
while i < 10
    i := i + 1

switch

Picks one value among several cases (=>), with a default case at the end:

signal = switch
    close > open => 1
    close < open => -1
    => 0

Indicator rules

  • The first line of the script must be //@version=6.
  • plot() inside an if only draws on the candles where that branch runs (on the others the value is na). For signals, keep plot() at the top level with condition ? value : na, style=plot.style_circles (or style_triangleup/style_triangledown) and a conditional color, or use plotshape(condition, style=shape.triangleup, location=location.belowbar) for a marker anchored to the candle. plotchar() and plotarrow() draw nothing on the chart.
  • offset= on plot()/plotshape() shifts the drawing by bars (positive forward, negative backward); the projection past the last candle is not drawn. linestyle=plot.linestyle_dashed|dotted dashes the line.
  • NeuroScript has no return at the top level.

Next

On this page