One indicator characteristic that we see most often is the indicator’s name. How do we specify that name programmatically in TradingView Pine?

In this article:

Setting the name of a TradingView indicator with code

In TradingView we specify a script’s characteristics, like its name and how it should be displayed on the chart, with the study() function (Pine Script Language Tutorial, n.d.). This is the only function that always needs to be included in an indicator’s code, and we always have to set this function’s title argument too (TradingView, n.d.).

That title argument specifies the name of the indicator (TradingView, n.d.), and that name is displayed in the chart panel’s legend, the ‘Data Window’, and in the ‘Create Alert’ window. A quick example of title is:

study(title="My example script")

Closely related to the title argument is shorttitle, an optional argument that also specifies the indicator’s name (TradingView, n.d.). Later on in this article we’ll at the similarities between title and shorttitle.

Note: Both the title and shorttitle arguments of the study() function only accept a literal string (like title="My string"). They cannot be set to a built-in or user-defined string variable nor do they accept a concatenated TradingView string.

The title and shorttitle arguments cannot be set manually and can only be defined in the script’s code – just like other features set by study() (such as the indicator’s decimal precision and its maximum number of referenced historical bars).

Example: setting the name of an indicator programmatically

To see how the title and shorttitle arguments work in practice, let’s consider a programming example. In the script below we recreate the RSI (Relative Strength Index) indicator. We’ll first look at the effect of the title argument, and later set the study() function’s shorttitle argument too.

study(title="My RSI")

// Inputs
rsiLen  = input(title="RSI Length", type=integer, defval=12)
obLevel = input(title="Overbought", type=integer, defval=70)
osLevel = input(title="Oversold", type=integer, defval=30)

// Plot
plot(series=rsi(close, rsiLen), color=blue)
hline(price=obLevel)
hline(price=osLevel)

We start with the study() function and set its title argument to “My RSI”. Then we add several input options to the indicator:

rsiLen  = input(title="RSI Length", type=integer, defval=12)
obLevel = input(title="Overbought", type=integer, defval=70)
osLevel = input(title="Oversold", type=integer, defval=30)

We add input options to a script with the input() function, and this function also returns the input’s value (Pine Script Language Tutorial, n.d.). The three inputs created here are all numerical integer inputs, and we make these by setting the type argument of the input() function to integer (Pine Script Language Tutorial, n.d.).

The first input has its title argument set to “RSI Length”, and this name is what’s placed before the option in the script’s ‘Inputs’ window (see image below). We give this input a default value (defval) of 12 and assign its current value to the rsiLen variable. That variable with the RSI length is used later on when computing the RSI.

The two other inputs are named “Overbought” and “Oversold” and have default values of 70 and 30. Their values are stored in the obLevel and osLevel variables and these are used later on when plotting the RSI’s overbought and oversold lines.

That plotting is done next:

plot(series=rsi(close, rsiLen), color=blue)
hline(price=obLevel)
hline(price=osLevel)

We start with plot() here, a function that displays the values of its series argument on the chart (TradingView, n.d.). That argument is set to rsi() here, a function that can calculate the RSI based on a series of values and an integer that specifies the RSI length (TradingView, n.d.). Here we use close and rsiLen as arguments, and that makes rsi() compute on the bar’s closing prices with a length of 12 bars by default. With the color argument of the plot() function we display those values in the blue basic TradingView colour.

We end the example with two hline() statements. That function creates a horizontal line at a fixed price level that’s set with the price argument (TradingView, n.d.). In the first hline() function call we set that argument to the obLevel input variable. That variable holds the value of the “Overbought” input that we gave a standard value of 70. The second hline() statement displays the value of the osLevel variable on the chart, which holds the “Oversold” input value that starts off with a value of 30.

After saving the script and adding it to the chart, we can configure the script with the following input options:

Input options of our TradingView script

Where does the value of the title argument appear in TradingView?

Now let’s see how the indicator looks like on the chart. As you recall, we set the title argument of the study() function to “My RSI”. We see this name first pop-up in the chart legend of the indicator’s chart panel:

Name of a TradingView indicator displayed on the chart

This title also shows in the chart’s ‘Data Window’:

Indicator name displayed in TradingView's Data Window

Alert messages also use the value that’s set by the title argument. We can see that when we right-click on the indicator’s line and select ‘Add Alert’ (or press Alt - A after selecting the plot):

Opening the 'Create Alert' window in TradingView

This brings up the ‘Create Alert’ window where “My RSI” appears in both the condition and default message:

Example of the 'Create Alert' window in TradingView

And so the text that we set to the title argument of the study() function is displayed in the TradingView environment as the script’s name.

Changing the filename of a TradingView indicator

One area where the value of the title argument is not necessarily used is with the indicator’s filename. While a script’s filename is by default set to the title argument’s value, we can change an indicator’s filename without changing the indicator’s name.

For instance, let’s rename the example script that we discussed above. For that we click on the ‘Rename script’ icon in the Pine Editor:

Renaming a TradingView Pine script

Then we can give our indicator any name we like, such as ‘My RSI - example script’:

Example script renamed in TradingView

But despite the different filename the indicator’s name on the chart (which is set by the title argument) is still “My RSI”. This distinction between the script’s filename and its chart name is important. That’s because, when searching for the script in the list of indicators, we need to look for its filename and not its name on the chart (the title argument).

For example, when we right-click on the chart and select ‘Insert Indicator…’:

Adding a TradingView indicator to the chart

This brings up the ‘Indicators’ window. Here we select the ‘My Scripts’ section on the left:

Selecting the 'My Scripts' in TradingView

Then we browse down in the list we see our ‘My RSI - example script’ name:

Example of the indicator name in the TradingView indicators list

Here we see that our indicator isn’t listed based on its title argument but instead use the script’s filename.

Tip: Set the filename of an indicator to a name that closely resembles the name that’s displayed on the chart (which we set with the title argument). That makes the script easier to find in the indicators list when you do remember its chart name but don’t recall its filename.

Specifying a shorthand title for a script in TradingView Pine

Another way to set the title of an indicator is with the shorttitle argument of the study() function. That argument also specifies the indicator’s name as would be seen on the chart (TradingView, n.d.). To see how the shorttitle argument affects the script, let’s add this argument to the first statement of the previous example:

study(title="My Relative Strength Index indicator", shorttitle="RSI")

After making this single change we save the script. The indicator now displays as follows:

Example of the indicator's name on the TradingView chart

Here we see that the script’s legend is now “RSI”; the value of its shorttitle argument. The same happens in the ‘Data Window’, where the shorttitle value is displayed instead of the title argument:

TradingView script renamed in the Data Window

And in the ‘Create Alert’ window the shorttitle argument is also used as the script’s name:

Example of the TradingView 'Create Alert' window

As we can see, the title and shorttitle arguments behave the same – the only practical difference between them is that title is a required argument whereas shorttitle is not.

The shorttitle argument of study() is likely still in TradingView Pine because of legacy reasons. In the past, title set the name that was displayed in the list of indicators while shorttitle would set the indicator name that was displayed on the chart (see Pine Script Language Tutorial, n.d.). And so nowadays we can do safely without using the shorttitle argument.

For more on the study() function and its arguments, see overlaying an indicator on a data series and programmatically defining an indicator’s price axis.

Summary

Every TradingView indicator needs to have the study() function included in its source code. This function has sets the indicator’s properties with several arguments, including title. That required argument specifies the script’s name with a literal string. That name is then displayed in the chart’s legend, the ‘Data Window’, and in the ‘Create Alert’ window. The study() function also has a shorttitle argument, but that one simply overrides the value that’s set with title.


References

Pine Script Language Tutorial (n.d.). Retrieved on February 24, 2016, from https://docs.google.com/document/d/1sCfC873xJEMV7MGzt1L70JTStTE9kcG2q-LDuWWkBeY/

TradingView (n.d.). Script Language Reference Manual. Retrieved on February 27, 2016, from https://www.tradingview.com/study-script-reference/