is barmerge.gaps_off.
lookahead
(barmerge_lookahead) Merge strategy for the requested data position. Possible values: barmerge.lookahead_on, barmerge.lookahead_off. Default value is barmerge.lookahead_off starting from version 3. Note that behavour is the same on real-time, and differs only on history.ignore_invalid_symbol
(const bool) An optional argument. Determines the behavior of the function if the specified symbol is not found: if false, the script will halt and return a runtime error; if true, the function will return na and execution will continue. The default value is false.currency
(simple string) Currency into which the symbol’s currency-related values (e.g. OHLC) are to be converted. The expression
is then calculated based on the converted values. The conversion rates used are based on the FX_IDC pairs’ daily rates of the previous day (relative to the bar where the calculation is done). Optional. The default is syminfo.currency. Possible values: a three-letter string with the currency code in the ISO 4217 format (e.g. “USD”) or one of the constants in the currency.* namespace, e.g. currency.USD.Remarks
PineScript code that uses this function could calculate differently on history and real-time data.
If you want to specify additional arguments for the requested symbol, e.g. session or adjustment type, you can use the ticker.new() function.
It is not possible to pass a spread to this function using the ‘ticker’ variable. You can use the ‘ticker.new’ variable or a string representation of the ticker, e.g. “AAPL+MSFT*TSLA”.
At the moment, up to 40 request.security calls can be present in a script.
Please note that using this variable/function can cause indicator repainting.
The resolution argument allowable values are:
1S, 5S, 15S, 30S - for seconds intervals (chart resolution should be less than or equal to the requested resolution)
from 1 to 1440 for minutes
from 1D to 365D for days
from 1W to 52W for weeks
from 1M to 12M for months
See also
syminfo.ticker
syminfo.tickerid
timeframe.period
ta.correlation
barmerge.lookahead_off
barmerge.lookahead_on
Returns true if the source
string contains the str
substring, false otherwise.
str.contains(source, str)
Example
// If the current chart is a continuous futures chart, e.g "BTC1!", then the function will return true, false otherwise.
var isFutures = str.contains(syminfo.tickerid, "!")
plot(isFutures ? 1 : 0)
Returns
True if the str
was found in the source
string, false otherwise.
Arguments
source
(series string) Source string.str
(series string) The substring to search for.See also
str.pos
str.match
Returns true if the source
string ends with the substring specified in str
, false otherwise.
str.endswith(source, str)
Returns
True if the source
string ends with the substring specified in str
, false otherwise.
Arguments
source
(series string) Source string.str
(series string) The substring to search for.See also
str.startswith
Returns true if the source
string starts with the substring specified in str
, false otherwise.
str.startswith(source, str)
Returns
True if the source
string starts with the substring specified in str
, false otherwise.
Arguments
source
(series string) Source string.str
(series string) The substring to search for.See also
str.endswith
Returns a new string that is a substring of the source
string. The substring begins with the character at the index specified by begin_pos
and extends to ‘end_pos - 1’ of the source
string.
str.substring(source, begin_pos)
str.substring(source, begin_pos, end_pos)
Example
sym= "EXCHANGE_NAME:SYMBOL_NAME"
pos = str.pos(sym, ":") // Get position of ":" character
tkr= str.substring(sym, pos+1) // "SYMBOL_NAME"
if barstate.islastconfirmedhistory
runtime.log(tkr)
Returns The substring extracted from the source string.
Arguments
source
(series string) Source string from which to extract the substring.begin_pos
(series int) The beginning position of the extracted substring. It is inclusive (the extracted substring includes the character at that position).end_pos
(series int) The ending position. It is exclusive (the extracted string does NOT include that position’s character). Optional. The default is the length of the source
string.Remarks
Strings indexing starts from 0. If begin_pos
is equal to end_pos
, the function returns an empty string.
See also
str.contains
str.pos
str.match
str.tonumber(string)
Returns A float version of the string if it contains a valid number, na otherwise.
Arguments
string
(series string) String representation of an int or float.Converts the formatting string and value(s) into a formatted string. The formatting string can contain literal text and one placeholder in curly braces {} for each value to be formatted. Each placeholder consists of the index of the required argument (beginning at 0) that will replace it, and an optional format specifier. The index represents the position of that argument in the str.format argument list.
str.format(formatString, arg0, arg1, ...)
Example
// The format specifier inside the curly braces accepts certain modifiers:
// - Specify the number of decimals to display:
s1 = str.format("{0,number,#.#}", 1.34) // returns: 1.3
runtime.log(s1)
// - Round a float value to an integer:
s2 = str.format("{0,number,integer}", 1.34) // returns: 1
runtime.log(s2)
// - Display a number in currency:
s3 = str.format("{0,number,currency}", 1.34) // returns: $1.34
runtime.log(s3)
// - Display a number as a percentage:
s4 = str.format("{0,number,percent}", 0.5) // returns: 50%
runtime.log(s4)
// EXAMPLES WITH SEVERAL ARGUMENTS
// returns: Number 1 is not equal to 4
s5 = str.format("Number {0} is not {1} to {2}", 1, "equal", 4)
runtime.log(s5)
// returns: 1.34 != 1.3
s6 = str.format("{0} != {0, number, #.#}", 1.34)
runtime.log(s6)
// returns: 1 is equal to 1, but 2 is equal to 2
s7 = str.format("{0, number, integer} is equal to 1, but {1, number, integer} is equal to 2", 1.34, 1.52)
runtime.log(s7)
// returns: The cash turnover amounted to $1,340,000.00
s8 = str.format("The cash turnover amounted to {0, number, currency}", 1340000)
runtime.log(s8)
// returns: Expected return is 10% - 20%
s9 = str.format("Expected return is {0, number, percent} - {1, number, percent}", 0.1, 0.2)
runtime.log(s9)
Returns The formatted string.
Arguments
formatString
(series string) Format string.arg0, arg1, ...
(series int/float/bool/string/na/int[]/float[]/bool[]/string[]) Values to format.Remarks Any curly braces within an unquoted pattern must be balanced. For example, “ab {0} de” and “ab ‘}’ de” are valid patterns, but “ab {0’}’ de”, “ab } de” and “’’{’’” are not.
Returns an integer corresponding to the amount of chars in that string.
str.length(string)
Returns The number of chars in source string.
Arguments
string
(series string) Source string.Returns a new string with all letters converted to lowercase.
str.lower(source)
Returns A new string with all letters converted to lowercase.
Arguments
source
(series string) String to be converted.See also
str.upper
Returns a new string with all letters converted to uppercase.
str.upper(source)
Returns A new string with all letters converted to uppercase.
Arguments
source
(series string) String to be converted.See also
str.lower
Returns the new substring of the source
string if it matches a regex
regular expression, ‘na’ otherwise.
str.match(source, regex)
Example
s = input.string("It's time to sell some EXCHANGE_NAME:SYMBOL_NAME!")
// finding first substring that matches regular expression "[\w]+:[\w]+"
var string tickerid = str.match(s, "[\\w]+:[\\w]+")
if barstate.islastconfirmedhistory
runtime.log(tickerid) // "EXCHANGE_NAME:SYMBOL_NAME"
Returns
The new substring of the source
string if it matches a regex
regular expression, ‘na’ otherwise.
Arguments
source
(series string) Source string.regex
(series string) The regular expression to which this string is to be matched.Remarks
Function returns first occurrence of the regular expression in the source
string.
The backslash “” symbol in the regex
string needs to be escaped with additional backslash, e.g. “\d” stands for regular expression “\d”.
See also
str.contains
str.substring
Returns the position of the first occurrence of the str
string in the source
string, ‘na’ otherwise.
str.pos(source, str)
Returns
Position of the str
string in the source
string.
Arguments
source
(series string) Source string.str
(series string) The substring to search for.Remarks Strings indexing starts at 0.
See also
str.contains
str.match
str.substring
Returns a new string with the N+1th occurrence of the target
string and the previous occurrence of target
string replaced by the replacement
string, where N is specified in occurrence
. N is the matching index of the target string to be replaced in the source string.
str.replace(source, target, replacement, occurrence)
Example
var source = "EXCHANGE1:SYMBOL1 / EXCHANGE1:SYMBOL2"
// Replace first occurrence of "EXCHANGE1" with "EXCHANGE2" replacement string
var newSource = str.replace(source, "EXCHANGE1", "EXCHANGE2", 0)
if barstate.islastconfirmedhistory
// Display "EXCHANGE1:SYMBOL1 / EXCHANGE1:SYMBOL2"
runtime.log(newSource)
Returns Processed string.
Arguments
source
(series string) Source string.target
(series string) String to be replaced.replacement
(series string) String to be inserted instead of the target string.occurrence
(series int) The matching index of the occurrence of the target string to be replaced in the source string Indexing starts at 0 for the first match. Optional. Default value is 0.See also
str.replace_all
str.match
Replaces each occurrence of the target string in the source string with the replacement string.
str.replace_all(source, target, replacement)
Returns Processed string.
Arguments
source
(series string) Source string.target
(series string) String to be replaced.replacement
(series string) String to be substituted for each occurrence of target string.Divides a string into an array of substrings and returns its array ID.
str.split(string, separator)
Returns The ID of an array of strings.
Arguments
string
(series string) Source string.separator
(series string) The string separating each substring.str.tostring(value)
str.tostring(value, format)
str.tostring(value[])
str.tostring(value[], format)
Returns
The string representation of the value
argument.
If the value
argument is a string, it is returned as is.
When the value
is na, the function returns the string “NaN”.
Arguments
value
(series int/float/bool/string/int[]/float[]/bool[]/string[]) Value or array ID whose elements are converted to a string.format
(series string) Format string. Accepts these format.* constants: format.mintick, format.percent, format.volume. Optional. The default value is ‘#.##########’.Remarks The formatting of float values will also round those values when necessary, e.g. str.tostring(3.99, ‘#’) will return “4”. To display trailing zeros, use ‘0’ instead of ‘#’. For example, ‘#.000’. When using format.mintick, the value will be rounded to the nearest number that can be divided by syminfo.mintick without the remainder. The string is returned with trailing zeroes. If the x argument is a string, the same string value will be returned. Bool type arguments return “true” or “false”. When x is na, the function returns “NaN”.
Function color applies the specified transparency to the given color.
color.new(color, transp)
Example
plot(close, color=color.new(color.red, 50))
Returns Color with specified transparency.
Arguments
color
(series color)transp
(series int/float) Possible values are from 0 (not transparent) to 100 (invisible).Remarks Using arguments that are not constants (e.g., ‘simple’, ‘input’ or ‘series’) will have an impact on the colors displayed in the script’s “Settings/Style” tab. See the User Manual for more information.
Creates a new color with transparency using the RGB color model.
color.rgb(red, green, blue, transp)
Example
plot(close, color=color.rgb(255, 0, 0, 50))
Returns Color with specified transparency.
Arguments
red
(series int/float) Red color component. Possible values are from 0 to 255.green
(series int/float) Green color component. Possible values are from 0 to 255.blue
(series int/float) Blue color component. Possible values are from 0 to 255.transp
(series int/float) Optional. Color transparency. Possible values are from 0 (opaque) to 100 (invisible). Default value is 0.Remarks Using arguments that are not constants (e.g., “simple”, “input” or “series”) will have an impact on the colors displayed in the script’s “Settings/Style” tab. See the User Manual for more information.
Print variable information to the console.
FMZ PINE language specific functions, runtime.debug(value)
, with only an argument.
Output content in the log.
FMZ PINE language specific functions, runtime.log(1, 2, 3, close, high, ...)
, you can pass multiple arguments.
When called, causes a runtime error with the error message specified in the message
argument.
runtime.error(message)
Arguments message (series string) Error message.
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function automatically detects the type of the argument used for “defval” and uses the corresponding input widget.
input(defval, title, tooltip, inline, group)
input(defval, title, inline, group, tooltip)
Example
i_switch = input(true, "On/Off") // Set true, the default is checked.
plot(i_switch ? open : na)
i_len = input(7, "Length")
i_src = input(close, "Source") // Drop-down box, select close by default.
plot(ta.sma(i_src, i_len))
i_col = input(color.red, "Plot Color")
plot(close, color=i_col)
i_text = input("Hello!", "Message")
runtime.log(i_text)
Returns Value of input variable.
Arguments
defval
(const int/float/bool/string/color or source-type built-ins) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where script users can change it. Source-type built-ins are built-in series float variables that specify the source of the calculation: close
, hlc3
, etc.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.Remarks Result of input function always should be assigned to a variable, see examples above.
See also
input.bool
input.color
input.int
input.float
input.string
input.timeframe
input.source
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a dropdown that allows the user to select a source for the calculation, e.g. close, hl2, etc. If the script includes only one input.source() call, the user can also select an output from another indicator on their chart as the source.
input.source(defval, title, tooltip, inline, group)
Example
i_src = input.source(close, "Source")
plot(i_src)
Returns Value of input variable.
Arguments
defval
(series int/float) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.Remarks Result of input.source function always should be assigned to a variable, see examples above.
See also
input.bool
input.int
input.float
input.string
input.timeframe
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a field for a string input to the script’s inputs.
input.string(defval, title, options, tooltip, inline, group, confirm)
Example
i_text = input.string("Hello!", "Message")
runtime.log(i_text)
Returns Value of input variable.
Arguments
defval
(const string) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it. When a list of values is used with the options
argument, the value must be one of them.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.options
(List of constants: [<type>…]) A list of options to choose from.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.string function always should be assigned to a variable, see examples above.
See also
input.bool
input.int
input.float
input.timeframe
input.source
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a checkmark to the script’s inputs.
input.bool(defval, title, tooltip, inline, group, confirm)
Example
i_switch = input.bool(true, "On/Off")
plot(i_switch ? open : na)
Returns Value of input variable.
Arguments
defval
(const bool) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.bool function always should be assigned to a variable, see examples above.
See also
input.int
input.float
input.string
input.timeframe
input.source
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a field for an integer input to the script’s inputs.
input.int(defval, title, minval, maxval, step, tooltip, inline, group, confirm)
input.int(defval, title, options, tooltip, inline, group, confirm)
Example
i_len1 = input.int(10, "Length 1", minval=5, maxval=21, step=1)
plot(ta.sma(close, i_len1))
i_len2 = input.int(10, "Length 2", options=[5, 10, 21])
plot(ta.sma(close, i_len2))
Returns Value of input variable.
Arguments
defval
(const int) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where script users can change it. When a list of values is used with the options
argument, the value must be one of them.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.minval
(const int) Minimal possible value of the input variable. Optional.maxval
(const int) Maximum possible value of the input variable. Optional.step
(const int) Step value used for incrementing/decrementing the input. Optional. The default is 1.options
(tuple of const int values: [val1, val2, …]) A list of options to choose from a dropdown menu, separated by commas and enclosed in square brackets: [val1, val2, …]. When using this argument, the minval
, maxval
and step
arguments cannot be used.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.int function always should be assigned to a variable, see examples above.
See also
input.bool
input.float
input.string
input.timeframe
input.source
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a field for a float input to the script’s inputs.
input.float(defval, title, minval, maxval, step, tooltip, inline, group, confirm)
input.float(defval, title, options, tooltip, inline, group, confirm)
Example
i_angle1 = input.float(0.5, "Sin Angle", minval=-3.14, maxval=3.14, step=0.02)
plot(math.sin(i_angle1) > 0 ? close : open, "sin", color=color.green)
i_angle2 = input.float(0, "Cos Angle", options=[-3.14, -1.57, 0, 1.57, 3.14])
plot(math.cos(i_angle2) > 0 ? close : open, "cos", color=color.red)
Returns Value of input variable.
Arguments
defval
(const int/float) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where script users can change it. When a list of values is used with the options
argument, the value must be one of them.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.minval
(const int/float) Minimal possible value of the input variable. Optional.maxval
(const int/float) Maximum possible value of the input variable. Optional.step
(const int/float) Step value used for incrementing/decrementing the input. Optional. The default is 1.options
(tuple of const int/float values: [val1, val2, …]) A list of options to choose from a dropdown menu, separated by commas and enclosed in square brackets: [val1, val2, …]. When using this argument, the minval
, maxval
and step
arguments cannot be used.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.float function always should be assigned to a variable, see examples above.
See also
input.bool
input.int
input.string
input.timeframe
input.source
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a color picker that allows the user to select a color and transparency, either from a palette or a hex value.
input.color(defval, title, tooltip, inline, group, confirm)
Example
i_col = input.color(color.red, "Plot Color")
plot(close, color=i_col)
Returns Value of input variable.
Arguments
defval
(const color) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.color function always should be assigned to a variable, see examples above.
See also
input.bool
input.int
input.float
input.string
input.timeframe
input.source
input
Adds a price input to the script’s “Settings/Inputs” tab. Using confirm = true
activates the interactive input mode where a price is selected by clicking on the chart.
input.price(defval, title, tooltip, inline, group, confirm)
Example
price1 = input.price(title="Date", defval=42)
plot(price1)
price2 = input.price(54, title="Date")
plot(price2)
Returns Value of input variable.
Arguments
defval
(const int/float) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, the interactive input mode is enabled and the selection is done by clicking on the chart when the indicator is added to the chart, or by selecting the indicator and moving the selection after that. Optional. The default is false.Remarks
When using interactive mode, a time input can be combined with a price input if both function calls use the same argument for their inline
argument.
See also
input.bool
input.int
input.float
input.string
input.resolution
input.source
input.color
input
Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a dropdown that allows the user to select a specific timeframe via the timeframe selector and returns it as a string. The selector includes the custom timeframes a user may have added using the chart’s Timeframe dropdown.
input.timeframe(defval, title, options, tooltip, inline, group, confirm)
Example
i_res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])
s = request.security("syminfo.tickerid", i_res, close)
plot(s)
Returns Value of input variable.
Arguments
defval
(const string) Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where the user can change it. When a list of values is used with the options
argument, the value must be one of them.title
(const string) Title of the input. If not specified, the variable name is used as the input’s title. If the title is specified, but it is empty, the name will be an empty string.options
(tuple of const string values: [val1, val2, …]) A list of options to choose from.tooltip
(const string) The string that will be shown to the user when hovering over the tooltip icon.inline
(const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.group
(const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.confirm
(const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.Remarks Result of input.timeframe function always should be assigned to a variable, see examples above.
See also
input.bool
input.int
input.float
input.string
input.source
input.color
input
Not available.
Not available.
Arnaud Legoux Moving Average. It uses Gaussian distribution as weights for moving average.
ta.alma(series, length, offset, sigma)
ta.alma(series, length, offset, sigma, floor)
Example
plot(ta.alma(close, 9, 0.85, 6))
// same on pine, but much less efficient
pine_alma(series, windowsize, offset, sigma) =>
m = offset * (windowsize - 1)
//m = math.floor(offset * (windowsize - 1)) // Used as m when math.floor=true
s = windowsize / sigma
norm = 0.0
sum = 0.0
for i = 0 to windowsize - 1
weight = math.exp(-1 * math.pow(i - m, 2) / (2 * math.pow(s, 2)))
norm := norm + weight
sum := sum + series[windowsize - i - 1] * weight
sum / norm
plot(pine_alma(close, 9, 0.85, 6))
Returns Arnaud Legoux Moving Average.
Arguments
series
(series int/float) Series of values to process.length
(series int) Number of bars (length).offset
(simple int/float) Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0).sigma
(simple int/float) Changes the smoothness of ALMA. The larger sigma the smoother ALMA.floor
(simple bool) An optional argument. Specifies whether the offset calculation is floored before ALMA is calculated. Default value is false.See also
ta.sma
ta.ema
ta.rma
ta.wma
ta.vwma
ta.swma
The sma function returns the moving average, that is the sum of last y values of x, divided by y.
ta.sma(source, length)
Example
plot(ta.sma(close, 15))
// same on pine, but much less efficient
pine_sma(x, y) =>
sum = 0.0
for i = 0 to y - 1
sum := sum + x[i] / y
sum
plot(pine_sma(close, 15))
Returns
Simple moving average of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.ema
ta.rma
ta.wma
ta.vwma
ta.swma
ta.alma
The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.
ta.cog(source, length)
Example
plot(ta.cog(close, 10))
// the same on pine
pine_cog(source, length) =>
sum = math.sum(source, length)
num = 0.0
for i = 0 to length - 1
price = source[i]
num := num + price * (i + 1)
-num / sum
plot(pine_cog(close, 10))
Returns Center of Gravity.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.stoch
Measure of difference between the series and it’s ta.sma
ta.dev(source, length)
Example
plot(ta.dev(close, 10))
// the same on pine
pine_dev(source, length) =>
mean = ta.sma(source, length)
sum = 0.0
for i = 0 to length - 1
val = source[i]
sum := sum + math.abs(val - mean)
dev = sum/length
plot(pine_dev(close, 10))
Returns
Deviation of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.variance
ta.stdev
ta.stdev(source, length, biased)
Example
plot(ta.stdev(close, 5))
//the same on pine
isZero(val, eps) => math.abs(val) <= eps
SUM(fst, snd) =>
EPS = 1e-10
res = fst + snd
if isZero(res, EPS)
res := 0
else
if not isZero(res, 1e-4)
res := res
else
15
pine_stdev(src, length) =>
avg = ta.sma(src, length)
sumOfSquareDeviations = 0.0
for i = 0 to length - 1
sum = SUM(src[i], -avg)
sumOfSquareDeviations := sumOfSquareDeviations + sum * sum
stdev = math.sqrt(sumOfSquareDeviations / length)
plot(pine_stdev(close, 5))
Returns Standard deviation.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).biased
(series bool) Determines which estimate should be used. Optional. The default is true.Remarks
If biased
is true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.
See also
ta.dev
ta.variance
The ema function returns the exponentially weighted moving average. In ema weighting factors decrease exponentially. It calculates by using a formula: EMA = alpha * source + (1 - alpha) * EMA[1], where alpha = 2 / (length + 1).
ta.ema(source, length)
Example
plot(ta.ema(close, 15))
//the same on pine
pine_ema(src, length) =>
alpha = 2 / (length + 1)
sum = 0.0
sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_ema(close,15))
Returns
Exponential moving average of source
with alpha = 2 / (length + 1).
Arguments
source
(series int/float) Series of values to process.length
(simple int) Number of bars (length).Remarks Please note that using this variable/function can cause indicator repainting.
See also
ta.sma
ta.rma
ta.wma
ta.vwma
ta.swma
ta.alma
The wma function returns weighted moving average of source
for length
bars back. In wma weighting factors decrease in arithmetical progression.
ta.wma(source, length)
Example
plot(ta.wma(close, 15))
// same on pine, but much less efficient
pine_wma(x, y) =>
norm = 0.0
sum = 0.0
for i = 0 to y - 1
weight = (y - i) * y
norm := norm + weight
sum := sum + x[i] * weight
sum / norm
plot(pine_wma(close, 15))
Returns
Weighted moving average of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.sma
ta.ema
ta.rma
ta.vwma
ta.swma
ta.alma
Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6].
ta.swma(source)
Example
plot(ta.swma(close))
// same on pine, but less efficient
pine_swma(x) =>
x[3] * 1 / 6 + x[2] * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6
plot(pine_swma(close))
Returns Symmetrically weighted moving average.
Arguments
source
(series int/float) Source series.See also
ta.sma
ta.ema
ta.rma
ta.wma
ta.vwma
ta.alma
The hma function returns the Hull Moving Average.
ta.hma(source, length)
Example
src = input(defval=close, title="Source")
length = input(defval=9, title="Length")
hmaBuildIn = ta.hma(src, length)
plot(hmaBuildIn, title="Hull MA", color=#674EA7)
Returns Hull moving average of ‘source’ for ‘length’ bars back.
Arguments
source
(series int/float) Series of values to process.length
(simple int) Number of bars.See also
ta.ema
ta.rma
ta.wma
ta.vwma
ta.sma
Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.
ta.rma(source, length)
Example
plot(ta.rma(close, 15))
//the same on pine
pine_rma(src, length) =>
alpha = 1/length
sum = 0.0
sum := na(sum[1]) ? ta.sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_rma(close, 15))
Returns
Exponential moving average of source
with alpha = 1 / length
.
Arguments
source
(series int/float) Series of values to process.length
(simple int) Number of bars (length).See also
ta.sma
ta.ema
ta.wma
ta.vwma
ta.swma
ta.alma
ta.rsi
Relative strength index. It is calculated using the ta.rma()
of upward and downward changes of source
over the last length
bars.
ta.rsi(source, length)
Example
plot(ta.rsi(close, 7))
// same on pine, but less efficient
pine_rsi(x, y) =>
u = math.max(x - x[1], 0) // upward ta.change
d = math.max(x[1] - x, 0) // downward ta.change
rs = ta.rma(u, y) / ta.rma(d, y)
res = 100 - 100 / (1 + rs)
res
plot(pine_rsi(close, 7))
Returns Relative strength index.(RSI)
Arguments
source
(series int/float) Series of values to process.length
(simple int) Number of bars (length).See also
ta.rma
True strength index. It uses moving averages of the underlying momentum of a financial instrument.
ta.tsi(source, short_length, long_length)
Returns True strength index. A value in range [-1, 1].
Arguments
source
(series int/float) Source series.short_length
(simple int) Short length.long_length
(simple int) Long length.Function roc (rate of change) showing the difference between current value of source
and the value of source
that was length
days ago.
It is calculated by the formula: 100 * change(src, length) / src[length].
ta.roc(source, length)
Returns
The rate of change of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Returns the difference between the min and max values in a series.
ta.range(source, length)
Returns The difference between the min and max values in the series.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).MACD (moving average convergence/divergence). It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock’s price.
ta.macd(source, fastlen, slowlen, siglen)
Example
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot(macdLine, color=color.blue)
plot(signalLine, color=color.orange)
plot(histLine, color=color.red, style=plot.style_histogram)
If you need only one value, use placeholders ‘_’ like this: Example
[_, signalLine, _] = ta.macd(close, 12, 26, 9)
plot(signalLine, color=color.orange)
Returns Tuple of three MACD series: MACD line, signal line and histogram line.
Arguments
source
(series int/float) Series of values to process.fastlen
(simple int) Fast Length argument.slowlen
(simple int) Slow Length argument.siglen
(simple int) Signal Length argument.See also
ta.sma
ta.ema
Returns the mode of the series. If there are several values with the same frequency, it returns the smallest value.
ta.mode(source, length)
Returns The mode of the series.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Returns the median of the series.
ta.median(source, length)
Returns The median of the series.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Linear regression curve. A line that best fits the prices specified over a user-defined time period. It is calculated using the least squares method. The result of this function is calculated using the formula: linreg = intercept + slope * (length - 1 - offset), where intercept and slope are the values calculated with the least squares method on source
series.
ta.linreg(source, length, offset)
Returns Linear regression curve.
Arguments
source
(series int/float) Source series.length
(series int)offset
(simple int) Offset.Bollinger Bands. A Bollinger Band is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of the security’s price, but can be adjusted to user preferences.
ta.bb(series, length, mult)
Example
[middle, upper, lower] = ta.bb(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
// the same on pine
f_bb(src, length, mult) =>
float basis = ta.sma(src, length)
float dev = mult * ta.stdev(src, length)
[basis, basis + dev, basis - dev]
[pineMiddle, pineUpper, pineLower] = f_bb(close, 5, 4)
plot(pineMiddle)
plot(pineUpper)
plot(pineLower)
Returns Bollinger Bands.
Arguments
series
(series int/float) Series of values to process.length
(series int) Number of bars (length).mult
(simple int/float) Standard deviation factor.See also
ta.sma
ta.stdev
ta.kc
Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the lower Bollinger Bands divided by the middle band.
ta.bbw(series, length, mult)
Example
plot(ta.bbw(close, 5, 4), color=color.yellow)
// the same on pine
f_bbw(src, length, mult) =>
float basis = ta.sma(src, length)
float dev = mult * ta.stdev(src, length)
((basis + dev) - (basis - dev)) / basis
plot(f_bbw(close, 5, 4))
Returns Bollinger Bands Width.
Arguments
series
(series int/float) Series of values to process.length
(series int) Number of bars (length).mult
(simple int/float) Standard deviation factor.See also
ta.bb
ta.sma
ta.stdev
The CCI (commodity channel index) is calculated as the difference between the typical price of a commodity and its simple moving average, divided by the mean absolute deviation of the typical price. The index is scaled by an inverse factor of 0.015 to provide more readable numbers.
ta.cci(source, length)
Returns Commodity channel index of source for length bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).The difference between the current value and the previous value, source - source [length].
ta.change(source, length)
ta.change(source)
Returns The result of subtraction.
Arguments
source
(series int/float) Source series.length
(series int) Offset from the current bar to the previous bar. Optional, if not given, length=1 is used.See also
ta.mom
ta.cross
Momentum of source
price and source
price length
bars ago. This is simply a difference: source - source[length].
ta.mom(source, length)
Returns
Momentum of source
price and source
price length
bars ago.
Arguments
source
(series int/float) Series of values to process.length
(series int) Offset from the current bar to the previous bar.See also
ta.change
Chande Momentum Oscillator. Calculates the difference between the sum of recent gains and the sum of recent losses and then divides the result by the sum of all price movement over the same period.
ta.cmo(series, length)
Example
plot(ta.cmo(close, 5), color=color.yellow)
// the same on pine
f_cmo(src, length) =>
float mom = ta.change(src)
float sm1 = math.sum((mom >= 0) ? mom : 0.0, length)
float sm2 = math.sum((mom >= 0) ? 0.0 : -mom, length)
100 * (sm1 - sm2) / (sm1 + sm2)
plot(f_cmo(close, 5))
Returns Chande Momentum Oscillator.
Arguments
series
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.rsi
ta.stoch
math.sum
Calculates percentile using method of linear interpolation between the two nearest ranks.
ta.percentile_linear_interpolation(source, length, percentage)
Returns
P-th percentile of source
series for length
bars back.
Arguments
source
(series int/float) Series of values to process (source).length
(series int) Number of bars back (length).percentage
(simple int/float) Percentage, a number from range 0…100.Remarks Note that a percentile calculated using this method will NOT always be a member of the input data set.
See also
ta.percentile_nearest_rank
Calculates percentile using method of Nearest Rank.
ta.percentile_nearest_rank(source, length, percentage)
Returns
P-th percentile of source
series for length
bars back.
Arguments
source
(series int/float) Series of values to process (source).length
(series int) Number of bars bac乞丐 为何策略广场复制的pine策略无法实盘
小小梦 好的,我们检查下。
乞丐 张超大佬的Optimized Trend Tracker
小小梦 您好,请问具体是哪个策略呢?