Skip to content

Script Editor

The Script Editor is where you write, save and manage your own indicators and strategies. A saved script appears in every chart's indicator list under My scripts; a script declared with strategy() also reports its backtest in the Strategy Tester.

Module
Script Editor
How to open
Add Widget ▸ Charting & Analysis ▸ Script Editor
Data source
Scripts are saved to your account
Saved in workspace
Yes
A script open in the editor.

The toolbar

ControlWhat it does
NewStart a new, untitled script.
RefreshReload your saved scripts from your account.
ExamplesLoad one of the built-in example scripts as a starting point.
OpenOpen a script from a file on your computer.
Compose with AIShow or hide the AI composer beside the editor.

Compose with AI

Compose with AI opens a conversation beside the editor. Describe the indicator or strategy you want in plain words, or ask for a change to the open script, and the script is typed into the editor as it is generated. Each reply is compiled on the spot: if the compiler objects, the composer asks the AI for a fix once by itself, and after that Ask AI to fix sends the problems back whenever you choose.

  • Try one starters cover price studies, order flow, open interest and strategies; More ideas rotates them.
  • Skip shows the whole script at once while it is still being typed; Stop (Esc) ends a reply and keeps what has arrived.
  • Revert on a reply puts the previous version of the script back.
  • An untitled script takes the title the AI gave it in study() or strategy().
  • Every reply carries the whole script, so what you save is never a fragment. Nothing reaches your account until you press Save.

The composer answers only what concerns scripts: writing one, changing the open one, and questions about the language, the data or the library. Anything else gets a one-line refusal, which still counts toward the day's allowance.

The composer is included in the Pro and Max plans (trials too) with a daily allowance per account, shown under the prompt box; it resets at midnight IST. Conversations are kept per script for the session. Each request sends the script in the editor and the earlier turns of that conversation, so the AI revises what you see; your charts, account and saved scripts are not sent.

My scripts

The list on the left holds your saved scripts, each with its saved status and version. Click one to open it.

Editing

ControlWhat it does
Script nameThe name shown in the chart's indicator list.
Format sourceTidy the indentation and spacing of the code.
Download sourceSave the script as a file.
SaveSave the script to your account (Ctrl/⌘ S).
Save copySave under a new name, leaving the original unchanged.
DeleteRemove the script.

Below the editor:

  • Inputs lists the inputs the script declares, with their defaults.
  • Problems shows what the compiler reports, or that the script compiles.
  • Data reference lists the order-flow, open-interest and footprint series a script can read (the data contract below).
  • Import Pine draft converts a Pine Script draft into the editor as a starting point; review the result before saving.
  • Open saved version returns to the last saved copy.

Data contract (v2)

Besides open, high, low, close, volume, oi and time, a script reads three FutPrint namespaces on the chart interval. Every value is a plain number per bar; a missing value is none. The Data Inspector shows the same rows and Capture ▸ CSV exports the same columns (flow.delta, oi.change, fp.poc, …), so the numbers agree everywhere. flow.version, oi.version and fp.version report the contract version, 2.

The feed is one Level-1 row per symbol per second with a side inferred by the backend from the price move, not an exchange aggressor flag; open interest is a level re-sent on traded rows. Everything below is built from that.

flow.* — order flow

SeriesMeaning
flow.available1 when the bar has a buy/sell split, else 0.
flow.buyVolume, flow.sellVolume, flow.delta, flow.deltaPercentBuy-side and sell-side volume from the inferred side of each one-second row, their difference, and delta as a % of classified volume.
flow.deltaHigh, flow.deltaLowHighest and lowest running delta inside the bar, for verified chronological data only.
flow.trades, flow.buyTrades, flow.sellTradesFeed-reported trade counts.
flow.cvdCumulative delta over the contiguous run of loaded bars; restarts after gaps.
flow.sessionCvdCumulative delta since the first bar of the calendar day in the chart's time zone, the CVD indicator's Session reset.

oi.* — open interest

SeriesMeaning
oi.available1 when the bar carries an OI level. None for an untraded contract, and never on an index or an equity.
oi.valueOI at the end of the bar, in contracts (the same level as the bare oi series).
oi.prevOI at the end of the previous chart bar, not the previous day.
oi.change, oi.changePctBar-over-bar change of the level and that change as a % of oi.prev, as Bar Statistics shows them.
oi.buildupPrice × OI quadrant against the previous bar: 2 long build-up, -2 short build-up, 1 short covering, -1 long unwinding, 0 when either change is zero, none when this bar or the previous one has no OI level. The sign follows price; 2 in size means OI rose.

fp.* — footprint structure

Built from the bar's traded price levels as the feed reports them (no display binning). Footprints are not served for index symbols or on the Free plan, so fp.* is none there; on a plain OHLCV chart only bars built from live rows carry levels.

SeriesMeaning
fp.available1 when the bar has a buy/sell split per price level.
fp.levelsNumber of traded price levels.
fp.poc, fp.pocVolumePrice level with the most volume (lowest on a tie) and its volume.
fp.vah, fp.valTop and bottom of the 70% value area grown outward from the POC, higher-volume side first.
fp.pocPosition100 × (poc − low) / (high − low): 0 at the low, 100 at the high.
fp.buyImbalances, fp.sellImbalances, fp.imbalancesDiagonal imbalance counts at the chart's footprint ratio (buy at a level against sell one level below; sell against buy one level above) and their difference. Zero volume never counts.
fp.imbalanceRatioThe ratio the counts were made with: the chart's Footprint ▸ Imbalance threshold at run time, pinned so the script can see it.
fp.cotHigh, fp.cotLowNet volume (buy − sell) traded after the bar's high and low were set.

These namespaces read the chart interval only; inside req.timeframe or req.symbol they are rejected. Scripts that read them run on the chart; server-side script alerts still evaluate price and volume series only. The OI build-up and Footprint structure examples show each namespace in use.

Using a script on a chart

  1. 1
    Save the script

    Scripts must be saved to your account before a chart can use them.

  2. 2
    Add it from the chart

    On a chart, open Indicators and choose it under My scripts.

  3. 3
    Set its inputs

    Each chart keeps its own input values, independent of the defaults in the editor.