FMZ PINE Script documentation is provided.

Author: The Little Dream, Created: 2022-05-06 14:27:06, Updated: 2024-02-23 15:36:48

GE_NAME:SYMBOL_NAME"


**返回值**
`source`字符串的新子字符串,如果它匹配一个`regex`正则表达式,否则为'na'。

**参数**
- ```source``` (series string) 来源字符串
- ```regex``` (series string) 与此字符串匹配的正则表达式。

**备注**
函数返回`source`字符串中第一次出现的正则表达式。
`regex`字符串中的反斜杠“\”符号需要使用额外的反斜杠进行转义,例如“\\d”代表正则表达式“\d”。

**另见**
```str.contains``` ```str.substring```

### str.pos

返回`source`字符串中第一次出现`str`字符串的位置,否则返回'na'。

str.pos(source, str)


**返回值**
`str`字符串在`source`字符串中的位置。

**参数**
- ```source``` (series string) 来源字符串
- ```str``` (series string) 要搜索的子字符串。

**备注**
字符串索引从0开始。

**另见**
```str.contains``` ```str.match``` ```str.substring```

### str.replace

返回一个新字符串,其中第N+1次出现的`target`字符串以及以前出现的`target`字符串替换为`replacement`字符串,其中N在`occurrence`中指定。N为要替换的目标字符串在来源字符串中出现的匹配索引。

str.replace(source, target, replacement, occurrence)


**例子**
```pine
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 "EXCHANGE2:SYMBOL1 / EXCHANGE1:SYMBOL2"
    runtime.log(newSource)

Returns the valueString has been processed

Parameters

  • source(series string) The source string
  • target(series string) replaced string
  • replacement(series string) The string to be inserted instead of the target string.
  • occurrence(series int) The matching index of the target string to be replaced appears in the source string. The first matching index starts at 0. Optional. Default is 0.

See you later str.replace_all str.match

str.replace_all

Replace the target string every time it appears in the source string.

str.replace_all(source, target, replacement)

Returns the valueString has been processed

Parameters

  • source(series string) The source string
  • target(series string) replaced string
  • replacement(series string) Each time the target string appears, it replaces the string

str.split

Splits the string into a substring array and returns its array ID.

str.split(string, separator)

Returns the valueThe ID of the string array

Parameters

  • string(series string) The source string
  • separator(series string) A string that separates each substring.

str.tostring

str.tostring(value)
str.tostring(value, format)
str.tostring(value[])
str.tostring(value[], format)

Returns the value valueString representation of the form of the parameter. What ifvalueIf the parameter is a string, it returns as it was. WhenvalueFor na, the function returns the string NaN.

Parameters

  • value(series int/float/bool/string/int[]/float[]/bool[]/string[]) whose elements are converted to the value of the string or the array ID.
  • format (series string) Format string. Accepts these format.* constants: format.mintick, format.percent, format.volume. Optional. The default value is ‘#.##########’.

NotesThe floating-point value format also quatrains these values when necessary, e.g. str.tostring ((3.99, #) will return 4. To display the zero, use 0 instead of #. For example, ##.000. When using format.mintick, this value is quaternized to the nearest number that can be divided by syminfo.mintick without remainders. The returned string has a zero after it. Returns the same string value if x is a string. The Bool type parameter returns either true or false. When x is na, the function returns NaN.

color

color.new

The function color specifies the transparency applied to the given color.

color.new(color, transp)

Examples

plot(close, color=color.new(color.red, 50))

Returns the valueThere is a certain transparency in the colours.

Parameters

  • color (series color)
  • transp(series int/float) Available values range from 0 (not transparent) to 100 (not visible)

NotesUsing a very large number of parameters (e.g. a simple button, input button, or series button) will affect the color displayed on the script button settings/stylesheet label page. See the user manual for more information.

color.rgb

Using the RGB color model to create new colors with transparency.

color.rgb(red, green, blue, transp)

Examples

plot(close, color=color.rgb(255, 0, 0, 50))

Returns the valueThere is a certain transparency in the colours.

Parameters

  • red(series int/float) Tone red. Possible values are from 0 to 255.
  • green(series int/float) Tone green. Possible values range from 0 to 255.
  • blue(series int/float) Blue tone. Possible values range from 0 to 255
  • transp(series int/float) Optional. Colour transparent. Possible values from 0 (not transparent) to 100 (transparent). Default value is 0.

NotesUsing a very large number of parameters (e.g. a simple button, input button, or series button) will affect the color displayed on the script button settings/stylesheet label page. See the user manual for more information.

runtime

runtime.debug

Print the variable information on the controller.

The FMZ PINE language has a special function.runtime.debug(value), there is only one parameter.

runtime.log

Export the contents in the log.

The FMZ PINE language has a special function.runtime.log(1, 2, 3, close, high, ...), can pass multiple parameters.

runtime.error

When called, it can cause runtime errors and can be associated withmessageError message specified in the parameter.

runtime.error(message)

Parametersmessage (series string) error message.

input

input

Add input to the input label page of the script setting, which allows you to provide configuration options to the script user. This function automatically detects the type of parameters used for the undefval tab and uses the corresponding input plugin.

input(defval, title, tooltip, inline, group)
input(defval, title, inline, group, tooltip)

Examples

i_switch = input(true, "On/Off")     // 设置true,默认勾选
plot(i_switch ? open : na)

i_len = input(7, "Length")
i_src = input(close, "Source")       // 下拉框,默认选择close
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 the valueEnter the value of the variable

Parameters

  • defval(const int/float/bool/string/color or source-type built-ins) Determines the default value of the input variable suggested in the script's float settings/input float label page, from which the script user can change it.closehlc3And so on and so forth.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.

NotesThe return value of the input function should always be assigned to the variable; see example above.

See you later input.bool input.color input.int input.float input.string input.timeframe input.source

input.source

Adding input to the input label page of the script settings, which allows you to provide configuration options to the script user. This feature adds a drop-down menu that allows the user to select a computation source, such as close, hl2, etc. If the script contains only one input.source call, the user can also select the output of another indicator on the chart as the source.

input.source(defval, title, tooltip, inline, group)

Examples

i_src = input.source(close, "Source")
plot(i_src)

Returns the valueEnter the value of the variable

Parameters

  • defval(series int/float) Determines the default value of the input variable suggested in the script's array settings/input array label page, from which the user can change it.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.

Notes input.source函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.int input.float input.string input.timeframe input.color input

input.string

Adding input to the input options tab of the script setting, which allows you to provide configuration options to the script user. This function adds a string input field to the input of the script.

input.string(defval, title, options, tooltip, inline, group, confirm)

Examples

i_text = input.string("Hello!", "Message")
runtime.log(i_text)

Returns the valueEnter the value of the variable

Parameters

  • defval(const string) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the user can change it.optionsWhen the arguments are used together, the value must be one of them.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • options(List of constants: [...]) List of options to choose from.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.string函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.int input.float input.timeframe input.source input.color input

input.bool

Adding input to the Input Tag page of the script settings, which allows you to provide configuration options to the script user. This function adds a check mark to the script input.

input.bool(defval, title, tooltip, inline, group, confirm)

Examples

i_switch = input.bool(true, "On/Off")
plot(i_switch ? open : na)

Returns the valueEnter the value of the variable

Parameters

  • defval(const bool) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the user can change it.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.bool函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.int input.float input.string input.timeframe input.source input.color input

input.int

Add input to the input label page of the script setting, which allows you to provide configuration options to the script user. This function adds an integer input field to the input of the script.

input.int(defval, title, minval, maxval, step, tooltip, inline, group, confirm) 
input.int(defval, title, options, tooltip, inline, group, confirm)

Examples

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 the valueEnter the value of the variable

Parameters

  • defval(const int) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the script user can change it.optionsWhen the arguments are used together, the value must be one of them.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • minval(const int) Minimum possible value of the input variable. Optional.
  • maxval(const int) The maximum possible value of the input variable. Optional.
  • step(const int) is used to increase/decrease the input step length. Optional. Default is 1
  • options(tuple of const int values: [val1, val2,...]) A list of options selected from the drop-down menu, separated by commas and encapsulated in square brackets: [val1, val2,...];; cannot be used when using this parameterminvalmaxvalandstepParameters are.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.int函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.float input.string input.timeframe input.source input.color input

input.float

Adding input to the input label page of the script setting, which allows you to provide configuration options to the script user. This function adds floating point input fields to the input of the script.

input.float(defval, title, minval, maxval, step, tooltip, inline, group, confirm)
input.float(defval, title, options, tooltip, inline, group, confirm)

Examples

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 the valueEnter the value of the variable

Parameters

  • defval(const int/float) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the script user can change it.optionsWhen the arguments are used together, the value must be one of them.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • minval(const int/float) Minimum possible value of the input variable. Optional.
  • maxval(const int/float) The maximum possible value of the input variable. Optional.
  • step(const int/float) is used to increase/decrease the input step length. Optional. Default is 1
  • options(tuple of const int/float values: [val1, val2,...]) A list of options selected from the drop-down menu, separated by commas and encapsulated in square brackets: [val1, val2,...];; cannot be used when using this parameterminvalmaxvalandstepParameters are.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.float函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.int input.string input.timeframe input.source input.color input

input.color

Input is added to the input label page of the script settings, which allows you to provide configuration options to the script user. This function adds a color selector, allowing the user to select colors and transparency from the color palette or the hexadecimal.

input.color(defval, title, tooltip, inline, group, confirm) 

Examples

i_col = input.color(color.red, "Plot Color")
plot(close, color=i_col)

Returns the valueEnter the value of the variable

Parameters

  • defval(const color) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the user can change it.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.color函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.int input.float input.string input.timeframe input.source input

input.price

Use the price input to add to the scripts of the tab setting/input tab tag page.confirm = trueActivate the interactive input mode and select the price by clicking on the chart.

input.price(defval, title, tooltip, inline, group, confirm) 

Examples

price1 = input.price(title="Date", defval=42)
plot(price1)

price2 = input.price(54, title="Date")
plot(price2)

Returns the valueEnter the value of the variable

Parameters

  • defval(const int/float) Determines the default value of the input variable suggested in the script's const settings/input const label page, from which the user can change it.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, enable interactive input mode and complete the selection by clicking on the chart when the indicator is added to the chart, or complete the selection by selecting the indicator and then moving the selection. Optional. Default is false.

NotesWhen using the interaction mode, if two functions are called against each otherinlineThe same parameters can be used to combine the time input with the price input.

See you later input.bool input.int input.float input.string input.resolution input.source input.color input

input.timeframe

Adding input to the input label page of the script settings, which allows you to provide configuration options to the script user. This function adds a drop-down list that allows the user to select a specific time period via the time period selector and return it as a string. The selector includes custom time periods that the user may add to the drop-down menu using the time period of the chart.

input.timeframe(defval, title, options, tooltip, inline, group, confirm)

Examples

i_res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])
s = request.security(syminfo.tickerid, i_res, close)
plot(s)

Returns the valueEnter the value of the variable

Parameters

  • defval(const string) Determines the default value of the input variable suggested in the script's const setting/input const label page, from which the user can change it.optionsWhen the arguments are used together, the value must be one of them.
  • title(const string) Input title. If not specified, the variable name is used as the input title. If the title is specified, but the title is empty, the name is an empty string.
  • options(tuple of const string values: [val1, val2,...]) List of options that can be selected.
  • tooltip(const string) This string will be displayed to the user when the mouse hangs over the tooltip icon.
  • inline(const string) Combines all input calls using the same parameter in one line. It does not display the string used as the parameter. It is only used to identify inputs belonging to the same line.
  • group(const string) Create a header above all inputs using the same set parameter string. The string is also used as the text of the header.
  • confirm(const bool) If true, the user is asked to confirm the input value before adding the indicator to the chart. The default is false.

Notes input.timeframe函数的结果总是应该分配给一个变量,见上面的例子。

See you later input.bool input.int input.float input.string input.source input.color input

input.integer

Not yet

input.resolution

Not yet

ta

ta.alma

Arnaud Legoux Moving Average. It uses the Gaussian distribution as a weight for the moving average.

ta.alma(series, length, offset, sigma) 
ta.alma(series, length, offset, sigma, floor) 

Examples

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 the valueArnaud Legoux moving average

Parameters

  • series(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).
  • offset(simple int/float) Controls the trade-off between smoothness (approximately 1) and responsiveness (approximately 0).
  • sigma(simple int/float) changes the smoothness of ALMA. The larger the Sigma, the smoother the ALMA.
  • floor(simple bool) Optional parameter. Specify whether the deflection is calculated as a lower bound before calculating ALMA. Default is false.

See you later ta.sma ta.ema ta.rma ta.wma ta.vwma ta.swma

ta.sma

The sma function returns the moving average, the last y value of x, divided by y.

ta.sma(source, length) 

Examples

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 the value lengthThe K line returnssourceThe simple moving average of the mean of the mean of the mean of the mean of the mean of the mean of the mean of the mean of the mean of the mean.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.ema ta.rma ta.wma ta.vwma ta.swma ta.alma

ta.cog

The cog is an indicator based on statistics and the Fibonacci Golden Ratio.

ta.cog(source, length) 

Examples

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 the valueFocus

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.stoch

ta.dev

衡量系列与其ta.sma之间的差异

ta.dev(source, length) 

Examples

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 the value lengthThe K line returnssourceI'm not going to say anything.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.variance ta.stdev

ta.stdev

ta.stdev(source, length, biased) 

Examples

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 the valueStandard deviation

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).
  • biased(series bool) Determines which estimate should be used. Optional. Default is true.

NotesWhat ifbiasedIf true, the function will calculate using biased estimates of the total, if false - biased estimates of the sample.

See you later ta.dev ta.variance

ta.ema

The ema function returns an index-weighted moving average. In ema, the weighting factor is exponentially decreasing. It is calculated using the following formula: EMA = alpha * source + (1 - alpha) * EMA,[1] where alpha = 2 / (length + 1) ;

ta.ema(source, length) 

Examples

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 the value sourceThe index of the moving average, alpha = 2 / (length + 1) ー

Parameters

  • source(series int/float) The series value to be executed.
  • length(simple int) K number of lines (length).

NotesPlease note that using this variable/function may result in a redrawing of the indicator.

See you later ta.sma ta.rma ta.wma ta.vwma ta.swma ta.alma

ta.wma

The wma function returnslengthK-linesourceIn wma, the weighting factor is decreased by the arithmetic mean.

ta.wma(source, length) 

Examples

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 the value lengthThe K line returnssourceThe weighted moving average.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.sma ta.ema ta.rma ta.vwma ta.swma ta.alma

ta.swma

A symmetrical weighted moving average with a fixed length:4. Weight: [1/6,2 / 6,2 / 6,1 / 6].

ta.swma(source)

Examples

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 the valueSymmetrical weighted moving averages.

Parameters

  • source(series int/float) Source series.

See you later ta.sma ta.ema ta.rma ta.wma ta.vwma ta.alma

ta.hma

The hma function returns the moving average HMA of the hull.

ta.hma(source, length)

Examples

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 the valueReturns the Hull Moving Average of the Hull length of the Hull column.

Parameters

  • source(series int/float) The series value to be executed.
  • length(simple int) K number of lines

See you later ta.ema ta.rma ta.wma ta.vwma ta.sma

ta.rma

The moving average used in the RSI. It is an index-weighted moving average, with alpha plus weight = 1/length.

ta.rma(source, length)

Examples

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 the value sourceThe index of the moving average, alpha = 1 /length

Parameters

  • source(series int/float) The series value to be executed.
  • length(simple int) K number of lines (length).

See you later ta.sma ta.ema ta.wma ta.vwma ta.swma ta.alma ta.rsi

ta.rsi

Relative intensity index. It is used in the lastlengthK-linesourceThe upward and downward changesta.rma()I'm not going to lie.

ta.rsi(source, length)

Examples

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 the valueRelative strength and weakness (RSI)

Parameters

  • source(series int/float) The series value to be executed.
  • length(simple int) K number of lines (length).

See you later ta.rma

ta.tsi

The true strength and weakness index. It uses the moving average of the potential movements of financial instruments.

ta.tsi(source, short_length, long_length)

Returns the valueTrue strength and weakness index. Values in the range [-1,1].

Parameters

  • source(series int/float) Source series.
  • short_length(simple int) Short length.
  • long_length(simple int) The length of the long string.

ta.roc

The function roc ((rate of change)) showssourceThe current value ofsourceA few days agolengthThe difference between the values. It is calculated by the following formula: 100 * change (src, length) / src (length).

ta.roc(source, length)

Returns the value lengthThe K line returnssourceThe rate of change in the number of people in the country is very high.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.range

Returns the difference between the minimum and maximum values in the sequence.

ta.range(source, length)

Returns the valueThe difference between the minimum and maximum values in the sequence.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.macd

The MACD (smooth asymmetric averages) is supposed to reveal the strength, direction, momentum and duration of changes in stock price trends.

ta.macd(source, fastlen, slowlen, siglen) 

Examples

[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 only need one value, use a placeholder symbol like this:

Examples

[_, signalLine, _] = ta.macd(close, 12, 26, 9)
plot(signalLine, color=color.orange)

Returns the valueThe three components of the MACD series are: MACD line, signal line, and rectangular line.

Parameters

  • source(series int/float) The series value to be executed.
  • fastlen(simple int) The shortcut parameter
  • slowlen(simple int) Slow length parameter.
  • siglen(simple int) Signal length parameter

See you later ta.sma ta.ema

ta.mode

Returns the pattern of the sequence. Returns the minimum value if there are multiple values of the same frequency.

ta.mode(source, length)

Returns the valueThe pattern of the sequence.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.median

Returns the median of the sequence.

ta.median(source, length) 

Returns the valueThe median of the sequence.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.linreg

A linear regression curve ─ a line that most closely matches the specified price within a user-defined time interval ─ is calculated using the least binary multiplication ─ the result of this function is calculated using the following formula: linreg = intercept + slope * (length - 1 - offset), where intercept and slope are used.sourceThe value of the smallest binary multiplication of the series.

ta.linreg(source, length, offset) 

Returns the valueLinear regression curve

Parameters

  • source(series int/float) Source series.
  • length (series int)
  • offset(simple int) shift

ta.bb

Brainstorming is a technical analysis tool defined by a set of lines that are spaced along two standard deviations (positive and negative) from the simple moving average (SMA) of a security's price, but can be adjusted according to user preference.

ta.bb(series, length, mult) 

Examples

[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 the valueI'm not sure what to do.

Parameters

  • series(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).
  • mult(simple int/float) standard deviation

See you later ta.sma ta.stdev ta.kc

ta.bbw

The width of the Brin band. The width of the Brin band is the distance from the upstream and downstream tracks to the midline.

ta.bbw(series, length, mult) 

Examples

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 the valueThe bandwidth of Brin.

Parameters

  • series(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).
  • mult(simple int/float) standard deviation

See you later ta.bb ta.sma ta.stdev

ta.cci

The CCI (Commodity Path Index) is calculated by dividing the difference between the typical price of a commodity and its simple moving average by the average absolute deviation of the typical price. The index is scaled by a factor of 0.015 to provide more readable figures.

ta.cci(source, length) 

Returns the valueThe commodity channel index of the source returned by the length K line.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.change

The difference between the current value and the previous value, source - source[length]。

ta.change(source, length) 
ta.change(source) 

Returns the valueThe result of the law's reduction.

Parameters

  • source(series int/float) Source series.
  • length(series int) Shifts from the current k-string to the previous k-string. Optional, if not given, use length = 1♦

See you later ta.mom ta.cross

ta.mom

sourcePrices andsourceThe pricelengthThis is just a difference: source - source[length]].

ta.mom(source, length) 

Returns the value sourcePrices andsourceThe pricelengthThe momentum before the K line.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) Shifts from the current k-line to the previous k-line.

See you later ta.change

ta.cmo

Chandler momentum oscillator. Calculate the sum of the number of recent rally points and the number of recent fall points, subtract the two and then divide the result by the sum of all price changes over the same period.

ta.cmo(series, length) 

Examples

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 the valueThe dynamic oscillation indicator in Chad

Parameters

  • series(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.rsi ta.stoch math.sum

ta.percentile_linear_interpolation

Calculate the percentage between the two most recent rankings using the linear insertion method.

ta.percentile_linear_interpolation(source, length, percentage) 

Returns the value lengthThe K line returnssourceThe first P percent of the series.

Parameters

  • source(series int/float) to be executed.
  • length(series int) Number of lines past K (length)
  • percentage(simple int/float) Percentage, a number in the range 0 to 100

NotesPlease note that not all of the input data set members are percentages calculated using this method.

See you later ta.percentile_nearest_rank

ta.percentile_nearest_rank

Percentages are calculated according to the most recent ranking method.

ta.percentile_nearest_rank(source, length, percentage) 

Returns the value lengthThe K line returnssourceThe first P percent of the series.

Parameters

  • source(series int/float) to be executed.
  • length(series int) Number of lines past K (length)
  • percentage(simple int/float) Percentage, a number in the range 0 to 100

NotesUsing a recent ranking method with less than 100 k lines of length in the past can result in the same number being used for multiple percentages. The most recent ranking percentage is an input data set member. The 100th percentile is defined as the maximum value in the input dataset.

See you later ta.percentile_linear_interpolation

ta.percentrank

The percentage rank is the percentage of the previous value less than or equal to the current value of the given series.

ta.percentrank(source, length) 

Returns the value lengthThe K line returnssourcePercentage of rankings.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

ta.variance

A differential is a set of expected values (ta.sma) of square deviation from its mean, which informally measures the distance of a set of numbers from its mean.

ta.variance(source, length, biased) 

Returns the value lengthThe K line returnssourceThe difference between the two.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).
  • biased(series bool) Determines which estimate should be used. Optional. Default is true.

NotesWhat ifbiasedIf true, the function will calculate using biased estimates of the total, if false - biased estimates of the sample.

See you later ta.dev ta.stdev

ta.tr

ta.tr(handle_na) 

Returns the valueThe real range. It is math.max ((high - low, math.abs ((high - close[1]), math.abs ((low - close[1]))).

Parameters

  • handle_na(simple bool) How to handle NaN values. If true, and the closing price of the previous day is NaN, then tr is calculated as the high-low of the day. Otherwise (if false) tr in this case returns NaN.ta.tr(true)。

Notes ta.tr(false)andta.trIt's exactly the same.

See you later ta.atr

ta.mfi

A cash flow indicator is a technical indicator that uses price and volume to determine whether an asset is overbought or oversold.

ta.mfi(series, length) 

Examples

plot(ta.mfi(hlc3, 14), color=color.yellow)

// the same on pine
pine_mfi(src, length) =>
    float upper = math.sum(volume * (ta.change(src) <= 0.0 ? 0.0 : src), length)
    float lower = math.sum(volume * (ta.change(src) >= 0.0 ? 0.0 : src), length)
    mfi = 100.0 - (100.0 / (1.0 + upper / lower))
    mfi

plot(pine_mfi(hlc3, 14))

Returns the valueIndicators of cash flow

Parameters

  • series(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.rsi math.sum

ta.kc

Cantonal channel. Cantonal channel is a technical indicator that contains a moving average in the middle as well as a channel up and down the track.

ta.kc(series, length, mult) 
ta.kc(series, length, mult, useTrueRange) 

Examples

[middle, upper, lower] = ta.kc(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)


// the same on pine
f_kc(src, length, mult, useTrueRange) =>
    float basis = ta.ema(src, length)
    float span = (useTrueRange) ? ta.tr : (high - low)
    float rangeEma = ta.ema(span, length)
    [basis, basis + rangeEma * mult, basis - rangeEma * mult]
    
[pineMiddle, pineUpper, pineLower] = f_kc(close, 5, 4, true)

plot(pineMiddle)
plot(pineUpper)
plot(pineLower)

Returns the valueThe Kenta Pass

Parameters

  • series(series int/float) The series value to be executed.
  • length(simple int) K number of lines (length).
  • mult(simple int/float) standard deviation
  • useTrueRange(simple bool) Optional parameter. Specifies whether to use a true range; default to true. If the value is false, the range is calculated using the expression ((high-low)).

See you later ta.ema ta.atr ta.bb

ta.kcw

Kenta channel width. Kenta channel width is the value of the difference between the upper and lower channels divided by the middle channel.

ta.kcw(series, length, mult) 
ta.kcw(series, length, mult, useTrueRange) 

Examples

plot(ta.kcw(close, 5, 4), color=color.yellow)

// the same on pine
f_kcw(src, length, mult, useTrueRange) =>
    float basis = ta.ema(src, length)
    float span = (useTrueRange) ? ta.tr : (high - low)
    float rangeEma = ta.ema(span, length)
    
    ((basis + rangeEma * mult) - (basis - rangeEma * mult)) / basis

plot(f_kcw(close, 5, 4, true))

Returns the valueThe width of the channel.

Parameters

  • series(series int/float) The series value to be executed.
  • length(simple int) K number of lines (length).
  • mult(simple int/float) standard deviation
  • useTrueRange(simple bool) Optional parameter. Specifies whether to use a true range; default to true. If the value is false, the range is calculated using the expression ((high-low)).

See you later ta.kc ta.ema ta.atr ta.bb

ta.correlation

相关系数。描述两个系列倾向于偏离其ta.sma值的程度。

ta.correlation(source1, source2, length) 

Returns the valueRelated coefficients.

Parameters

  • source1(series int/float) Source series.
  • source2(series int/float) The target series.
  • length(series int) length ((K number of lines)

See you later request.security

ta.cross

ta.cross(source1, source2) 

Returns the valueIf two series cross each other, they are true, otherwise they are false.

Parameters

  • source1(series int/float) The first data series.
  • source2(series int/float) The second data series.

See you later ta.change

ta.crossover

source1-series is defined as the spansource2-series, if on the current line K,source1is greater thansource2So the first line is the value of K, and the first line is the value of K.source2The value of source 1小于The value of source2 ≠.

ta.crossover(source1, source2) 

Returns the valueWhat ifsource1Go throughsource2If you want to change the name of the file, you can change the name of the file to true or false.

Parameters

  • source1(series int/float) The first data series.
  • source2(series int/float) The second data series.

ta.crossunder

source1-series is defined assource2-series below the intersection, if on the current line K,source1is less thansource2So the first line is the value of K, and the first line is the value of K.source1is greater thansource2The value of.

ta.crossunder(source1, source2) 

Returns the valueWhat ifsource1In thesource2The lower cross is true, the lower is false.

Parameters

  • source1(series int/float) The first data series.
  • source2(series int/float) The second data series.

ta.atr

The function ATR (true amplitude mean) returns a real range RMA. The real amplitude is max (high - low, abs (high - close[1]), abs (low - close[1])).

ta.atr(length) 

Examples

plot(ta.atr(14))

//the same on pine
pine_atr(length) =>
    trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
    //true range can be also calculated with ta.tr(true)
    ta.rma(trueRange, length)

plot(pine_atr(14))

Returns the valueThe mean of the true oscillation magnitude (ATR)

Parameterslength (simple int) length ((K number of lines)

See you later ta.tr ta.rma

ta.sar

Paradoxical reversal (also known as paradoxical stopping and reversal) is a method devised by J. Welles Wilder, Jr. to find potential reversals in the direction of a trading market price.

ta.sar(start, inc, max) 

Examples

plot(ta.sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)

// The same on Pine
pine_sar(start, inc, max) =>
  var float result = na
  var float maxMin = na
  var float acceleration = na
  var bool isBelow = na
  bool isFirstTrendBar = false
  
  if bar_index == 1
    if close > close[1]
      isBelow := true
      maxMin := high
      result := low[1]
    else
      isBelow := false
      maxMin := low
      result := high[1]
    isFirstTrendBar := true
    acceleration := start
  
  result := result + acceleration * (maxMin - result)
  
  if isBelow
    if result > low
      isFirstTrendBar := true
      isBelow := false
      result := math.max(high, maxMin)
      maxMin := low
      acceleration := start
  else
    if result < high
      isFirstTrendBar := true
      isBelow := true
      result := math.min(low, maxMin)
      maxMin := high
      acceleration := start
      
  if not isFirstTrendBar
    if isBelow
      if high > maxMin
        maxMin := high
        acceleration := math.min(acceleration + inc, max)
    else
      if low < maxMin
        maxMin := low
        acceleration := math.min(acceleration + inc, max)
  
  if isBelow
    result := math.min(result, low[1])
    if bar_index > 1
      result := math.min(result, low[2])
    
  else
    result := math.max(result, high[1])
    if bar_index > 1
      result := math.max(result, high[2])
  
  result
  
plot(pine_sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)

Returns the valueThe parallelized line turns towards the indicator.

Parameters

  • start(simple int/float) started.
  • inc(simple int/float) increases
  • max(simple int/float) is the largest.

ta.barssince

Calculate the number of k-strings from the last condition true.

ta.barssince(condition) 

Examples

// get number of bars since last color.green bar
plot(ta.barssince(close >= open))

Returns the valueIf the condition is true then the number of k strings is true.

NotesIf the condition is never satisfied before the current line K, the function returns na. Please note that using this variable/function may result in a redrawing of the indicator.

See you later ta.lowestbars ta.highestbars ta.valuewhen ta.highest ta.lowest

ta.cum

sourceThe sum of the sum of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums of the sums.sourceThe sum of all the elements of the equation.

ta.cum(source) 

Returns the valueSum of series.

Parameters

  • source (series int/float)

See you later math.sum

ta.dmi

The dmi function returns the dynamic index DMI.

ta.dmi(diLength, adxSmoothing) 

Examples

len = input.int(17, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(len, lensig)
plot(adx, color=color.red, title="ADX")
plot(diplus, color=color.blue, title="+DI")
plot(diminus, color=color.orange, title="-DI")

Returns the valueThe three components of the DMI series are: positive directional motion (+DI), negative directional motion (−DI) and average directional motion (ADX).

Parameters

  • diLength (simple int) DI Period。
  • adxSmoothing(simple int) ADX smooth cycle

See you later ta.rsi ta.tsi ta.mfi

ta.falling

TestingsourceThe serieslengthIs the K-long line going down?

ta.falling(source, length) 

Returns the valueIf the currentsourceValue less thanlengthAny previous k-line returnedsourceThe value is true or false.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.rising

ta.rising

TestingsourceThe serieslengthIs the K-long line going up?

ta.rising(source, length) 

Returns the valueIf the currentsourceThe value is greater thanlengthAny previous k-line returnedsourceThe value is true or false.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

See you later ta.falling

ta.pivothigh

This function returns the price at the pivot height. If no pivot height is available, it returns NaN.

ta.pivothigh(source, leftbars, rightbars) 
ta.pivothigh(leftbars, rightbars) 

Examples

leftBars = input(2)
rightBars=input(2)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_cross, linewidth=3, color= color.red, offset=-rightBars)

Returns the valueThe price at this point is either NaN.

Parameters

  • source(series int/float) Optional parameter↑ data sequence computed value↑ default value string High string↑
  • leftbars(series int/float)
  • rightbars(series int/float) Right length.

NotesIf the parameter is leftbars or rightbars, you should use the max_bars_back function as the source bar.

ta.pivotlow

This function returns the price at the pivot lows. If there is no pivot lows, it returns NaN.

ta.pivotlow(source, leftbars, rightbars) 
ta.pivotlow(leftbars, rightbars) 

Examples

leftBars = input(2)
rightBars=input(2)
pl = ta.pivotlow(close, leftBars, rightBars)
plot(pl, style=plot.style_cross, linewidth=3, color= color.blue, offset=-rightBars)

Returns the valueThe price at this point is either NaN.

Parameters

  • source(series int/float) Optional parameter. The data series calculation value.
  • leftbars(series int/float)
  • rightbars(series int/float) Right length.

NotesIf the parameter is leftbars or rightbars, you should use the max_bars_back function as the source bar.

ta.highest

The highest value of a given number of past k lines.

ta.highest(source, length) 
ta.highest(length) 

Returns the valueThe highest value in the series.

Parameters

  • source(series int/float) The series value to be executed.
  • length(series int) K number of lines (length).

NotesTwo versions of args:sourceIt's a series.lengthis the number of returned k lines. A version of arg:lengthis the number of k lines returned. The algorithm uses high as thesourceThe series.

See you later ta.lowest ta.lowestbars ta.highestbars ta.valuewhen ta.barssince

ta.highestbars

The maximum value deviation of a given number of past k lines.

ta.highestbars(source, length) 
ta.highestbars(length) 

Returns the valueShift to the highest k-line.

Parameters

  • source (series

More

wuhuoyanHow do you do it if you want to have multiple transactions running simultaneously?

Light cloudsPlease tell me, can pine do more transactions? Can it also go through transactions like JS? Thank you.

lisa20231Thank you for providing detailed documentation.

artistryWow! How does this pine script use the okex simulation on the platform?

artistryThis is equivalent to copying the tradingview platform's strategy directly to the inventor platform and using it!

The Little DreamThe PINE language can only do single-variety strategies, multi-variety strategies are best written in python, javascript, c++.

The Little DreamOh, yes, OKX is special, their analog environment and the real disk environment have the same address, only the difference is made elsewhere.

Light cloudsI can't use the okx analogue disc.

The Little DreamThis multi-variety architecture problem cannot be solved, because each exchange has a different interface, and the frequency limitation of the interface is not the same, which causes many problems.

The Little DreamWell, thank you for the suggestion, please report this request here.

Light cloudsIt feels better to be able to mix with JS and JS can be better adapted to different trading methods.

The trend hunterIn the future, will we consider more varieties?

The Little DreamI'm not being polite.

Light cloudsGood, thank you very much.

The Little DreamHello, the PINE language policy is currently only for single varieties.

The Little DreamThank you for your support. The documentation will continue to be improved.

The Little DreamYes, I did.

The Little DreamPINE template library, where parameters can be set to switch exchange base addresses.