Pine Script on NepseX
Last updated 29 October 2026
The indicators and strategies on NepseX charts are written in Pine Script, the scripting language of TradingView. If you have written or copied a TradingView script before, you already know the language used here.
Which language
Pine Script®, versions 5 and 6. The first line of a script says which one, for example //@version=6. Pine Script is designed and documented by TradingView; NepseX follows that definition rather than inventing its own, so TradingView's user manual and language reference are the documentation for the language itself. Version 6 is the current one; most older v5 scripts run unchanged.
Pine Script is a trademark of TradingView. NepseX is not affiliated with TradingView.
How a script runs here
- In your browser, not on our server. NepseX uses PineTS, an open-source engine by LuxAlgo that turns Pine Script into JavaScript and runs it with Pine's own time-series rules.
- Once per candle, oldest first. As on TradingView, the script runs on every bar from the start of the history to the latest one;
closeis this bar's close andclose[1]the previous bar's. See the execution model. - Kept apart from the page. Scripts run in a Web Worker, a separate browser thread with no access to the page or your account. A community script cannot read your wishlist or journal, or act as you.
- On NEPSE data. Bars are NEPSE daily prices, adjusted for bonus and rights shares, plus the weekly and monthly views built from them.
NEPSE specifics
- Symbols are NEPSE tickers such as
NABILorNICA. The index isNEPSE, sorequest.security("NEPSE", "D", close)reads the NEPSE index inside any stock's script. - Strategy defaults: a strategy that does not set its own uses Rs 10 lakh starting capital and 0.44% commission per side, close to NEPSE's broker commission, SEBON fee and DP charge combined.
- Long only. NEPSE has no short selling, so write
strategy.longentries and close them; a short entry tests something you cannot trade. - What the backtest leaves out: capital gains tax, NEPSE's daily price limits (a stock locked at its limit cannot be bought or sold) and slippage on thinly traded stocks. Real results are lower.
- Daily data. There is no intraday history, so intraday timeframes and per-tick logic do not apply.
What is supported
Indicators and strategies; inputs (shown in the settings dialog); plot, plotshape, fill and background colours; the ta.* and math.* functions; arrays; request.security; and drawing objects such as labels, lines and boxes. PineTS is young and adds functions often: if a script fails with an unknown function, check the API coverage list. The error shows under the preview when you edit a script.
Two examples
An indicator
//@version=6
indicator("Two moving averages", overlay = true)
fast = ta.sma(close, input.int(20, "Fast length"))
slow = ta.sma(close, input.int(50, "Slow length"))
plot(fast, "Fast", color.teal)
plot(slow, "Slow", color.orange)
plotshape(ta.crossover(fast, slow), "Cross up", shape.triangleup, location.belowbar, color.teal)A strategy, using the NEPSE index as a filter
//@version=6
strategy("SMA cross, long only", overlay = true)
fast = ta.sma(close, 20)
slow = ta.sma(close, 50)
// Only trade while the NEPSE index is above its 50-day average.
indexUp = request.security("NEPSE", "D", close > ta.sma(close, 50))
if ta.crossover(fast, slow) and indexUp
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")Both were run on NEPSE data in the chart's engine while writing this page.
Writing and sharing your own
- Publish a script: paste or write Pine Script, see it run on a live chart as you type, then publish it to everyone or keep it private.
- Open any script on a chart from the community library or the chart's Indicators button.
- Copying someone else's TradingView script? Keep their credit and licence. Many published scripts use licences such as the Mozilla Public Licence that require it.
- Scripts marked Tested by NepseX were checked against NEPSE data and our own Python results. Every other script is its author's idea, and none of it is advice. See the risk disclosure.
Links
The language (TradingView, the standard it follows)
- Pine Script user manual: Start here: concepts, examples, how scripts are built.
- Pine Script v6 reference: Every built-in function, variable and keyword.
- Execution model: Why a script runs once per bar, and what close[1] means.
- Strategies: strategy(), orders, the backtest report.
- Moving from v5 to v6: What changed between the two versions NepseX runs.
The engine NepseX uses
- PineTS documentation: The open-source runtime that runs Pine on NepseX.
- PineTS API coverage: Which Pine functions are supported today.
- PineTS on GitHub: Source code and issue tracker.
- Vela-pinets on GitHub: How the engine plugs into the chart and runs in a Web Worker.
- GNU AGPL-3.0 licence: The licence of PineTS and Vela-pinets.
- Web Workers (MDN): The browser feature that keeps scripts away from the page.