Frequently asked questions

The questions that come up most often when writing SahiScript.

Getting started

What is SahiScript?

SahiScript is the scripting language used to build custom indicators on Sahi charts. Every built-in indicator on a Sahi chart is written in SahiScript, so your own scripts have the same capabilities.

Is SahiScript compatible with Pine Script?

SahiScript is compatible with Pine v6 syntax, so an indicator written for another charting platform generally runs with little or no modification. A few features are not supported yet — see what is not supported — and SahiScript adds functions for Indian markets that have no equivalent elsewhere, such as options data and a derivatives expiry input.

Do I need a //@version=6 line at the top of my script?

No. The version line is accepted so that scripts copied from elsewhere work unchanged, but it is optional and does not change how your script behaves.

How do I create a script?

Open the indicator picker and go to the My scripts tab, or choose Create new in the script editor. Either way you start from a working template.

Apply runs the script on the chart without saving it, which is what you want while experimenting. Save stores the script under your account and applies that version. Both leave the editor open.

What does every script need?

Exactly one indicator() declaration at the top level. A script with no declaration, or with more than one, will not run.

Saving and syncing

Where are my scripts saved, and can other people see them?

Saved scripts are stored under your Sahi account and sync to every device you sign in on. There is no way to publish or share a script from the app, so nobody else can load a script you have written.

How many scripts can I save?

Up to 20 saved scripts, each up to 250 KB of source, with titles up to 128 characters.

What is not supported yet

Can I write strategies?

Not yet. Scripts in this release are indicators: they calculate and draw on the chart, but they do not place simulated orders or produce a backtest report. Strategies are planned for a future release.

Can I import libraries?

Not yet. Publishing a script as a library and importing one into another script are planned for a future release, so each script is self-contained for now.

Can my script trigger alerts?

Not yet. alert() and alertcondition() are accepted so that scripts written elsewhere parse cleanly, but they do not send notifications.

Data and limits

Can I use data from another symbol or timeframe?

Yes. Use request.security and request.security_lower_tf for other symbols and timeframes, request.instrument for Sahi instruments, and request.pcr, request.oi_change_pcr and request.volume_pcr for options data.

Bars before the first higher-timeframe value is available are na, so guard the early bars of your calculation.

How fast do my scripts run?

Scripts execute within milliseconds, but scripts using request.security can trigger network calls to fetch market data for the requested symbol and timeframe, so results may take longer to load.

What limits should I know about?

Troubleshooting

Why does my script say “Execution timed out”?

Each bar has one second to finish. The usual causes are a loop whose length grows with the bar count, or work repeated on every bar that could be calculated once. Move setup out of the per-bar path and keep loop bounds fixed.

Why is my input rejected?

Every input.* call must be assigned to a variable, because the variable name identifies the setting. Write length = input.int(14, "Length") rather than calling input.int() inline inside a larger expression.

Why do some characters not appear in my labels?

Label and table text is drawn with the chart's bundled fonts, which do not cover every emoji. Geometric shapes such as ▲, ▼, ● and ■ render reliably; many emoji show as an empty box.

Why is my line missing when I use xloc.bar_time?

With xloc.bar_time the x coordinates must be timestamps in milliseconds, not bar index numbers. Passing a bar index places the line far off screen, where it never becomes visible.

Why does close[-1] not work?

History offsets must be zero or positive, so close[1] is the previous bar. A negative offset would look into the future and is rejected rather than returning na.

Still stuck? The editor reports errors and warnings as you type, and its autocomplete and hover documentation are the most complete reference until the documentation is published.