Skip to content

Guide

Build an Indicator with an AI Assistant

In TradingLead Desktop, an AI assistant can write a Pine v5/v6 or Python indicator for you. It checks the tab's capabilities and validates the exact source with indicators.validate or pythonIndicators.validate. It can save the indicator to your library, apply it to the chart and update its inputs. Pine support is a documented subset, not TradingView parity. Python validation is syntax-only, and some Python features need Desktop. The assistant reads the chart back to confirm what actually rendered.

What the assistant can do

TradingLead's Indicator Studio supports two languages:

With TradingLead Desktop and its AI integration, an assistant such as GitHub Copilot CLI or Claude Code can write the source, validate it, save it and put it on your chart. It does this through the public tl-tlscript and tl-python skills. You see the result in the chart and the Studio, exactly as if you had typed it.

Before you start

  1. Enable Help > AI integrations in Desktop and start your assistant in a new terminal. See control TradingLead with AI.
  2. Open the chart (symbol, feed and interval) you want the indicator on.
  3. Decide on the language. Pine is the natural choice if you know TradingView-style scripts. Python is better for custom logic with pandas or NumPy.

Path A: a Pine indicator

1. Discover what is supported

Ask: "Read indicators.listCapabilities for this tab." Pine v5/v6 support is selective. The skill tells the assistant to validate the exact source rather than guess whether a function is supported.

2. Write and validate

Describe the indicator: "A 20 and 50 EMA pair overlaid on price." The assistant writes source like:

//@version=5
indicator("Trend average", overlay=true)
length = input.int(20, "Length", minval=2)
plot(ta.ema(close, length), "EMA")

It then sends the source to indicators.validate. A response can be status:"ok" and still contain valid:false, so the assistant reads all diagnostics and fixes them. Validation is compile-only. It shows that the script compiles, not that the maths is right.

3. Save (optional) and apply

  • indicators.save stores the source and input values in your library. Updating an existing script needs its current revision.
  • indicators.apply adds it to the chart from the source or a saved ID, with your declared inputs and a retry key.
  • indicators.update changes an existing chart instance instead of adding a second copy. indicators.showInputs opens the input dialog for you.

4. Confirm what rendered

The assistant reads indicators.applied and chart.snapshot. A successful command does not imply a fallback feed or stale candles were used. Check the plotted values yourself.

Porting TradingView scripts

You can paste an existing script and ask for a port. Unsupported constructs get explicit diagnostics. Hosted libraries, TradingView services and external data are not assumed. Pine strategy() scripts compile in the Studio, but they run in backtesting (backtesting.run with language:"pine", vectorized only), not on the chart as indicators. See run a Pine Script indicator.

Path B: a Python indicator

1. Check the runtime

Ask: "Read pythonIndicators.capabilities and tell me if execution is ready." The assistant checks executionReady.

  • The browser sandbox runs standard-library, NumPy and pandas indicators.
  • The bundled tradinglead Strategy SDK, native packages and hard process isolation require Desktop.
  • Neither allows unrestricted host Python, filesystem access or network access.

2. Write against the contract

The entry point is calculate(bars, params):

  • Bars are chronological OHLCV dictionaries. Time is in milliseconds, and volume can be None.
  • Plots must align one value per candle, using finite numbers or None.
  • Typed inputs are declared with # @input JSON comments. Supported types are int, float, bool, string, enum and color, with min/max/step/options.
# @input {"id":"enabled","type":"bool","default":true,"group":"Display"}
def calculate(bars, params):
    return {"title": "Close reference", "overlay": True,
            "plots": [{"id": "close", "title": "Close", "color": "#22c55e",
                       "values": [b["close"] if params.get("enabled", True) else None for b in bars]}]}

3. Validate, save, apply

  • Validate. pythonIndicators.validate is a syntax-only check in an isolated AST checker. It does not run imports or calculations. Saving the source is not validation.
  • Save and apply. pythonIndicators.save stores the source, and pythonIndicators.apply puts it on the chart.
  • Inputs. pythonIndicators.setSettings changes inputs later.
  • History. pythonIndicators.history and pythonIndicators.restore bring back an earlier revision.

See write a Python indicator.

Good habits to ask for

  • "Keep plot IDs stable so my colours survive updates."
  • "Show me the last 10 values next to the candles so I can check the calculation."
  • "Don't use future candles." Backtesting does not certify code that peeks at future information.

From indicator to strategy

When the indicator works, ask for a strategy version and a backtest. Follow backtest with an AI assistant. To scan many stocks with a Pine indicator on broker candles, see screen stocks with an AI assistant. The older walkthrough create a custom indicator with AI covers the in-app flow.

Example prompts

  • "Write a Pine v5 Supertrend-style indicator, validate it, fix any diagnostics, and apply it to my 15-minute chart."
  • "Port this TradingView script and list every unsupported line."
  • "Write a Python indicator that plots the distance of close from the 20-day high as a percentage in a separate pane."

More examples are in the AI prompt cookbook.

Steps

  1. Open the chart where you want the indicator in TradingLead Desktop
  2. Ask the assistant to read indicators.listCapabilities or pythonIndicators.capabilities
  3. Describe the indicator; the assistant writes source and validates it
  4. Fix any diagnostics, then optionally save it to your library
  5. Apply it to the chart with a retry key and confirm with indicators.applied or chart.snapshot
  6. Adjust inputs later with indicators.update or the Python settings commands

Limitations

  • Requires TradingLead Desktop with managed AI integration (Apple Silicon Mac 0.1.8+, current 0.1.18); the public Windows 0.1.7 build lacks it.
  • Pine v5/v6 support is a selective subset, not TradingView parity.
  • Pine strategy() is rejected on indicator and scanner surfaces; use backtesting.
  • Python in the browser sandbox is limited to standard library, NumPy and pandas; the TradingLead SDK and native packages require Desktop.
  • No unrestricted host Python, filesystem or network access for indicators.
  • Commands and transport have size budgets (2 MiB for Python requests).

Frequently asked questions

Can an AI assistant write a Pine Script indicator for TradingLead?
Yes. Through TradingLead Desktop, the tl-tlscript skill has the assistant check indicators.listCapabilities, validate the exact Pine v5/v6 source, then save and apply it. Support is selective, and unsupported constructs return explicit diagnostics.
Can I paste a TradingView Pine script and have the AI port it?
You can ask, and the assistant validates it against TradingLead's TLScript-Pine worker. Anything unsupported is reported in diagnostics. TradingView libraries, services and external data are not assumed to exist, and full parity is not claimed.
What does a Python indicator need to look like?
A calculate(bars, params) function that returns plots aligned to the input candles. Bars are chronological OHLCV dictionaries. Typed inputs are declared with # @input JSON comments.
Does validation prove the indicator is correct?
No. Pine validation is compile-only and Python validation is syntax-only. Neither certifies calculation correctness, so check the plotted values on the chart.
Can the AI turn the indicator into a strategy backtest?
Pine strategy() scripts run through backtesting.run with language pine, not indicators.apply. Python strategies also run through the tl-backtesting skill.

Last updated: