Wintrading

Navy: getting started

Navy: getting started

Navy is the scripting language of the Wintrading charts: how it is built, how a script runs, your first indicator.

What Navy is

How Navy works: the editor checks the code, the compiler builds it, a worker runs it bar by bar, the chart engine draws it; the data flows in; Save keeps it in your account, Publish sends it through review to Community
Everything runs in your browser: the editor checks the code, a worker runs it, the chart draws it.

Navy is the language of indicators on the Wintrading charts.

  • A script is an indicator like the built-in ones: on the price chart or in its own pane, with a legend, settings and alerts.
  • Written like TypeScript, runs like Pine Script: once per bar, every value a series with history.
  • The built-in library (Trend Cloud, Ichimoku, Supertrend, RSI Pro…) and every script in My scripts and Community are written in it.
You do not have to write it yourselfChatGPT or Claude writes it from your description (Create with AI); this guide helps you check it.

Next: your first indicator, core concepts, what a script draws, the reference.

Bar by bar: how a script runs

The script's top level runs once per bar, starting from the oldest bar.

Bar by bar: closed bars run once each, oldest first; the live bar runs again on every price update after its state is rolled back; a signal on the live bar can appear and vanish
One run per closed bar; the live bar runs again on every update.
  • close, volume… are the values of the bar being run; close[1] — the bar before.
  • The live bar re-runs on every update, its state first rolled back: var counts the bar once, an object drawn on it is redrawn, not copied.
  • History equals live: the same result either way. Older bars, another coin or timeframe — the history runs again.
  • barstate.islast — the live bar; barstate.isconfirmed — its last run; barstate.ishistory — a closed bar.
//@navy 2.0
indicator('Bars and updates')

var bars = 0      // var: kept from bar to bar, rolled back before every update of the live bar
bars += 1
varip runs = 0    // varip: kept between the updates of the live bar too
runs += 1

plot(bars, { title: 'Bars', color: color.blue })
plot(runs, { title: 'Runs', color: color.orange })

On the live bar runs keeps growing: varip is never rolled back.

No looking aheadA bar sees only itself and the bars before. ta.pivothigh(high, 5, 5) reports a swing 5 bars late; drawn back on the pivot bar, it shows on history what nobody saw live.

What a script looks like

A complete indicator: an EMA colored by the trend, labels on the crosses, an alert.

The EMA trend example with its parts marked: the language line, the declaration, the inputs, the calculations, the outputs — and the chart it draws: an EMA colored teal and red with Up and Down labels
The parts of a script, and what it draws on a BTCUSDT 1m chart.
  • //@navy 2.0 first (else NV1001), then exactly one overlay('…') or indicator('…'): its title names the script.
  • Outputs — plot, hline, fill, bgcolor, marker.*, alert — stay at the top level, never inside if or a loop: their value changes per bar, na draws nothing.
  • Comments //, /* … */; a ; at a line's end is optional.

Your first indicator

Five minutes, no AI. Saving your own scripts needs Pro (the trial counts).

  1. Open the editor: the indicator window → My scripts → Open editor. Paste:
    //@navy 2.0
    overlay('My first indicator')
    
    plot(ta.sma(close, 20), { title: 'SMA 20', color: color.orange, width: 2 })
  2. Add to chart (Ctrl+Enter): saved under its overlay('…') name, an orange line appears; errors are under Problems.
  3. Two EMAs and a cloud: Update on chart shows the new code at once, before saving.
    //@navy 2.0
    overlay('My first indicator')
    
    const fastLen = input.int('Fast', 9, { min: 1 })
    const slowLen = input.int('Slow', 21, { min: 1 })
    const fast = ta.ema(close, fastLen)
    const slow = ta.ema(close, slowLen)
    
    const a = plot(fast, { title: 'Fast', color: color.orange, width: 2 })
    const b = plot(slow, { title: 'Slow', color: color.blue, width: 2 })
    fill(a, b, { color: fast > slow ? color.new(color.teal, 0.15) : color.new(color.red, 0.15) })
  4. Signals and alerts — the whole script:
    //@navy 2.0
    overlay('My first indicator')
    
    const fastLen = input.int('Fast', 9, { min: 1 })
    const slowLen = input.int('Slow', 21, { min: 1 })
    const fast = ta.ema(close, fastLen)
    const slow = ta.ema(close, slowLen)
    
    const a = plot(fast, { title: 'Fast', color: color.orange, width: 2 })
    const b = plot(slow, { title: 'Slow', color: color.blue, width: 2 })
    fill(a, b, { color: fast > slow ? color.new(color.teal, 0.15) : color.new(color.red, 0.15) })
    
    // Signals: computed at the top level, on every bar
    const up = ta.crossover(fast, slow)
    const down = ta.crossunder(fast, slow)
    marker.below(up, 'Buy', { shape: 'label', color: color.teal })
    marker.above(down, 'Sell', { shape: 'label', color: color.red })
    alert(up, '{{ticker}}: fast EMA crossed above the slow one at {{close}}', { freq: 'close' })
    alert(down, '{{ticker}}: fast EMA crossed below the slow one at {{close}}', { freq: 'close' })
  5. Save (Ctrl+S). Fast and Slow are now in the settings window (the gear in the legend).
The script of step 4 on a BTCUSDT 1m chart: an orange and a blue EMA, a teal or red cloud between them, Buy and Sell labels on the crosses
Step 4 on a BTCUSDT 1m chart.
The Wintrading script editor over the Coins chart: the code of a script with Update on chart, and the chart showing its two EMAs and Buy labels
The editor over the chart: Update on chart draws the result at once.
Nothing drawn?The first bars of an average are na. A run-time error is in the editor's On the chart tab.

Where a script runs and who sees it

  • In your browser, in a thread next to the chart; nothing is computed on a server.
  • Only where it is on (Coins, the heatmap, the constructor, the trend screener); its data loads only while it reads it.
  • Safely: the chart's data and the language only — no page, no network. Too long a loop or too much memory stops the script, not the chart (limits).
Measured speed: compiling a script takes 2.5 to 4.4 ms the first time, 10 000 bars of history 0.4 to 4.1 ms, one live update well under a microsecond; a bar per script
Measured: a few ms to compile, about a millisecond for 10 000 bars.
  • A new script is private: My scripts, your account.
  • Publish it: after a review it is in Community — anyone can add it, vote, copy it; the code is open (Publishing).
My scripts in the indicator window: Open editor, From TradingView, Create with AI, the list of the account’s scripts, one of them published
My scripts: your own; a published one shows its votes.
Community in the indicator window: a published script with its author, category, description, votes and number of users
Community: published scripts, popular or new.

Writing with AI

ChatGPT or Claude get the Navy reference from the same compiler: answers usually compile the first time.

Create with AI in the indicator window: a description, the prompt copied for ChatGPT or Claude, the answer pasted and checked — on the price chart, 2 inputs
Create with AI: describe, send the prompt, paste the answer — it is checked at once.
  • One thing, with what to tune: «EMA 50 and 200, a cloud between them, lengths in the settings».
  • Name the data and the place: «long liquidations», «the nearest density», «the 4h trend»; «on the price chart» or «in a pane».
  • Ask for a marker or label on the signal, and an alert.
  • Errors → Copy the errors for the AI or Fix with AI, into the same chat.
  • The Navy reference (.txt) for a chat; steps: Create with AI, From TradingView.
Read it before you trade itNo look-ahead in the signal, inputs that mean what they say, data your exchange has; then a few coins and timeframes.

The editor and its keys

Opens from My scripts → Open editor or a script's Open in the editor; saving, updating and problems: Scripts → The editor.

The editor’s layout: a panel over the chart with the header (back to Indicators, the script, Compiled, fold and close), the code, the Problems and On the chart tabs, Save and Update on chart
A panel over the chart: the header, the code, problems, Save and Update on chart.
  • Checks as you type with the chart's compiler: Compiled · 3 ms or the number of errors.
  • Completes names, Wintrading's too (liq., walls.…); help on hover; parameters inside the brackets.
  • Quick fixes for typical mistakes (Pine's :=, an if without brackets, a misspelled name); a color swatch by every color; folding in the margin.
Help on hover in the editor: ta.crossover with its signature, parameters, return type and an example
Help on hover: the signature, the parameters, an example.
Completion in the editor: typing ta.cr offers cross, crossover and crossunder with their parameters
Completion as you type.
The Problems tab: NV2003 unknown name clsoe at line 20, column 6, with Fix with AI
Problems: the code, the line and the column; a click jumps there.
ActionKeys
Run the code on the chart (Add to chart / Update on chart)Ctrl+Enter
SaveCtrl+S
Complete a nameCtrl+Space
Go to where a name is declaredF12, Ctrl+click
Add another cursorAlt+click
Select the next occurrence of a wordCtrl+D
Find and replaceCtrl+F
Comment lines out and back inCtrl+/
Move a line up or downAlt+↑, Alt+↓
Next problemF8
Undo, redoCtrl+Z, Ctrl+Y

On a Mac: Cmd for Ctrl; redo — Cmd+Shift+Z; completion stays Ctrl+Space.