What a script is, and where it runs
The sandbox, and an honest list of what a script cannot do.
An NCR script is a small program you write that reads the bars on your chart, works something out from them, and draws the answer back onto the chart. That is the whole idea. Every indicator in the app started life as the same shape of calculation; a script lets you write one the app does not have.
It runs INSIDE YOUR BROWSER, on your machine, and never on a server. Nothing you write is sent anywhere unless you deliberately save or publish it. When you press Run, the app starts a small JavaScript engine in a background thread and hands your code to it along with a copy of the bars currently on screen.
The engine is deliberately empty. It is not a browser tab and it is not the app. It has no page, no window, no address bar and no connection to anything. The only thing placed inside it is one object called ncr, and everything a script can do it does through that object.
Two consequences follow, and both are worth internalising early. First, a script someone else wrote cannot steal anything from you, which is why installing one is safe in a way that running a downloaded program never is. Second, a script cannot reach data you could not already see yourself — every figure it reads comes back through the same request, with the same login, that the app itself uses.
Here is a complete script. It is not useful, but it is real: paste it in, press Run, and the message appears in the debug panel underneath the editor.
// Every script starts by saying what it is. This one is a study// (an indicator) rather than a strategy.ncr.study({ name: 'Hello', overlay: true }); // main() is where the work happens. The app calls it once, for you.export function main() { // ncr.log writes to the debug panel under the editor. ncr.log('Hello from ' + ncr.chart.symbol() + ' on the ' + ncr.chart.timeframe() + ' timeframe'); ncr.log('There are ' + ncr.data.length() + ' bars loaded right now.');}If you saw two lines appear in the debug panel, you have written and run a program. The rest of this track is about what to put between those braces.