Write Scripts with AI
You do not need to know programming to make your own indicator. Tell an AI what you want in plain English or Nepali, and it writes the NCR script for you. NChartPro gives the AI our script guide first, so it writes a script that works here — not TradingView Pine Script. This page shows every way to do it, with real examples you can copy.
What this page is
NCR Script is the small programming language of the Script tab on the chart. A script reads the candles, works something out, and draws lines, arrows, bands or tables on your chart. It is plain JavaScript with one extra object called ncr.
Any AI can write it — ChatGPT, Claude, Gemini, Perplexity, Copilot, DeepSeek and others — as long as it reads our script guide first. Without the guide an AI guesses, and it usually writes Pine Script from TradingView, which does not run here.
The Ask AI button in the Script tab does this for you. It opens the AI with your request AND the link to our guide already typed, so you only press Send. It works with free AI accounts. You do not need to set anything up.
The guide the AI reads is open to anyone: https://nchartpro.com/ncr-skill.md (short) and https://nchartpro.com/ncr.txt (full). The same guide as a web page is at https://nchartpro.com/help/script/ai, and a copy is kept on GitHub at https://github.com/Amritshr/nchartpro-ncr-skill.
Why it helps you
- Turn your own setup into an indicator in a minute: "buy arrow when price closes above the 20-day high with volume 2 times the average". The AI writes it, you run it, and you see every past signal on the chart.
- Make a buy/sell signal script and test it in Trading Horizon. The AI knows the rule: the script must plot one line called signal, with 1 on a buy day and -1 on a sell day.
- Copy a Pine Script you found online and ask the AI to convert it to NCR. Our guide has a Pine-to-NCR table, so the AI translates it instead of pasting Pine code that does not run.
- You can ask for simple, slow indicators too: a 200-day average, a 52-week high and low channel, or a line that shows how far price is from its yearly average.
- A script only draws and calculates on your own chart. It can never buy or sell, never touch your account, and never send your data anywhere.
- A signal on the chart is not advice. Always read what the script does — the AI explains it in a few lines under the code.
When to use it, and where to find it
- When the indicator you want is not in the indicator list, or you want your own version of one.
- When you have a trading rule in your head and want to see where it would have fired on past candles.
- When a script shows an error — the AI can fix it for you in one click.
- Main → Chart → the Script tab at the bottom of the chart → the Ask AI button (✦) on the Script toolbar. The Script tab can also be popped out into a floating window; the button is the same there.
- The full-page Script editor, in the Experimental menu → Script, has the same button. The Script help page (/help/script) has the same one-click AI buttons in the strip at the top.
- The Ask AI box has a "Full help with examples ↗" link at the top. It opens this page.
- Once a script is saved, it is also in the Indicators box (ƒx on the chart toolbar) under the my scripts chip, so you can add it to any chart like a normal indicator.
Try it — a short walkthrough
- 1Open the Script tab and press Ask AIOpen the chart, pick a stock, and open the Script tab at the bottom. Press Ask AI on the Script toolbar. A box opens with three numbered steps.
- 2Step 1 — write what the script should doType it in plain words, English or Nepali, in the first box (up to 2,000 letters). Say what to draw and when. For example: "RSI 14 with a 9-day average of the RSI, in its own pane." The AI buttons stay grey until something is typed.
- 3Step 2 — click an AI and press SendClick ChatGPT, Claude or Perplexity. The AI opens in a new tab with your request and our guide link already typed — press Send. For Gemini the request is copied for you: click the message box, press Ctrl + V, then Send.
- 4Step 3 — copy the code and bring it backWhen the AI answers, press its "Copy code" button above the script. Come back to NChartPro and press "Paste the AI’s script". The script opens in the editor as a new script and a note says "The script is in the editor. Press Run." If you are not signed in, the box says to sign in, press New in the editor and paste with Ctrl + V.
- 5Run it, change it, keep itPress Run (Ctrl + Enter). The lines appear on the chart. Change the numbers in the Inputs rail on the right — no code editing needed. Press Save, then Add to chart to keep it as a normal indicator.
- 6If it shows an error, let the AI fix itOpen Ask AI again. A red box headed "The script shows an error — let the AI fix it" shows Fix in ChatGPT, Fix in Claude, Fix in Gemini and Fix in Perplexity. Each sends your script and the error to that AI together. Copy the fixed code and press "Paste the AI’s script" again. If you use your own AI key, a "Fix with my AI key" button there fixes it in place with no copy and paste.
Reading the numbers
- The paid way, with no copy and paste: if your plan includes it and you saved your own AI key in AI Chat → Settings → My API keys, the Ask AI box shows "Write script". Press it and the script appears in the editor directly. It uses your own key — your AI account pays, not NChartPro. A key from OpenAI (ChatGPT), Gemini, DeepSeek, Kimi or OpenRouter (which also gives Claude) works.
- The own-key box, step by step: it is headed "Faster: write it right here with your own AI key". If your plan does not include it, the box says so and reminds you the free way above works for everyone. If you have no key saved yet, it tells you where to add one: AI Chat → Settings → My API keys. Once you have a key, a list shows each of your keys by name, model and the last four characters, so you can pick which one to use. Press Write script; the button reads "Writing… (up to a minute)" while the AI works. When it is done the script is in the editor — press Run.
- When the clipboard cannot be read: some browsers do not let a web page read what you copied. Then a box opens under the Paste button that says so. Paste the AI’s code there with Ctrl + V and press "Put it in the editor".
- Ready-made examples: besides asking an AI, the Script editor has its own examples to open and change, including 15 made for testing in Trading Horizon. Each one draws a signal line and explains every part in plain comments. Save one, then use it as a rule in Trading Horizon.
- Using it as an indicator: after Save, press Add to chart on the Script toolbar, or open ƒx on the chart toolbar and find the script under the my scripts chip. From then on it behaves like any other indicator: a legend row with the eye, ⋮, gear and ×, and its inputs in the settings box.
- What the AI is told: the prompt asks it to read https://nchartpro.com/ncr-skill.md first, to give ONE complete script in ONE code block, and then to explain it in short, simple steps. You can see the whole prompt under "More ways" in the Ask AI box.
- Set it up once, if you like: in ChatGPT you can make your own GPT, in Gemini a Gem, and in Claude a Project or a Skill, each with our skill file attached. Then you just ask for an indicator. The steps are under "More ways" in the Ask AI box and on /help/script. Some AIs need a paid account for this; the one-click way above does not.
- Pasting: "Paste the AI’s script" reads what you copied. If you copied the whole answer, it takes only the code block out of it. If your browser does not allow reading the clipboard, a box opens — paste there with Ctrl + V.
Worked examples — copy, paste, Run
Example 1 — RSI with its own average, in a pane
What was typedRSI 14 with a 9-day average of the RSI, in its own pane.
// RSI with its own average, in a pane under the chart.
ncr.study({ name: 'RSI with average', overlay: false });
const rsiLen = ncr.input.int('rsiLen', { label: 'RSI length', def: 14, min: 2, max: 100, step: 1 });
const avgLen = ncr.input.int('avgLen', { label: 'Average length', def: 9, min: 2, max: 100, step: 1 });
export function main() {
ncr.plot.pane('new');
const close = ncr.data.close();
const rsi = ncr.ta.rsi(close, rsiLen);
const avg = ncr.ta.sma(rsi, avgLen);
ncr.plot.line('rsi', rsi, { color: ncr.chart.color('--accent', '#f5a623'), width: 2 });
ncr.plot.line('avg', avg, { color: ncr.chart.color('--color-info', '#4a9eff'), width: 1 });
ncr.plot.hline('ob', 70, { color: ncr.chart.color('--color-down', '#ef5350'), style: 'dashed' });
ncr.plot.hline('os', 30, { color: ncr.chart.color('--color-up', '#26a69a'), style: 'dashed' });
}overlay: false and ncr.plot.pane('new') put it in a pane under the candles, because RSI goes from 0 to 100. Change the two lengths in the Inputs rail.
Example 2 — EMA 20 / 50 with BUY arrows
What was typedShow EMA 20 and EMA 50 on the candles, and a BUY arrow when EMA 20 crosses above EMA 50.
// Two moving averages on the candles, with a BUY arrow where the fast one
// crosses above the slow one.
ncr.study({ name: 'EMA 20 / 50 cross', overlay: true });
const fastLen = ncr.input.int('fastLen', { label: 'Fast EMA', def: 20, min: 2, max: 200, step: 1 });
const slowLen = ncr.input.int('slowLen', { label: 'Slow EMA', def: 50, min: 3, max: 400, step: 1 });
export function main() {
const n = ncr.data.length();
if (n < slowLen + 2) { ncr.warn('Need at least ' + (slowLen + 2) + ' bars.'); return; }
const close = ncr.data.close();
const low = ncr.data.low();
const time = ncr.data.time();
const fast = ncr.ta.ema(close, fastLen);
const slow = ncr.ta.ema(close, slowLen);
ncr.plot.line('fast', fast, { color: ncr.chart.color('--accent', '#f5a623'), width: 2 });
ncr.plot.line('slow', slow, { color: ncr.chart.color('--color-info', '#4a9eff'), width: 2 });
const up = ncr.util.crossover(fast, slow);
for (let i = 0; i < n; i++) {
if (up[i]) {
ncr.plot.marker('buy', {
time: time[i], price: low[i], shape: 'arrowUp', text: 'BUY',
color: ncr.chart.color('--color-up', '#26a69a'),
});
}
}
}overlay: true draws on the candles. ncr.util.crossover marks the exact day the fast line goes above the slow one; the arrow sits under that day’s low.
Example 3 — a buy/sell signal for Trading Horizon (asked in Nepali)
What was typedRSI 30 bhanda tala gayera feri mathi aauda kinne, 70 mathi gaye bechne signal banau. Trading Horizon ma test garne.
// A buy/sell signal for Trading Horizon: 1 = buy day, -1 = sell day, 0 = nothing.
// RSI climbs back above 30 = buy. RSI climbs above 70 = sell.
ncr.study({ name: 'Signal: RSI bounce', overlay: false });
const length = ncr.input.int('length', { label: 'RSI length', def: 14, min: 2, max: 100, step: 1 });
const low = ncr.input.number('low', { label: 'Oversold', def: 30, min: 1, max: 50, step: 1 });
const high = ncr.input.number('high', { label: 'Overbought', def: 70, min: 50, max: 99, step: 1 });
export function main() {
const n = ncr.data.length();
const rsi = ncr.ta.rsi(ncr.data.close(), length);
const buy = ncr.util.crossover(rsi, low);
const sell = ncr.util.crossover(rsi, high);
const signal = new Array(n).fill(0);
for (let i = 0; i < n; i++) {
if (buy[i]) signal[i] = 1;
else if (sell[i]) signal[i] = -1;
}
// The plot id must be 'signal' — that is the name Trading Horizon shows.
ncr.plot.pane('new');
ncr.plot.histogram('signal', signal, { color: ncr.chart.color('--accent', '#4a9eff') });
}Save it, then open Trading Horizon, pick this script and use: Buy when signal ≥ 1, Sell when signal ≤ -1. NEPSE has no short selling, so a sell day means exit or stay out.
Example 4 — a 20-day high and low channel
What was typedDraw the highest high and lowest low of the last 20 days as a shaded channel.
// Highest high and lowest low of the last 20 days, drawn as a channel.
ncr.study({ name: '20-day high / low channel', overlay: true });
const days = ncr.input.int('days', { label: 'Days', def: 20, min: 2, max: 250, step: 1 });
export function main() {
const top = ncr.util.highest(ncr.data.high(), days);
const bottom = ncr.util.lowest(ncr.data.low(), days);
ncr.plot.line('top', top, { color: ncr.chart.color('--color-up', '#26a69a'), width: 1 });
ncr.plot.line('bottom', bottom, { color: ncr.chart.color('--color-down', '#ef5350'), width: 1 });
ncr.plot.band('channel', top, bottom, { fill: ncr.chart.color('--accent', '#f5a623'), opacity: 0.06 });
}ncr.util.highest and ncr.util.lowest give one value per day. ncr.plot.band shades the space between the two lines.
Example 5 — fixing an error with one click
What was typedI pasted a TradingView script and pressed Run.
plot(close)
Error in the Debug panel:
NCR2003 This script declares neither ncr.study({...}) nor ncr.strategy({...}).That is Pine Script, not NCR. Open Ask AI and press "Fix in ChatGPT" in the red box. The AI gets the script and the error together and sends back a whole NCR script, like Example 4 above. Copy it and press "Paste the AI’s script".
What it does not do
- The AI can still make a mistake. Our guide makes it much rarer, but always press Run and look at the result before you trust a line or an arrow.
- A script has only two places to draw: the candles, and ONE pane under them. Two things on very different scales (for example an RSI and a ±1 signal) should be two scripts.
- The one-click way needs you to copy the answer back yourself — an outside AI cannot put a script into NChartPro on its own. Only the own-key "Write script" puts it in directly.
- Gemini does not accept a pre-typed message from a link, so for Gemini you press Ctrl + V once.
- A script cannot read the internet, place an order, or see your account. If the AI writes fetch(), localStorage or setTimeout, the editor refuses it — ask the AI to fix it.
Questions people ask
No. The one-click Ask AI way works with free ChatGPT, Claude, Gemini and Perplexity accounts. Only the "Write script" button inside NChartPro needs your own AI key and a plan that includes it.
It did not read our guide. Use the Ask AI button — its prompt tells the AI to read https://nchartpro.com/ncr-skill.md first. If you typed your own message, add: "Read https://nchartpro.com/ncr-skill.md and write NCR Script, not Pine Script."
Open Ask AI → More ways → Download skill file, and attach that file to the AI chat. Or give it the web page version: https://nchartpro.com/help/script/ai.
Yes. Write your request in Nepali or Romanised Nepali. The script itself is always code, but the AI can explain it in Nepali.
In the one-click way, your request goes only to the AI you clicked, in your own account. NChartPro does not see the conversation. With "Write script", your request goes to the AI of your own saved key.
No. Scripts run in a closed box inside your browser. They can only read the candles and draw. They cannot buy or sell, cannot reach the internet, and cannot see your account.