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)
返回值 已处理字符串
参数
source
(series string) 来源字符串target
(series string) 被替换字符串replacement
(series string) 要插入的字符串而不是目标字符串。occurrence
(series int) 要替换的目标字符串在来源字符串中出现的匹配索引。第一个匹配的索引从0开始。可选。默认值为0。另见
str.replace_all
str.match
用替换字符串,替换源字符串中每次出现的目标字符串。
str.replace_all(source, target, replacement)
返回值 已处理字符串
参数
source
(series string) 来源字符串target
(series string) 被替换字符串replacement
(series string) 每次出现的目标字串都将替换的字串将字符串划分为子字符串阵列,并返回其阵列ID。
str.split(string, separator)
返回值 字符串阵列的ID。
参数
string
(series string) 来源字符串separator
(series string) 分隔每个子字符串的字符串。str.tostring(value)
str.tostring(value, format)
str.tostring(value[])
str.tostring(value[], format)
返回值
value
参数的字符串表示形式。
如果value
参数是字符串,则按原样返回。
当value
为na时,函数返回字符串“NaN”。
参数
value
(series int/float/bool/string/int[]/float[]/bool[]/string[]) 其元素转换为字符串的值或数组ID。format
(series string) Format string. Accepts these format.* constants: format.mintick, format.percent, format.volume. Optional. The default value is ‘#.##########’.备注 浮点值的格式也会在必要时四舍五入这些值,例如str.tostring(3.99, ‘#’) 将返回“4”。 要显示尾随零,请使用’0’而不是’#’。例如,’#.000’。 使用format.mintick时,该值将四舍五入到可以除以syminfo.mintick而没有余数的最接近的数字。返回的字符串带有尾随零。 如果x参数是字符串,则将返回相同的字符串值。 Bool类型参数返回“true”或“false”。 当x为na时,函数返回“NaN”。
功能颜色将指定透明度应用于给定的颜色。
color.new(color, transp)
例子
plot(close, color=color.new(color.red, 50))
返回值 有特定透明度的颜色。
参数
color
(series color)transp
(series int/float) 可用的值是从0(不透明)到100(不可见)备注 使用非常数的参数(例如,“simple”、“input”或“series”)将对脚本“设置/样式”标签页中显示的颜色产生影响。请参阅用户手册了解更多信息。
使用RGB颜色模型创建带有透明度的新颜色。
color.rgb(red, green, blue, transp)
例子
plot(close, color=color.rgb(255, 0, 0, 50))
返回值 有特定透明度的颜色。
参数
red
(series int/float) 红色调。可能的值是从0到255。green
(series int/float) 绿色调。可能的值是从0到255。blue
(series int/float) 蓝色调。可能的值是从0到255。transp
(series int/float) 可选。颜色透明。可能的值从0(不透明)到100(透明)。默认值为0。备注 使用非常数的参数(例如,“simple”、“input”或“series”)将对脚本“设置/样式”标签页中显示的颜色产生影响。请参阅用户手册了解更多信息。
在控制台打印变量信息。
FMZ PINE语言特有函数,runtime.debug(value)
,只有一个参数。
在日志输出内容。
FMZ PINE语言特有函数,runtime.log(1, 2, 3, close, high, ...)
,可以传多个参数。
调用时,会导致运行时错误,并带有在message
参数中指定的错误消息。
runtime.error(message)
参数 message (series string) 错误消息。
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数自动检测用于“defval”的参数类型并使用相应的输入插件。
input(defval, title, tooltip, inline, group)
input(defval, title, inline, group, tooltip)
例子
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)
返回值 输入变量值
参数
defval
(const int/float/bool/string/color or source-type built-ins) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,脚本用户可以从中更改它。源类型内置函数是指定计算源的内置系列浮点变量:close
、hlc3
等。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。备注 input函数的返回值应始终分配给变量。见上面的例子
另见
input.bool
input.color
input.int
input.float
input.string
input.timeframe
input.source
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此功能添加了一个下拉菜单,允许用户选择计算源,例如close、hl2等。如果脚本只包含一个input.source()调用,用户还可以选择图表上另一个指标的输出作为源。
input.source(defval, title, tooltip, inline, group)
例子
i_src = input.source(close, "Source")
plot(i_src)
返回值 输入变量值
参数
defval
(series int/float) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。备注 input.source函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.int
input.float
input.string
input.timeframe
input.color
input
将input添加到脚本设置的输入选项卡,它允许您向脚本用户提供配置选项。此函数将字符串输入字段添加到脚本的输入中。
input.string(defval, title, options, tooltip, inline, group, confirm)
例子
i_text = input.string("Hello!", "Message")
runtime.log(i_text)
返回值 输入变量值
参数
defval
(const string) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。当值列表与options
参数一起使用时,该值必须是其中之一。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。options
(List of constants: [<type>…]) 可供选择的选项列表。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.string函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.int
input.float
input.timeframe
input.source
input.color
input
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数为脚本的输入添加复选标记。
input.bool(defval, title, tooltip, inline, group, confirm)
例子
i_switch = input.bool(true, "On/Off")
plot(i_switch ? open : na)
返回值 输入变量值
参数
defval
(const bool) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.bool函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.int
input.float
input.string
input.timeframe
input.source
input.color
input
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数将整数输入字段添加到脚本的输入中。
input.int(defval, title, minval, maxval, step, tooltip, inline, group, confirm)
input.int(defval, title, options, tooltip, inline, group, confirm)
例子
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))
返回值 输入变量值
参数
defval
(const int) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,脚本用户可以从中更改它。当值列表与 options
参数一起使用时,该值必须是其中之一。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。minval
(const int) 输入变量的最小可能值。可选。maxval
(const int) 输入变量的最大可能值。可选。step
(const int) 用于增加/减少输入的步长值。可选。默认值为1。options
(tuple of const int values: [val1, val2, …]) 从下拉菜单中选择的选项列表,以逗号分隔并用方括号括起来:[val1, val2, …]。使用该参数时,不能使用minval
、maxval
和step
参数。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.int函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.float
input.string
input.timeframe
input.source
input.color
input
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数将浮点输入字段添加到脚本的输入中。
input.float(defval, title, minval, maxval, step, tooltip, inline, group, confirm)
input.float(defval, title, options, tooltip, inline, group, confirm)
例子
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)
返回值 输入变量值
参数
defval
(const int/float) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,脚本用户可以从中更改它。当值列表与 options
参数一起使用时,该值必须是其中之一。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。minval
(const int/float) 输入变量的最小可能值。可选。maxval
(const int/float) 输入变量的最大可能值。可选。step
(const int/float) 用于增加/减少输入的步长值。可选。默认值为1。options
(tuple of const int/float values: [val1, val2, …]) 从下拉菜单中选择的选项列表,以逗号分隔并用方括号括起来:[val1, val2, …]。使用该参数时,不能使用minval
、maxval
和step
参数。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.float函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.int
input.string
input.timeframe
input.source
input.color
input
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数添加了一个颜色选择器,允许用户从调色板或十六进制值中选择颜色和透明度。
input.color(defval, title, tooltip, inline, group, confirm)
例子
i_col = input.color(color.red, "Plot Color")
plot(close, color=i_col)
返回值 输入变量值
参数
defval
(const color) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.color函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.int
input.float
input.string
input.timeframe
input.source
input
将价格输入添加到脚本的“设置/输入”标签页。使用 confirm = true
激活交互式输入模式,通过点击图表选择价格。
input.price(defval, title, tooltip, inline, group, confirm)
例子
price1 = input.price(title="Date", defval=42)
plot(price1)
price2 = input.price(54, title="Date")
plot(price2)
返回值 输入变量值
参数
defval
(const int/float) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则启用交互式输入模式,并通过在将指标添加到图表时点击图表来完成选择,或者通过选择指标并在此之后移动选择来完成选择。可选。默认值为false。备注
使用交互模式时,如果两个函数调用对其 inline
参数使用相同的参数,则可以将时间输入与价格输入结合使用。
另见
input.bool
input.int
input.float
input.string
input.resolution
input.source
input.color
input
将input添加到脚本设置的输入标签页,它允许您向脚本用户提供配置选项。此函数添加一个下拉列表,允许用户通过时间周期选择器选择特定时间周期并将其作为字符串返回。选择器包括用户可能使用图表的时间周期下拉菜单添加的自定义时间周期。
input.timeframe(defval, title, options, tooltip, inline, group, confirm)
例子
i_res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])
s = request.security(syminfo.tickerid, i_res, close)
plot(s)
返回值 输入变量值
参数
defval
(const string) 确定脚本的“设置/输入”标签页中建议的输入变量的默认值,用户可以从中更改它。当值列表与options
参数一起使用时,该值必须是其中之一。title
(const string) 输入的标题。如果未指定,则将变量名用作输入的标题。如果指定了标题,但标题为空,则名称将为空字符串。options
(tuple of const string values: [val1, val2, …]) 可供选择的选项列表。tooltip
(const string) 此字符串将在鼠标悬停在工具提示图标上时显示给用户。inline
(const string) 在一行中使用相同的参数合并所有输入调用。不显示用作参数的字符串。它仅用于辨识属于同一行的输入。group
(const string) 使用相同的组参数字符串在所有输入上方创建标头。该字符串也用作标头的文本。confirm
(const bool) 如果为true,则在将指标添加到图表之前,将要求用户确认输入值。默认值为false。备注 input.timeframe函数的结果总是应该分配给一个变量,见上面的例子。
另见
input.bool
input.int
input.float
input.string
input.source
input.color
input
暂无
暂无
Arnaud Legoux移动平均线。 它使用高斯分布作为移动平均值的权重。
ta.alma(series, length, offset, sigma)
ta.alma(series, length, offset, sigma, floor)
例子
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))
返回值 Arnaud Legoux移动平均线
参数
series
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).offset
(simple int/float) 控制平滑度(更接近1)和响应性(更接近0)之间的权衡。sigma
(simple int/float) 改变ALMA的平滑度。Sigma越大,ALMA越平滑。floor
(simple bool) 可选参数。在计算ALMA之前,指定偏移量计算是否为下限。默认值为false。另见
ta.sma
ta.ema
ta.rma
ta.wma
ta.vwma
ta.swma
sma函数返回移动平均值,即x的最后y值,除以y。
ta.sma(source, length)
例子
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))
返回值
length
K线返回的source
的简单移动平均线。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.ema
ta.rma
ta.wma
ta.vwma
ta.swma
ta.alma
cog(重心点)是基于统计学和斐波那契黄金比例的指标。
ta.cog(source, length)
例子
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))
返回值 重心
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.stoch
衡量系列与其ta.sma之间的差异
ta.dev(source, length)
例子
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))
返回值
length
K线返回的source
偏差。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.variance
ta.stdev
ta.stdev(source, length, biased)
例子
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))
返回值 标准差
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).biased
(series bool) 确定应该使用哪个估计。可选。默认值为true。备注
如果biased
为true,函数将使用对整个总体的有偏估计进行计算,如果为false - 对样本的无偏估计。
另见
ta.dev
ta.variance
ema 函数返回指数加权移动平均线。在 ema 中,加权因子呈指数下降。它使用以下公式计算:EMA = alpha * source + (1 - alpha) * EMA[1],其中 alpha = 2 / (length + 1)。
ta.ema(source, length)
例子
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))
返回值
source
的指数移动平均线,alpha = 2 / (长度 + 1)。
参数
source
(series int/float) 待执行的系列值。length
(simple int) K线数量(长度).备注 请注意,使用此变量/函数可能会导致指标重新绘制。
另见
ta.sma
ta.rma
ta.wma
ta.vwma
ta.swma
ta.alma
wma 函数返回 length
K线的 source
的加权移动平均值。在 wma 中,加权因子以算术级数递减。
ta.wma(source, length)
例子
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))
返回值
length
K线返回的source
加权移动平均线。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.sma
ta.ema
ta.rma
ta.vwma
ta.swma
ta.alma
具有固定长度的对称加权移动平均线:4.权重:[1/6,2 / 6,2 / 6,1 / 6]。
ta.swma(source)
例子
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))
返回值 对称加权移动平均线。
参数
source
(series int/float) 源系列。另见
ta.sma
ta.ema
ta.rma
ta.wma
ta.vwma
ta.alma
hma函数返回船体移动平均线HMA。
ta.hma(source, length)
例子
src = input(defval=close, title="Source")
length = input(defval=9, title="Length")
hmaBuildIn = ta.hma(src, length)
plot(hmaBuildIn, title="Hull MA", color=#674EA7)
返回值 返回 ‘length’ 柱的 ‘source’ 的船体移动平均线Hull Moving Average。
参数
source
(series int/float) 待执行的系列值。length
(simple int) K线数量另见
ta.ema
ta.rma
ta.wma
ta.vwma
ta.sma
RSI中使用的移动平均线。 它是指数加权移动平均线,alpha加权值 = 1 /长度。
ta.rma(source, length)
例子
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))
返回值
source
的指数移动平均线,alpha = 1 / length
。
参数
source
(series int/float) 待执行的系列值。length
(simple int) K线数量(长度).另见
ta.sma
ta.ema
ta.wma
ta.vwma
ta.swma
ta.alma
ta.rsi
相对强度指数。它是使用在最后一个 length
K线上source
的向上和向下变化的ta.rma()
计算的。
ta.rsi(source, length)
例子
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))
返回值 相对强弱指标(RSI)
参数
source
(series int/float) 待执行的系列值。length
(simple int) K线数量(长度).另见
ta.rma
真实强弱指数。它使用金融工具潜在动量的移动平均线。
ta.tsi(source, short_length, long_length)
返回值 真实强弱指数。范围[-1,1]中的值。
参数
source
(series int/float) 源系列。short_length
(simple int) 短的长度。long_length
(simple int) 长线长度。函数 roc(变化率)显示 source
的当前值与 source
几天前的 length
值之间的差异。
由以下公式计算:100 * change(src, length) / src[length]。
ta.roc(source, length)
返回值
length
K线返回的source
的变化率。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).返回序列中最小值和最大值之间的差。
ta.range(source, length)
返回值 序列中最小值和最大值之间的差。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).MACD(平滑异同平均线)。 它应该揭示股票价格趋势的实力、方向、动量和持续时间的变化。
ta.macd(source, fastlen, slowlen, siglen)
例子
[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)
如果您只需要一个值,请使用像这样的占位符’_’:
例子
[_, signalLine, _] = ta.macd(close, 12, 26, 9)
plot(signalLine, color=color.orange)
返回值 三个MACD系列的元组:MACD线、信号线和直方图线。
参数
source
(series int/float) 待执行的系列值。fastlen
(simple int) 快线参数slowlen
(simple int) 慢长度参数。siglen
(simple int) 信号长度参数。另见
ta.sma
ta.ema
返回序列的模式。如果有多个具有相同频率的值,则返回最小值。
ta.mode(source, length)
返回值 序列的模式。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).返回序列的中位数。
ta.median(source, length)
返回值 序列的中位数。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).线性回归曲线。一条最符合用户定义时间段内指定价格的线。它是使用最小二乘法计算的。此函数的结果使用以下公式计算:linreg = intercept + slope * (length - 1 - offset),其中 intercept 和 slope 是使用 source
系列的最小二乘法计算的值。
ta.linreg(source, length, offset)
返回值 线性回归曲线
参数
source
(series int/float) 源系列。length
(series int)offset
(simple int) 偏移布林带。布林带是一种技术分析工具,由一组线定义,这些线与证券价格的简单移动平均线(SMA)相距两个标准偏差(正向和负向),但可以根据用户偏好进行调整。
ta.bb(series, length, mult)
例子
[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)
返回值 布林带。
参数
series
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).mult
(simple int/float) 标准差因子。另见
ta.sma
ta.stdev
ta.kc
布林带的宽度。布林带宽度是上轨和下轨到中线的距离。
ta.bbw(series, length, mult)
例子
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))
返回值 布林带宽度。
参数
series
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).mult
(simple int/float) 标准差因子。另见
ta.bb
ta.sma
ta.stdev
CCI(商品路径指数)的计算方法是商品的典型价格与其简单移动平均线之间的差值除以典型价格的平均绝对偏差。该指数按0.015的倒数进行缩放,以提供更多可读的数字。
ta.cci(source, length)
返回值 lengthK线返回的source的商品渠道指数。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).当前值与前一个值之间的差分,source - source[length]。
ta.change(source, length)
ta.change(source)
返回值 减法的结果。
参数
source
(series int/float) 源系列。length
(series int) 从当前k线偏移到上一个k线。 可选,如未给予,则使用length = 1。另见
ta.mom
ta.cross
source
价格和source
价格length
K线之前的动量。这只是一个差分:source - source[length]。
ta.mom(source, length)
返回值
source
价格和source
价格length
K线之前的动量。
参数
source
(series int/float) 待执行的系列值。length
(series int) 从当前k线偏移到上一个k线。另见
ta.change
钱德动量摆动指标。计算最近的上涨点数之和与最近的下跌点数之和,然后将两者相减,然后将结果除以同一时期内所有价格变动的总和
ta.cmo(series, length)
例子
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))
返回值 钱德动量摆动指标
参数
series
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.rsi
ta.stoch
math.sum
使用最近的两个排名之间的线性插值方法计算百分比。
ta.percentile_linear_interpolation(source, length, percentage)
返回值
length
K线返回的source
系列的第P个百分位数。
参数
source
(series int/float) 待执行的系列值(来源)。length
(series int) 过去的K线数量(长度)percentage
(simple int/float) 百分比,从0到100的范围内的数字备注 请注意,使用此方法计算的百分比并非都是输入数据集一员。
另见
ta.percentile_nearest_rank
根据最近的排名方法计算百分比。
ta.percentile_nearest_rank(source, length, percentage)
返回值
length
K线返回的source
系列的第P个百分位数。
参数
source
(series int/float) 待执行的系列值(来源)。length
(series int) 过去的K线数量(长度)percentage
(simple int/float) 百分比,从0到100的范围内的数字备注 使用少于过去100 k线长度的最近排名法可导致相同的数字用于多个百分位数。 最近排名法计算的百分比都是输入数据集一员。 第100个百分点被定义为输入数据集中的最大值。
另见
ta.percentile_linear_interpolation
百分比等级是以前的值小于或等于给定系列当前值的百分比。
ta.percentrank(source, length)
返回值
length
K线返回的source
百分比排名。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).方差是一系列与其均值的平方偏差的期望值 (ta.sma),它非正式地衡量一组数字与其均值的距离。
ta.variance(source, length, biased)
返回值
length
K线返回的source
的方差。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).biased
(series bool) 确定应该使用哪个估计。可选。默认值为true。备注
如果biased
为true,函数将使用对整个总体的有偏估计进行计算,如果为false - 对样本的无偏估计。
另见
ta.dev
ta.stdev
ta.tr(handle_na)
返回值 真实范围。它是math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]))。
参数
handle_na
(simple bool) 如何处理 NaN 值。 如果为 true,并且前一天的收盘价为 NaN,则 tr 将被计算为当天的高-低点。否则(如果为false) tr 在这种情况下将返回 NaN。另请注意,ta.atr 使用 ta.tr(true)。备注
ta.tr(false)
与ta.tr
完全相同。
另见
ta.atr
资金流量指标。资金流量指标是一种技术指标,它使用价格和成交量来确定资产中的超买或超卖状况。
ta.mfi(series, length)
例子
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))
返回值 资金流量指标
参数
series
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.rsi
math.sum
肯特纳通道。肯特那通道是一个技术指标,包含了中间的移动平均线以及上下轨的通道。
ta.kc(series, length, mult)
ta.kc(series, length, mult, useTrueRange)
例子
[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)
返回值 肯特纳通道
参数
series
(series int/float) 待执行的系列值。length
(simple int) K线数量(长度).mult
(simple int/float) 标准差因子。useTrueRange
(simple bool) 可选参数。指定是否使用真实范围; 默认为true。 如果值为false,则将使用表达式(high-low)来计算范围。另见
ta.ema
ta.atr
ta.bb
肯特纳通道宽度。肯特那通道宽度是上,下通道之间的差除以中间通道的值。
ta.kcw(series, length, mult)
ta.kcw(series, length, mult, useTrueRange)
例子
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))
返回值 肯特纳通道宽度。
参数
series
(series int/float) 待执行的系列值。length
(simple int) K线数量(长度).mult
(simple int/float) 标准差因子。useTrueRange
(simple bool) 可选参数。指定是否使用真实范围; 默认为true。 如果值为false,则将使用表达式(high-low)来计算范围。另见
ta.kc
ta.ema
ta.atr
ta.bb
相关系数。描述两个系列倾向于偏离其ta.sma值的程度。
ta.correlation(source1, source2, length)
返回值 相关系数。
参数
source1
(series int/float) 源系列。source2
(series int/float) 目标系列。length
(series int) 长度(K线数量)另见
request.security
ta.cross(source1, source2)
返回值 如果两个系列相互交叉则为true,否则为false。
参数
source1
(series int/float) 第一数据系列。source2
(series int/float) 第二数据系列。另见
ta.change
source1
-series被定义为跨越source2
-series,如果在当前K线上,source1
的值大于source2
的值,并且在前一个K线上,source2
的值source1小于
source2`的值。
ta.crossover(source1, source2)
返回值
如果source1
穿过source2
则为true,否则为false。
参数
source1
(series int/float) 第一数据系列。source2
(series int/float) 第二数据系列。source1
-series 被定义为在 source2
-series 下交叉,如果在当前K线上,source1
的值小于source2
的值,并且在前一根K线上,source1
的值大于source2
的值。
ta.crossunder(source1, source2)
返回值
如果source1
在source2
下交叉,则为true,否则为false。
参数
source1
(series int/float) 第一数据系列。source2
(series int/float) 第二数据系列。函数ATR(真实波动幅度均值)返回真实范围的RMA。真实波动幅度是max(high - low, abs(high - close[1]), abs(low - close[1]))。
ta.atr(length)
例子
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))
返回值 真实波动幅度均值(ATR)
参数 length (simple int) 长度(K线数量)
另见
ta.tr
ta.rma
抛物线转向(抛物线停止和反向)是J. Welles Wilder, Jr.设计的方法,以找出交易市场价格方向的潜在逆转。
ta.sar(start, inc, max)
例子
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)
返回值 抛物线转向指标。
参数
start
(simple int/float) 开始。inc
(simple int/float) 增加max
(simple int/float) 最大.从上次条件为true起,计算K线数量。
ta.barssince(condition)
例子
// get number of bars since last color.green bar
plot(ta.barssince(close >= open))
返回值 如状况为true的k线数目。
备注 如果在当前K线之前从未满足该条件,则该函数返回na。 请注意,使用此变量/函数可能会导致指标重新绘制。
另见
ta.lowestbars
ta.highestbars
ta.valuewhen
ta.highest
ta.lowest
source
的累积(全部的)总和。换句话说,它是source
的所有元素的总和。
ta.cum(source)
返回值 系列总和。
参数
source
(series int/float)另见
math.sum
dmi函数返回动向指数DMI。
ta.dmi(diLength, adxSmoothing)
例子
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")
返回值 三个DMI系列的元组:正方向运动(+DI)、负方向运动(-DI) 和平均方向运动指数(ADX)。
参数
diLength
(simple int) DI Period。adxSmoothing
(simple int) ADX平滑周期另见
ta.rsi
ta.tsi
ta.mfi
测试 source
系列对于 length
K线long是否正在下跌。
ta.falling(source, length)
返回值
如果当前 source
值小于 length
K线返回的任何先前 source
值,则为true,否则为false。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.rising
测试 source
系列对于 length
K线long是否正在上涨。
ta.rising(source, length)
返回值
如果当前 source
值大于 length
K线返回的任何先前 source
值,则为true,否则为false。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).另见
ta.falling
此函数返回枢轴高点的价格。 如果没有枢轴高点,则返回“NaN”。
ta.pivothigh(source, leftbars, rightbars)
ta.pivothigh(leftbars, rightbars)
例子
leftBars = input(2)
rightBars=input(2)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_cross, linewidth=3, color= color.red, offset=-rightBars)
返回值 此点的价格或者 ‘NaN’.
参数
source
(series int/float) 可选参数。数据序列计算值。预设值’High’。leftbars
(series int/float) 左力量。rightbars
(series int/float) 右长度。备注 如果参数’leftbars’或’rightbars’是系列,你应该使用max_bars_back函数作为’source’变量。
此函数返回枢轴低点的价格。 如果没有枢轴低点,它返回“NaN”。
ta.pivotlow(source, leftbars, rightbars)
ta.pivotlow(leftbars, rightbars)
例子
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)
返回值 此点的价格或者 ‘NaN’.
参数
source
(series int/float) 可选参数。 数据系列计算值。 默认为“Low”。leftbars
(series int/float) 左力量。rightbars
(series int/float) 右长度。备注 如果参数’leftbars’或’rightbars’是系列,你应该使用max_bars_back函数作为’source’变量。
过去k线的给定数目的最高值。
ta.highest(source, length)
ta.highest(length)
返回值 系列中的最高值。
参数
source
(series int/float) 待执行的系列值。length
(series int) K线数量(长度).备注
两个 args 版本:source
是一个系列,length
是返回的K线数。
一个 arg 版本:length
是返回的K线数。算法使用high作为 source
系列。
另见
ta.lowest
ta.lowestbars
ta.highestbars
ta.valuewhen
ta.barssince
过去k线的给定数目的最高值偏移。
ta.highestbars(source, length)
ta.highestbars(length)
返回值 偏移到最高k线。
参数
source
(serieswuhuoyan 想要币安u合约多个交易对同时运行怎么搞
轻轻的云 请教下,pine能多交易对吗? 也是和JS一样遍历交易对吗??谢谢。
lisa20231 謝謝提供詳細的文檔
artistry 大佬!这 pine script 怎么在平台上使用 okex 的模拟盘?
artistry 这等于是 tradingview平台的策略直接copy到发明者平台就可以使用了吧!
小小梦 PINE语言只能做单品种策略,多品种策略最好还是用python , javascript , c++编写设计。
小小梦 嗯,是的,OKX比较特殊,他们的模拟环境和实盘环境是一样的地址,只是在其它地方做了区别。所以没办法用切换基地址,去切换到模拟盘。
轻轻的云 用不了okx模拟盘。。。。。[捂脸]
小小梦 这个多品种的架构问题不好解决,因为每个交易所接口不一样,对接口频率限定也不一样,会产生很多问题。
小小梦 好的,感谢云总提出建议,这边报下这个需求。
轻轻的云 感觉最好能和JS混编,JS可以更好的适应各种交易方式。
趋势猎手 以后会考虑多品种吗?收盘价每个品种遍历就行
小小梦 不客气。
轻轻的云 好的,谢谢梦大。
小小梦 您好,暂时PINE语言策略只能做单品种。
小小梦 不客气,感谢您的支持。文档还会继续完善。
小小梦 是的。
小小梦 PINE模版类库,参数上可以设置切换交易所基地址。文档开头的:PINE语言交易类库模版参数。