Pine Script on Your Phone: Write, Check and Backtest Scripts in StockYatra

Write a Pine Script on your phone, tap Check to see errors by line, then Save & run to see it on the chart with a full backtest. What is supported, an example, and the 15 library scripts.

By StockYatra Team
The Pine Script editor in StockYatra next to a chart with a backtest

In short

  • Pro Chart has a Pine Script editor with line numbers.
  • Tap Check to see any error by line, then Save & run to draw it on the chart.
  • Strategy scripts get a full backtest; indicator scripts draw plots and markers.
  • A practical subset of Pine Script v5, plus 15 ready-made scripts to run or copy.

Pine Script is the small language many traders use to describe indicators and strategies. It is a good way to learn, because you have to say exactly what you mean: when to enter, when to exit, and what to plot. StockYatra now runs it right on your phone.

Pine Script editor with an EMA cross strategyThe result drawn on the chart with a backtest
Write a script, then see it on the chart.

Your first script

This is the library's EMA crossover. It goes long when the 9 EMA crosses above the 21 EMA and closes when it crosses back:

//@version=5
strategy("EMA Crossover", overlay=true)
fastLen = input.int(9, "Fast EMA", minval=2, maxval=100)
slowLen = input.int(21, "Slow EMA", minval=3, maxval=300)
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
plot(fast, "Fast EMA", color=color.blue)
plot(slow, "Slow EMA", color=color.orange)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.close("Long")

Open Pro Chart → Pine Script, tap the copy icon on EMA Crossover, change 9 to 12, and tap Save & run. The new lines and arrows appear on the chart, with the backtest underneath.

Errors you can understand

Tap Check before you run. If something is wrong you get the line number and a plain message, for example Line 13: "foo" isn't defined. Declare it first, e.g. foo = close. Fix the line and check again.

What is supported

AreaSupported
Script typesindicator(), strategy() with overlay=
Inputsinput.int, input.float, input.bool (title, minval, maxval, step)
Variables=, var, :=, +=, tuples like [m, s, h] = ta.macd(...)
Logicif / else if / else, for … to, ternary ?:, and / or / not, history like close[1]
Indicatorsta.sma, ema, wma, rma, hma, vwma, rsi, macd, stoch, cci, mfi, wpr, atr, stdev, bb, supertrend, vwap, obv, dmi, highest, lowest, change, roc, crossover, crossunder, pivothigh, pivotlow, barssince, valuewhen and more
Drawingplot, hline, plotshape, plotchar, colours with color.new and hex
Ordersstrategy.entry, strategy.close, strategy.close_all, strategy.exit with stop and limit

Not supported yet: your own functions (=>), switch, while, and types, methods or imports. These give a clear "not supported" message.

The 15 library scripts

ScriptType
EMA Crossoverstrategy
RSI Reversalstrategy
MACD Signal Crossstrategy
Bollinger Mean Reversionstrategy
Supertrend Flipstrategy
Donchian Breakoutstrategy
Golden Crossstrategy
ATR Trailing Stopstrategy
ADX Trend Filterstrategy
VWAP with Bandsindicator
Stochastic %K %Dindicator
Momentum (ROC)indicator
Volume Spike Finderindicator
CCI Zonesindicator
Pivot Highs & Lowsindicator
Key idea: Start from a library script, change one thing, and compare the backtest. Changing one thing at a time is how you learn what each part does.

Key takeaways

  • Pine Script v5 subset runs in the app, free.
  • Check shows errors by line before you run.
  • Strategies get a backtest; indicators draw plots and markers.
  • 15 scripts to run or copy.

Summary in Nepali (नेपालीमा सारांश)

StockYatra को Pro Chart मा अब फोनमै Pine Script लेख्न सकिन्छ। Check थिच्दा गल्ती कुन लाइनमा छ भनेर देखाउँछ, Save & run थिच्दा चार्टमा देखिन्छ र ब्याकटेस्ट पनि आउँछ। सुरुमा प्रयोग गर्न १५ वटा तयारी स्क्रिप्ट छन्।

Write your first script

StockYatra is free on the App Store and Google Play. Already installed? The October update arrives automatically the next time you open the app. You start with 10,000 free virtual coins; prices are simulated and coins are never real money.

Get StockYatra See the changelog

More from the October update

StockYatra is an education app, not a broker or adviser. Prices on its practice market are simulated around each stock's real-world level, coins are virtual, and nothing here is a recommendation to buy or sell any security. Backtests describe the past and do not predict future results.

Frequently asked questions

Is this full Pine Script?
It is a practical subset of Pine Script v5 covering inputs, variables, if/else, for loops, history, 30+ ta functions, plots and strategy orders. Custom functions and switch are not supported yet.
Where are my scripts saved?
On your phone, under My scripts on the Pine Script tab. You can edit or delete them any time.
Can I paste a script from elsewhere?
Yes. Paste it into the editor and tap Check. If it uses something not supported, you will see which line.