Custom Scripts are rolling out gradually. If you don’t find them in the
Indicators dialog, they aren’t available on your account yet.
Add a script
- Open the chart and select Indicators.
- Search for MFP and choose MFP Custom Script or MFP Custom Script Overlay.
- Open the indicator’s settings from its row in the chart legend.
- On the Inputs tab, replace the text in the Script box with your script and select Ok.
Fix errors
If a script has a mistake, the indicator draws nothing and a notice appears at the bottom of the chart. The notice gives the line and column of the problem and, where it can, a suggestion:Write a script
A script is a list of statements, one per line. You can also separate statements with a semicolon. Text after// is a comment.
- Names.
fast = ema(close, 9)gives a value a name you can reuse on later lines. Each name can be set once, and a name can’t reuse a built-in value such ascloseorna. - One-line scripts. A script that is a single expression, such as
ema(close, 21), draws that expression as a line. - Long lines. A line continues onto the next one when the next line is
indented, when it starts with an operator such as
+or?, or when the line ends with an operator, a comma, or an open bracket. - History. Add
[n]to read a value fromncandles ago:close[1]is the previous close, andfast[5]isfastfive candles back. - Missing values.
nameans “no value”. Math withnagivesna, and a line isn’t drawn where its value isna. Early candles often have no value because a moving average needs a full window first.
Operators
&& and ! work like and and not, and a double vertical bar works like
or. true and false are the same as 1 and 0.
Draw lines
plot(value, title, color, linewidth, style) draws a line. Only the value
is required; the other arguments can be passed in order or by name.
hline(price, title, color, linestyle, linewidth) draws a horizontal level.
It is dashed unless you set linestyle.
A script can draw up to 8 lines between
plot and hline. In the
indicator’s Style tab they appear in order as Plot 1 to Plot 8;
titles are for your own reference and don’t rename those rows. The style and
width you set in the script apply whenever you add the indicator or edit the
script. Between edits you can still change them in the Style tab.
Colors
Colors come from your script, so the Style tab has no color pickers for Custom Scripts. A line with no color uses its slot’s default color.
The named colors are
color.aqua, color.black, color.blue,
color.fuchsia, color.gray, color.green, color.lime, color.maroon,
color.navy, color.olive, color.orange, color.purple, color.red,
color.silver, color.teal, color.white, and color.yellow.
A color can change from candle to candle:
transp= alongside a color are also supported.
Mark candles
plotshape(condition, title, style, location, color) draws a marker on every
candle where the condition is true. A script can have up to 4 markers.
With
location.absolute, the marker sits at the value you pass instead of at
the candle, for example plotshape(high, location=location.absolute). In
MFP Custom Script, which draws in its own pane, above-bar and below-bar
markers are placed at the top and bottom of that pane.
Shade the background and candles
bgcolor(color) shades the chart background behind candles. barcolor(color)
recolors the candles themselves. Pass na to leave a candle unchanged.
Add adjustable inputs
Inputs let you change a script’s numbers without editing the script.input call is
Input 1, the second is Input 2, and so on. Leave a field blank to use
the script’s default, or type a value to replace it. A value outside
minval or maxval, or of the wrong kind, shows an error that names the
input.
Inputs can also appear directly inside a helper. For example,
sma(input.source(close), input.int(20)) uses Input 1 for the source
and Input 2 for the length. Each input call uses one field, including
inside helpers such as vwma, cci, hma, and stoch.
Built-in values
Built-in functions
Lengths and occurrences must be whole numbers known before the script runs: a number, an input, or a name set to one of those (for examplelen = input.int(14) or slow = len * 2). You can write functions with or
without Pine’s ta. and math. prefixes, so ta.sma and sma are the same.
Notes on specific functions:
highest(len)andlowest(len)with only a length usehighandlow.change,mom, androccompare against one candle back when you leave out the length.stdevandvariancemeasure the whole window (population), matching Pine.valuewhen(cond, src, 0)is the value at the most recent candle where the condition was true;1is the one before that, up to9.min,max, andavgtake 2 to 10 values.
Limits
The last limit keeps a script from slowing down your chart. A script over
any limit shows an error instead of running.
Differences from Pine Script
Many simple Pine Script indicators paste in with little or no change, and headers such as//@version=5 and indicator(...) are accepted. These parts
of Pine Script aren’t supported, and each shows an error explaining so:
if,for,while, andswitchblocks. Usecondition ? a : b.var, reassigning with:=, and your own functions.- Lists, tuples such as
[a, b] = ..., and text other than titles. - Data from other markets or timeframes (
request.security). - Strategies, alerts,
fill,plotchar,plotarrow, and drawing objects such as labels, lines, boxes, and tables. offset=on plots, andinput.string,input.color, andinput.timeframe.
plotshape accepts text= and size=, but markers are drawn without text,
at the chart’s standard size. alertcondition is accepted and has no effect.