> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myfundedperpetuals.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pine Scripts

> Run TradingView-style Pine Script indicators and strategies on the trade chart, with their limits, data sources, saved libraries, and the reasons values can differ from TradingView.

The trade chart can run scripts written in TradingView's Pine Script
language. The chart draws a script's lines, markers, fills, labels, tables,
and, for strategies, simulated trades. There are two ways to run one:

* **Save it on the Scripts page** and turn on **Show On /trade**. It runs on
  every trade chart, and you get the editor, versions, backtests, and
  sharing. See [Scripts Page](https://docs.myfundedperpetuals.com/guides/scripts-page.md).
* **Paste it into the chart** with one of the chart's Custom Script
  indicators. It runs on that chart only, saved with the chart layout.

Scripts run only in your browser, on the chart's own market data. A script can
read prices and draw on the chart. It can't place orders, change settings,
read your account, or send data anywhere, so a script someone shares with you
can't act on your behalf.

A script runs as Pine Script when its source contains a version line such as
`//@version=5` or `//@version=6`. A script without that line runs on the
simpler [Custom Script language](https://docs.myfundedperpetuals.com/guides/custom-scripts.md) instead, with that
language's own limits.

## Paste a Pine script into the chart

To run a script you saved on the Scripts page, turn it on there instead; see
[Show scripts on your trade charts](https://docs.myfundedperpetuals.com/guides/scripts-page.md#show-scripts-on-your-trade-charts).
To paste one into a single chart:

1. On the trade page, select **Indicators** in the chart header.
2. Search for **MFP** and choose:
   * **MFP Custom Script Overlay** for a script that draws on the candles
     (one declared with `overlay = true`, such as a moving average or bands).
   * **MFP Custom Script** for a script that draws in its own pane below the
     price chart (such as RSI or MACD).
3. Open the indicator's settings from its row in the chart legend.
4. On the **Inputs** tab, replace the text in the **Script** box with the
   whole script, including its `//@version` line, and select **Ok**.

The chart picks the pane from the indicator you added, not from the script's
`overlay` setting, so choose the one that matches the script. If they don't
match, a notice suggests the other indicator. A pane script
can still draw selected outputs on the price chart with `force_overlay = true`.

Your script is saved with your chart layout, so it comes back when you reload
the page. You can add the indicators more than once to run several scripts,
up to 4 Pine scripts on one chart. Scripts you turned on from the Scripts page
count toward the 4 and run first.

Pine scripts run on the trade chart, including the **Advanced Chart** widget
and each chart in a multiple-chart layout. The chart in the
[Trading Journal](https://docs.myfundedperpetuals.com/guides/trading-journal.md) runs only the Custom Script
language, so a Pine script there either runs as a Custom Script or shows an
error.

Pine Script versions 5 and 6 are supported. Version 4 scripts usually run but
can behave differently, so update them to `//@version=6` where you can.

## Change a script's inputs

The **Inputs** tab shows the script's own inputs under their titles (an input
without a title shows its variable name), with the
script's groups and tooltips. Each input gets the matching field:

| Input kind | Field |
| - | - |
| True or false (`input.bool`) | A checkbox. |
| Whole number or number (`input.int`, `input.float`) | A number box inside the input's minimum and maximum. |
| Color (`input.color`) | A color picker. |
| Source (`input.source`) or an input with listed options | A list to choose from. |
| Text, timeframe, symbol, or session | A text box. |

Up to 64 inputs can be changed. A script with more keeps the defaults for the
rest and shows a notice; to change one of those, edit its default value in
the script itself.

When you edit the script, inputs you changed keep your value if the input
still exists with the same kind and the value still fits. Inputs you didn't
change follow the script's new defaults.

## What a script can draw

| Output | Limit per script |
| - | - |
| Lines (`plot`, `hline`) | 32 |
| Markers (`plotshape`, `plotchar`) | 20 |
| Fills between two lines (`fill`) | 16 |
| Candles and bars (`plotcandle`, `plotbar`) | 4 |
| Arrows (`plotarrow`) | 4 |
| Background and candle colors (`bgcolor`, `barcolor`) | No separate limit |
| Lines, labels, boxes, and polylines | The newest 500 of each kind |
| Tables (`table.new`) | Shown in their corner of the script's pane |

A pane script's `force_overlay = true` outputs draw on the price chart, up to
8 lines, 4 markers, 4 fills, and 2 sets of candles.

Outputs past these limits aren't drawn. A notice lists what was hidden, for
example `plot × 3`. Line fills (`linefill.new`) aren't drawn, and a notice
counts them.

In the **Style** tab, a script's lines and markers appear under their titles
in the script. Outputs the script doesn't use, and outputs it marks
`editable = false`, are hidden. A `barcolor()` colors the whole candle,
including its border and wick. The colors and
styles in the script apply when you add the indicator or edit the script.

## How much history a script uses

A script runs over the latest 5,000 candles of the chart's timeframe, however
far you have scrolled, so its values don't change as you scroll. Older candles
load in the background, and results for candles the chart hasn't shown yet
appear as you scroll back. Candles older than that window show no values.

Some markets have less history than 5,000 candles on a timeframe, so a script
starts later on them. If older candles can't be loaded, a notice says the
script ran on the chart's loaded candles only.

Live candles update the script up to four times a second, and less often
while the chart is busy drawing heavy scripts.

## Other markets and timeframes

`request.security()` and `request.security_lower_tf()` load data for other
markets and timeframes from the same market data as the chart. A script can
request up to 8 different market and timeframe combinations, each up to the
newest 20,000 candles.

How a symbol in a script is read:

| Symbol in the script | Data it loads |
| - | - |
| The chart's own symbol, `syminfo.tickerid`, or `syminfo.ticker` | The chart's market and venue. |
| A venue the platform uses, such as `BINANCE:ETHUSDT`, `BYBIT:SOLUSDT`, or `HYPERLIQUID:ETH` | That market on that venue. |
| No exchange, such as `"ETHUSDT"` | The same coin on the chart's own venue. |
| Another crypto exchange, such as `COINBASE:BTCUSD`, `OKX:SOLUSDT`, `KUCOIN:` or `BITSTAMP:` | The same coin on the chart's own venue, with a notice such as "Using Binance data". |
| Any other exchange, such as stocks, futures, forex, or `ECONOMICS:` | No data: the script sees `na` and a notice names the request. |

A `.P` perpetual suffix and a quote currency such as `USDT`, `USDC`, or `USD`
are ignored when matching. If the venue doesn't offer the market or can't
build the timeframe, a notice lists the data that isn't available and the
script sees no value (`na`) for it. If a request needs more than 20,000
candles, a notice says only the newest were loaded.

Company and economic data (`request.financial`, `request.earnings`,
`request.dividends`, `request.splits`, `request.economic`, and
`request.quandl`) isn't available. These calls return `na`, so anything built
on them draws nothing, and a notice names them.

## Your own data in a script

`request.data("key")` returns a text value you stored under that key, such
as a day's options gamma exposure by strike, call and put walls, or any CSV,
JSON, or key-value text. The value is a `string`, so parse it with
`str.split()`, `str.tonumber()`, and the other string functions. The call
returns `na` when you have no value under that key.

```pine theme={null}
//@version=6
indicator("Call Wall", overlay = true)
// Stored as "call:5900,put:5800"
raw = request.data("spx-walls")
parts = str.split(raw, ",")
callWall = parts.size() > 0 ? str.tonumber(str.replace(parts.get(0), "call:", "")) : na
plot(callWall, "Call Wall", color.green)
```

Store values from **Script Data** on the [Scripts page](https://docs.myfundedperpetuals.com/guides/scripts-page.md#script-data)
or push them from a program with the
[Script Data API](https://docs.myfundedperpetuals.com/api-reference.md) (`PUT /v1/scripts/data/{key}`). When a
value changes, charts and editor previews running a script that reads it
recalculate within a few seconds, without reloading the chart.

* The key must be a constant string in the script: 1 to 64 letters, digits,
  dots, dashes, or underscores, starting with a letter or digit. A key from an
  input or another variable is an error.
* A script can read up to 20 keys.
* Values are yours alone. A script someone shares with you reads **your**
  values under its keys, never the author's, and the shared page lists the
  keys it reads.

## Strategies

A script declared with `strategy()` runs as a simulated backtest on the
chart's candles. On the trade chart, each simulated fill is marked on the
chart, up to the newest 300 fills.

The strategy's results are on the Scripts page, under the editor's preview
chart: **Strategy Results**, the **Trades** panel, and **Show Strategy
Report**, which opens **Net Profit**, **Closed Trades**, **Percent
Profitable**, **Profit Factor**, **Max Drawdown**, **Open Profit**, and a list
of the newest 500 closed trades. The totals count every trade. To test a
strategy on several markets or input values, see
[Backtest a strategy](https://docs.myfundedperpetuals.com/guides/scripts-page.md#backtest-a-strategy).

> [!WARNING]
>
> A strategy never places orders on your account. Its report is a simulation
> using the script's own settings, such as `initial_capital` and order size. It
> doesn't use your account balance and doesn't affect your challenge, rules, or
> statistics. Trades you want on your account must be placed yourself from the
> order ticket, or with the [Developer API](https://docs.myfundedperpetuals.com/trading-with-api.md).

## Alerts and logs

Scripts can't send alerts. `alert()` and `alertcondition()` are accepted so a
script runs, but they don't notify you. Log messages (`log.info`,
`log.warning`, and `log.error`) appear in the **Problems** panel of the
Scripts page editor, the newest 200 lines; the trade chart doesn't show them.

## Libraries

A script that imports a library (`import Author/Name/1`) needs that library
saved to your account first. Libraries published on TradingView aren't
available automatically, so you save a copy of the library's source yourself.

The easiest way is from the script that needs it:

1. Add the script that imports the library. It shows a notice naming every
   library it needs that you haven't saved, such as "This script imports
   Author/Name version 7, which you haven't saved."
2. Select **Manage Libraries** in that notice. The form names the first
   missing library and version and links to the author's scripts on
   TradingView. **Missing Libraries** lists the rest.
3. Open the library on TradingView, copy its full source code, paste it into
   the form, and save. The form moves on to the next missing library,
   including any library the one you pasted imports. Your script runs once
   every library is saved.

On the Scripts page, **Libraries** opens **Manage Libraries**, and importing a
library's source with **Import** offers **Save Library**. Your saved libraries
also appear in the editor's list of scripts; open one to edit it and save it
with **Save As New Version**. Scripts that import a library keep running the
version they name.

To open **Manage Libraries** from the chart, right-click a Pine script's name in
the chart legend or one of its lines. You can also open **Manage Libraries** and paste a library's source without a
script waiting for it, or add the library's source to the chart as its own
script and select **Save Library** in its notice ("Name is a library. Save
it so your other scripts can import it."). Remove that indicator
afterwards: a library draws nothing and counts toward the 4 Pine scripts on
the chart.

### Which saved version a script uses

An import names an author, a library name, and a version, and the name must
match exactly, including capitals:

```
import Author/Name/7 as lib
```

* A library saved from a script's import keeps that import's author and is
  never used for another author's library of the same name. A library you
  pasted without a script waiting for it can be used by any author's import.
* If you saved the exact version the import names, that version is used.
* Otherwise the script uses the first version of that library you saved, and
  the chart shows a notice naming the version it uses. Saving a newer version
  later doesn't change which version an unchanged script uses; save the exact
  version the import names, or delete the one in use, to change it.

Each save without a version number adds the next one (1, 2, 3, and so on).
Saving the same source again doesn't add a version. A version you already saved can't be replaced: delete it in **Manage
Libraries** first. **Manage Libraries** lists your saved libraries and
versions, and deletes the ones you no longer need. Deleting a version a
script on the chart uses asks you to confirm first. Scripts that use a library
update after you save or delete one.

| Library limit | Value |
| - | - |
| Saved library versions per account | 100 |
| Libraries one script can import, including libraries they import | 16 |
| Library name | Letters, digits, and underscores, up to 64 characters, not starting with a digit |
| Library length | 64,000 characters |

At 100 saved versions, delete one in **Manage Libraries** to save another.

## Your scripts and privacy

Scripts pasted into the chart are saved in your chart layout on your account.
Scripts saved on the Scripts page and your libraries are saved to your
account. Only your own scripts can import your libraries, and libraries are
never shared.

A saved script stays private unless you share it. A share link, a share code,
or a Public Library listing shows a frozen copy of one saved version's
source to other traders, credited to your public username. See
[Share a script](https://docs.myfundedperpetuals.com/guides/scripts-page.md#share-a-script) for exactly what a
share shows and how to stop it.

## Limits

| Limit | Value |
| - | - |
| Pine scripts on one chart | 4 |
| Script length | 64,000 characters |
| Candles a script runs on | 5,000 (fewer if the market has fewer) |
| Inputs you can change | 64 |
| Time to run a script over its candles | 20 seconds |
| Other market and timeframe requests per script | 8, up to 20,000 candles each |
| Strategy fill markers | Newest 300 |
| Strategy report trade list | Newest 500 closed trades |
| `request.data()` keys per script | 20 |

A script longer than 64,000 characters shows an error naming the limit. A
script exactly 64,000 characters long was probably cut off when it was
pasted, and shows an error saying so.

A script that takes longer than 20 seconds is stopped. Edit the script or its
inputs to run it again.

Limits for saved scripts, versions, sharing, and backtests are in
[Scripts Page](https://docs.myfundedperpetuals.com/guides/scripts-page.md#limits).

## Why values can differ from TradingView

Most published scripts draw the same values as on TradingView. They can differ
when:

* **The market data differs.** The chart uses its own venue's candles. A
  TradingView chart of another exchange, or of a spot market rather than the
  perpetual, has different prices and volume. Compare against the same
  venue's perpetual on TradingView, on the same timeframe.
* **The script depends on where history starts.** Scripts run over 5,000
  candles. TradingView plans that load more history start earlier, which
  changes values such as cumulative totals, anchored VWAP, and long moving
  averages, and changes strategy results.
* **Sessions differ.** Index and forex markets use their exchange trading day
  (see [Chart preferences and templates](https://docs.myfundedperpetuals.com/guides/trading-guide.md#chart-preferences-and-templates)),
  which can shift daily values against a TradingView chart of another
  exchange.
* **Another exchange maps to the chart's venue.** See
  [Other markets and timeframes](#other-markets-and-timeframes).
* **Drawing differs.** A gradient fill draws one color per candle instead of
  a smooth gradient. Outputs past the drawing limits are hidden.

If a script still differs on the same market and timeframe, use
[Report a Problem](https://docs.myfundedperpetuals.com/guides/scripts-page.md#report-a-problem) and choose
**Differs From TradingView**, or contact support with the script, the market
and venue, the timeframe, the TradingView symbol you compared against, and a
screenshot of both charts.

## Fix errors and notices

Errors stop a script from drawing; notices mean it draws, with something left
out. Both appear at the bottom of the chart and name the script they're
about. You can dismiss one with the close button; when there are several, the
chart shows the most important first, counts the rest, and offers **Dismiss
All** to clear the queue at once.

On trading charts, dismissing an informational notice is remembered in your
browser for that script and notice type, so it stays hidden when you reload,
adjust inputs, switch markets, or open extra panes (until you edit the script's
code or reset dismissals). Select **Mute Notices** on any notice card to hide
informational Pine notices on trading charts in this browser; script errors and
the Scripts editor preview always stay visible. You can turn trading chart
notices back on or reset dismissed notices under
[Notification settings](https://docs.myfundedperpetuals.com/settings/notifications.md#pine-script-notices).

| Message | What to do |
| - | - |
| **Pine Script Error** with `Line 12, column 5: ...` | The script has a mistake or uses something not supported at that line. Fix that line. |
| **Pine Script Error** with `Bar 1234: ...` | The script failed while running on that candle, for example an array index out of range. |
| `This script imports Author/Name version 7, which you haven't saved.` | Save the library. See [Libraries](#libraries). |
| `... so it runs your saved version 2.` | The script runs another saved version of the library. Save the exact version to run that one. |
| `Name is a library. Save it so your other scripts can import it.` | Select **Save Library**, then remove the indicator. |
| `Up to 4 Pine scripts run on one chart.` | Remove a Pine script from the chart. |
| `Up to 4 Pine scripts run on one chart, and scripts from your Scripts page run first.` | Turn a script off on the Scripts page, or remove a script you pasted into the chart. |
| `This script has more outputs than the chart made room for when it loaded.` | Reload the page or switch markets to draw them all. |
| `Edit this script on the Scripts page. Chart changes to its code aren't kept.` | The script was turned on from the Scripts page. Change its code in the editor there. |
| `This script ran longer than 20 seconds and was stopped.` | Simplify the script, or reduce lookback or loop sizes in its inputs. |
| `This chart draws up to 32 lines and 20 markers per script. Hidden: ...` | The script has more outputs than the chart draws. Remove outputs you don't need from the script. |
| `This chart can't draw some of this script's outputs. Hidden: ...` | Those outputs are past the chart's drawing limits. Remove outputs you don't need from the script. |
| `Only the newest drawings are shown.` | The script made more than 500 lines, labels, boxes, or polylines of one kind. |
| `Line fills aren't drawn on this chart.` | `linefill.new` fills are skipped; the rest of the script draws. |
| `Data the script requests isn't available: ...` | The venue doesn't offer that market or timeframe, or the script requests more than 8. |
| `Using Binance data for: ...` | The script named a crypto exchange the platform doesn't use; it gets the same coin from the chart's venue. |
| `Requests to exchanges that aren't available here return na: ...` | The script asks for stocks, futures, forex, or economic data. That part of the script draws nothing. |
| `Calls with no data here return na: ...` | Company or economic data calls such as `request.financial` have no data here. |
| `Only the newest 20,000 bars were loaded for: ...` | The request reaches further back than 20,000 candles. Earlier candles see no value. |
| `Older bars could not be loaded, ...` | The script ran on the candles already on the chart. Reload the page to try again. |
| `Input 3 (...) isn't a valid ... value` | Fix that input's value in the script's settings. |
| `Only the first 64 inputs can be changed in this script's settings.` | Edit the other inputs' defaults in the script. |
| `Running this script…` | The script is still running over the chart's candles. It draws when the run finishes. |
| `The Pine engine couldn't load.` | Reload the page. |

Pine Script is a trademark of TradingView, Inc. MyFundedPerps runs its own
engine for the language and isn't affiliated with TradingView.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.