Appearance
Your first script
How do you write a script and see it on your chart? Open the Script Editor, replace its blank indicator with the script below, and press Add to chart. The editor checks the script, runs it on every bar of the chart, and the chart draws what it plots.
pine
//@version=6
indicator("Moving average band", overlay = true)
length = input.int(20, "Length", minval = 1) // a setting you can change on the chart
mid = ta.sma(close, length)
dev = ta.stdev(close, length)
plot(mid, "Mean")
plot(mid + 2 * dev, "Upper", color = color.gray)
plot(mid - 2 * dev, "Lower", color = color.gray)This is Pine Script v6, which AmenoScript runs unchanged.
Where your script runs
AmenoScript runs inside Ameno Terminal, a market terminal: charts, a Script Editor and the panes that run scripts across bars, symbols and settings. A script added to a chart is a study, and the chart's legend lists each study by its title.
| Pane | What it does with a script |
|---|---|
| Script Editor | Edits, checks and saves scripts, and adds one to the chart. |
| Strategy Tester | Reports a strategy's backtest: equity, metrics and every trade. |
| Optimizer | Runs a strategy over many settings of its inputs and ranks the results. |
| Screener | Runs a script on many symbols and lists each one's last values. |
The terminal has four engines, and each place runs your script on the one that suits it:
- The editor's check runs in your browser, on the JIT, which compiles the script to JavaScript.
- A study on the chart runs on the terminal's server, on the Rust engine. A study with
strategy()orvarip, one that readstimenow, or one that imports a library other than the technical-analysis one runs in your browser instead. - The Strategy Tester reads the strategy's run in your browser.
- An alert runs on the server, as each bar closes.
- The Optimizer and the Screener run on the server, with your browser taking any run the server doesn't answer.
The four engines are built to give the same values, bit for bit, on any script TradingView compiles: the tests run every example on each one and compare, and a difference is a bug, fixed in all of them. Text TradingView refuses has no such promise, so write a script TradingView's way (see Pine compatibility). The engines has the details.
Open the Script Editor
Press / to open the command field at the top of the terminal, type SCRIPT and press Enter. The editor opens in a pane of its own. The first time, it holds a blank indicator: select all of its text and paste the script above in its place.
Add it to the chart
Press Add to chart, or Mod+Enter (Ctrl+Enter, or Cmd+Enter on a Mac). The editor checks the text, runs it on the chart's bars and draws three lines over the candles. Once the study is on the chart, the button reads Update on chart: press it again after each edit.
Each line of the script does one job:
| Line | What it does |
|---|---|
//@version=6 | Says the text is Pine Script v6. TradingView needs it, and our engine reads every script as v6 anyway. |
indicator(...) | Names the script. overlay = true draws it on the price pane; leave it out for a pane of its own. |
input.int(...) | Makes a setting with a default of 20, shown in the study's settings. |
ta.sma, ta.stdev | Built-in functions, computed on each bar. |
plot(...) | Draws a value on every bar, under the title you give it. |
A script runs once on each bar, from the oldest to the newest, and every name holds that bar's value. How a script runs explains what a bar sees.
Read what the editor says
The status line, under the editor's toolbar, says how the run went: Compiled, what the script is (Indicator on the chart, 3 plots), and how many bars it ran on in how many milliseconds.
When the text has a problem, the status line counts the errors and offers Go to first error, and the console under the code lists each one at its line. F8 steps to the next problem and Shift+F8 to the one before. The editor also checks as you type, so most mistakes show before you run anything. A text that doesn't compile changes nothing on the chart.
Change an input
Hover the study's name in the chart's legend and press its Settings button. Length is there with its default of 20. Change it, and the chart runs the script again with the new value. The script's text doesn't change. The legend's Remove button takes the study off the chart.
To read every plot's value at one bar, type DATAWINDOW in the command field: the data window lists them at the bar under the crosshair.
Save the script
Press Save, or Mod+S. Each save keeps a version, which Version history in the editor's menu lists, so you can look at an old one or restore it. A study made from a saved script comes back on the chart after a reload. A study made from text you never saved is the editor's own: the chart holds one such study, and each Update on chart replaces it.
See also
- Your first strategy: backtest a rule and read the Strategy Tester.
- Pine or AmenoScript: which dialect to write in.
- Inputs: every kind of setting a script can offer.
- Plots and colours: lines, fills, shapes and colours.
- Errors and debugging: what each kind of message means.