Feature
Python Indicators for Indian Stock Charts
TradingLead lets you write chart indicators in ordinary Python: define calculate(bars, params), return plots and drawings, and they render on the chart. In the browser, compatible code runs in an isolated Pyodide sandbox with the standard library, NumPy and pandas; the TradingLead Desktop app runs Python when installed and is required for the TradingLead SDK and other packages.
What it does
Python indicators let you turn any calculation you can express in Python into a chart overlay or a separate indicator pane on TradingLead. If you already analyse Nifty or Bank Nifty data in pandas, you can bring the same logic onto a live chart.
There is no new language to learn. You write a normal function:
def calculate(bars, params):
closes = [bar["close"] for bar in bars]
return {
"title": "Close",
"overlay": True,
"plots": [{"id": "close", "title": "Close", "color": "#2962ff", "values": closes}],
"drawings": [],
}
How it works
- Input:
barsis a chronological list of OHLCV dictionaries (timein Unix milliseconds,open,high,low,close,volume; missing volume isNone).paramsis a JSON-style dictionary of your settings. - Output: return a dictionary with a
title,overlay(on the price chart or in its own pane), a list ofplotsand an optional list ofdrawings. - Runtime:
- In the browser, compatible code runs in a pinned Pyodide build inside a fresh, isolated iframe. Packages load first; then network APIs are disabled. The sandbox is destroyed after each calculation.
- If the TradingLead Desktop app is installed, it becomes the runtime automatically. It is required for
tradingleadSDK/Strategy imports, native or OS-level modules, arbitrary packages and workloads that need hard memory/process limits. - If your code needs Desktop, Studio tells you exactly why and links to the desktop app.
Key capabilities
- Plain Python: functions, loops, classes,
math,statistics, plus NumPy and pandas in the browser. NumPy arrays and pandas Series are accepted as plot values. - Plot styles:
line,linebr,stepline,histogram,columns,area,cross,circles, pluscandlesandbarsfor OHLC output. Per-bar colours are supported. - Drawings: text, rectangles, trend lines, horizontal and vertical lines, rays, extended lines and up/down arrows, anchored to exact candle timestamps.
- Typed settings: add
# @inputcomments to get form controls —int,float,bool,string,enum(dropdown) andcolor(picker), with titles, groups and bounds. - Multiple timeframes and symbols: declare extra datasets with
# @datacomments and read them from an optional thirdcontextargument. Secondary datasets contain closed candles only, from the same provider — no silent fallback to another exchange. - Named plot settings: each plot keeps its own name, colour, width and style in a TradingLead settings panel. Apply style does not rerun Python; Apply & recalculate does.
- AI prompt panel: generates a complete, editable authoring prompt (Indicator or Backtest strategy) to paste into your own AI; your code is included only if you tick the option.
- Saved indicators: saved Python indicators appear under My saved indicators in the chart's Indicators dialog.
How to use it
Follow Write a Python indicator on TradingLead for a full walkthrough, from a simple moving average to a multi-timeframe pandas example.
When to choose Python vs Pine
| Choose Python when… | Choose Pine when… |
|---|---|
| You already have pandas/NumPy logic | You have an existing Pine v5/v6 script |
| You need custom data structures or statistics | You want Pine's ta.* built-ins and Pine-style inputs |
| You want to reuse research code | You prefer a TradingView-like syntax |
Both run in Indicator Studio and both can be saved and added from the Indicators dialog.
Limitations
- Browser Python is limited to the standard library, NumPy and pandas. Everything else requires the Desktop app's isolated package environment, which is set up explicitly — scripts cannot install packages themselves.
- Return exactly one value per primary candle per plot, using
Nonefor warmup and gaps. - Desktop runtime limits: 100,000 combined primary and secondary candles, 64 MiB serialized input/output, 20,000 visual objects, 2 million output values, 15 seconds per calculation and 512 MiB memory. Results are never silently truncated — oversize output fails with an explicit error.
- No internet access during execution.
- Vectorized strategy backtests do not verify lookahead; write causal code. Backtests are simulations, not guarantees.
Limitations
- Browser Python supports the standard library, NumPy and pandas; other packages and the tradinglead SDK require the Desktop app.
- One numeric value per primary candle must be returned for each plot.
- Desktop runtime limits: 100,000 combined candles, 64 MiB input/output, 20,000 visual objects, 15 seconds per calculation, 512 MiB memory.
- No network access during execution; extra datasets must come from the chart's provider.
Frequently asked questions
- Can I write trading indicators in Python on TradingLead?
- Yes. In Indicator Studio choose Python, write a calculate(bars, params) function that returns plots and drawings, and click Run on chart. No special SDK is required.
- Do I need to install anything to run Python indicators?
- Not for compatible scripts. In a supported browser, code using the standard library, NumPy or pandas runs in an isolated Pyodide sandbox. The TradingLead Desktop app is needed for the tradinglead SDK/Strategy imports, other or native packages, and hard memory/process limits.
- Can my Python indicator use another timeframe or symbol?
- Yes. Declare it with a '# @data' comment (for example a daily dataset) and read it from the optional third context argument. Data comes from the same provider as the chart and contains closed candles only.
- Can a Python indicator access the internet?
- No. Network access is disabled while browser Python executes, and the Desktop runtime blocks network access, personal files and subprocesses.
- Can I backtest a Python strategy?
- Python strategies can be authored in Studio and run in Backtesting; the Backtest action requires a ready chart and the Desktop Python runtime. Backtests are simulations, not guarantees.
Related
Last updated: