millionchart
فارسی

The editor

Where scripts are written, how the editor shows problems as you type, how to save a script, put it on the chart and update it, and how your scripts are kept.

The script editor is a panel under the chart (full screen on a phone). The chart narrows to make room, so nothing covers the price. You open it from Indicators, on the On chart tab, under My scripts: pick a script to edit it, or New script to start one. A new script opens with a small working example.

What you see#

  • The code, with line numbers, colours for comments, texts, numbers and built-in names, and matching brackets. The indentation is four spaces; the Tab key indents.
  • The name of the script at the top, which is what the chart and the Indicators panel call it.
  • A status next to the name. Ready means the script has no problem. Ready (strategy) says the script is a strategy. Ready · 2 notes means it works and has warnings to read. 1 problem means it does not compile yet; the editor shows the first error it finds.
  • A list of Problems or Notes beside the code. Each entry names the line and its code (such as E3171). A problem is an error that stops the script from running; a note is a warning that does not. Where the mistake can be mended mechanically, the entry offers a Fix.
  • A module shows Library — ready to import when it compiles; it draws nothing itself (see Modules and libraries).

The editor checks the script a moment after you stop typing and marks the line: a wavy underline, red for a problem and amber for a note, with the message.

A script can work and still deserve a second look. This one runs, and the editor lists a note for it, because the engine warns that it reads the forming hourly bar, whose value moves:

Cuprel · warning W-LIVE-READ
indicator "A note, not a problem"
    edition = 1
    display = price

let forming = data.series("60", close, symbol = symbol.id, live = true)
plot(forming)

If you misspell a name, the editor shows a problem and, where it can, names the one you probably meant. A rule of an input that names a price or a variable (show_if or check) is the problem E3133, and show_if rules that lead back to each other are E3134; both are found as you type, and Inputs says what a rule may name. The editor shows the line, the message and its code; Reading the editor's messages walks through the ones you will meet first.

Completion#

While you type, the editor offers the built-in functions with their parameters and the built-in variables such as close and bar.index. Press Enter to accept a suggestion. In this release the parameter names that the suggestions and the hover card show can differ from the names the checker accepts: a plot, for example, takes name and width. When a name is refused, the message lists the accepted ones, and the Function index lists every function with the parameters it accepts.

The toolbar#

ActionWhat it doesShortcut
SaveKeeps the script; signed in, it is kept with your account, the same on every device. A copy already on the chart runs the new codeCmd or Ctrl + S
Add to chartPuts the script on the chart like any other indicatorCmd or Ctrl + Enter
Update on chartReplaces the running copy with the new code; the inputs, the look and the visibility stay as they wereCmd or Ctrl + Enter
Test (strategies)Saves the script and runs it in the Strategy Lab (Lesson 15)
FormatRewrites the script in the canonical layout (indentation, spaces, line breaks); the meaning does not change. A script with errors is not formattedShift + Cmd or Ctrl + F
Open fileOpens a script kept as a text file (.txt) on your computer; you can also drop the file on the code
LearnEight short lessons, each a program to finish; Check my work runs it on your chart and says what is still missing
DocsOpens this guide in a new tab
Delete (the bin)Removes the script, after you confirm with Delete (or Keep to change your mind)

Write edition = 1 in the header of every script. It says which reading of the language the script was written for; without it the current edition is used. A script must be small enough to save: 400,000 characters at most. The number of scripts you can keep depends on your plan: see Limits and budgets.

The Scripts menu at the top lists your other scripts and starts new ones:

  • New script opens a new script with a small working example.
  • From a template starts from a small working program: an indicator, a strategy, an alert on a signal, a trading session or a dashboard table.
  • Format when saving formats the script each time you save it, while it is ticked.
  • If your account has it, an entry to bring in a script written for another charting program. It is an experimental source conversion of a limited subset: most programs are refused, and what converts must be checked line by line. This guide does not cover it.

You can resize the panel by dragging its top border.

If a script stops on the chart#

A script that compiles can still stop while it runs: it may spend more than the budget, or ask for another symbol's data. The editor then shows Stopped on the chart with the engine's message, which names the bar and the line. Limits and budgets lists what the engine bounds.

Private by default#

Scripts belong to your account. Nobody else can open one, and there is no way to share a script in this release. The free chart plan keeps 2 scripts; MillionChart Pro keeps up to 100.

See also: Your first script, Reading the editor's messages, Modules and libraries.