Scripts without a
//@version line run on the Custom Script language
described here. On the trade chart, a script with a //@version line, such as
one copied from TradingView, runs as Pine Script instead, with more features
and higher limits: see Pine Scripts. The trade
journal chart runs every script in the Custom Script language. To save,
version, backtest, or share a script, write it as Pine Script on the
Scripts Page; Custom Script language scripts live only
in your chart layout.
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. These limits apply to the Custom
Script language only; Pine scripts have their own, listed in
Pine Scripts.
Differences from Pine Script
The Custom Script language covers a small part of Pine Script. These parts of Pine Script aren’t supported in it, 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.
On the trade chart, add a //@version=6 line at the top of the script to run
it as Pine Script, which supports these features. See
Pine Scripts. The trade journal chart doesn’t run Pine
Script, so a script that uses them shows an error there.