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; close is this bar's close and close[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 NABIL or NICA. The index is NEPSE, so request.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.long entries 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.

The language (TradingView, the standard it follows)

The engine NepseX uses