millionchart
فارسی

Questions people ask

Short, honest answers to the questions members ask most about writing scripts, the editor, the limits, alerts and the Strategy Lab.

Short answers, each with a link to the page that explains more. If your question is not here, ask on the support page.

The editor and your scripts#

Where is the script editor?#

Open the Indicators panel, go to the On chart tab and look under My scripts. New script opens the editor with a small working example. See The editor.

Who can write scripts?#

Every signed-in member has the editor. A visitor who is not signed in does not; sign up first.

How many scripts can I keep?#

The free chart plan keeps 2 scripts; MillionChart Pro keeps up to 100. A script may be up to 400,000 characters long.

Can I share a script with someone?#

No. Every script is private to your account and nobody else can open it; there is no way to share one in this release.

Can I open a script I keep as a file?#

Yes: Open file in the editor opens a text file (.txt) from your computer, or drop the file on the code.

Does my script run when the chart is closed?#

No. A script runs in your browser, on the chart you have open. Nothing of your script runs on the server in this release.

Can I paste a program written for another charting program?#

Not as it is: it is a different language. If your account has the import entry in the editor's Scripts menu, it offers an experimental conversion of a limited subset; most programs are refused, and what converts must be checked line by line. Rewriting the idea in this language, with the tutorial at hand, is usually quicker.

When the result is not what you expect#

Why does my line start a little after the first bar?#

A calculation needs enough bars first. A 20-bar average has no value on the first 19 bars, so the line starts on bar 20. Until then the value is na, "no value", and a plot draws nothing where its value is na.

Why is my value na?#

Either there are not enough bars yet, or the arithmetic has no answer (0 / 0 is na), or a value it depends on is na: na + 1 is na. Test it with is_na(x) and give a fallback with x ?? 0. See na, errors and arithmetic.

Why is x == na never true?#

na is not equal to anything, not even to itself. The checker warns about it (W-NA-COMPARE); write is_na(x).

Why does my signal on the newest bar come and go?#

The newest bar is still forming: its close is the latest price and changes until the bar closes, so a condition can be true one moment and false the next. Test on closed bars when that matters. See Results that look too good.

What does E3302 mean?#

A call that remembers earlier bars, such as tech.sma, stands on the right side of and, or or ??, or in a branch of if ... then ... else. That part runs only on some bars, so the call's memory would skip bars. Work the value out on a line of its own first (let average = tech.sma(close, 20)) and use the name. See Lazy operators.

Where do I find what a code means?#

Every message has a stable code such as E3171. Diagnostics lists each code with its cause and fix; messages of a script that stops while it runs are in Engine messages. Lesson 18: Reading the editor's messages walks through the common ones.

My script stopped on the chart. Why?#

It compiled, but the run hit a limit: a loop that does too much work, a window longer than the history, or a request the engine refuses. The editor shows Stopped on the chart with the message and the bar. See Limits and budgets.

What the language can and cannot do#

Can I read another symbol from my script?#

No. A script reads the chart's own symbol only; a request for another symbol stops the script with an error that names it (E4001). You can read other timeframes of the same symbol with data.series. See Other timeframes and symbols.

Can I read a higher timeframe without peeking into the future?#

Yes, that is the default: data.series gives the last bar of the other timeframe that has closed. Reading the forming bar or a future value needs live = true or future = true, and the editor lists a warning when you do (W-LIVE-READ, W-FUTURE-READ).

Is there a power operator?#

No. Write math.pow(x, 2). The arithmetic operators are +, -, *, / and %.

Can a function call itself?#

No: a function that calls itself is refused (E3310). Write a loop instead. See Functions, types and enums.

Can I use code from one script in another?#

Yes, with a module: save a script whose header is module Name, and import it in another of your scripts with import Me/Name@1 as alias. Only your own modules can be imported. See Modules and libraries.

What is not available yet?#

A list of the things people expect and that this release does not have is in Limits and budgets.

Alerts, strategies and trading#

Why does my script's alert never reach me?#

Alerts on your own scripts are switched off in this release. Creating one is refused with the message "Alerts on your own scripts are not available." The calls alert.when and alert.send still compile and run. See Alerts that say something.

Can a script trade for me?#

No. MillionChart is not a broker and executes no real orders. A strategy places simulated orders on the bars of the chart, and the chart shows the trades that would have happened, with the costs you declare. See Your first strategy.

What is the Strategy Lab, and what does the free plan include?#

The Strategy Lab tests a strategy over history and reports its trades and results. Open it with Strategy lab — backtest a strategy in the top bar, from More › Strategy lab, or with Test in the editor on a strategy. Today the free chart plan has 10 Lab runs a month on up to 92 days of history; optimisation and the other tools beyond a single run come with MillionChart Pro. See Lesson 15: Testing in the Strategy Lab.

Does a good test result mean a strategy will make money?#

No. A test replays the past on simulated fills; the future can differ, and a result can look good by chance or because the script used something a bar could not have known. Nothing here is investment advice. Read Results that look too good before you trust a result.

Getting help#

I think I found a bug. What do I do?#

Write to support from the support page. Say what you expected and what happened, and paste the smallest script that shows it, with the symbol and the timeframe.

See also: Glossary, Cheat sheet.