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.
Bar by bar: how a script runs
The script's top level runs once per bar, starting from the oldest bar.

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:
varcounts 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.

//@navy 2.0first (else NV1001), then exactly oneoverlay('…')orindicator('…'): its title names the script.- Outputs —
plot,hline,fill,bgcolor,marker.*,alert— stay at the top level, never insideifor a loop: their value changes per bar,nadraws 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).
- 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 }) - Add to chart (
Ctrl+Enter): saved under itsoverlay('…')name, an orange line appears; errors are under Problems. - 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) }) - 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' }) - Save (
Ctrl+S). Fast and Slow are now in the settings window (the gear in the legend).


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

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


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

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

- 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
:=, anifwithout brackets, a misspelled name); a color swatch by every color; folding in the margin.



| Action | Keys |
|---|---|
| Run the code on the chart (Add to chart / Update on chart) | Ctrl+Enter |
| Save | Ctrl+S |
| Complete a name | Ctrl+Space |
| Go to where a name is declared | F12, Ctrl+click |
| Add another cursor | Alt+click |
| Select the next occurrence of a word | Ctrl+D |
| Find and replace | Ctrl+F |
| Comment lines out and back in | Ctrl+/ |
| Move a line up or down | Alt+↑, Alt+↓ |
| Next problem | F8 |
| Undo, redo | Ctrl+Z, Ctrl+Y |
On a Mac: Cmd for Ctrl; redo — Cmd+Shift+Z; completion stays Ctrl+Space.

