FMZ PINE Script 文档

Author: 雨幕(youquant), Created: 2022-05-10 10:18:57, Updated: 2024-02-23 15:11:55

ta.lowestbarsta.highestbarsta.valuewhenta.barssince```

ta.highestbars

过去k线的给定数目的最高值偏移。

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

返回值 偏移到最高k线。

参数

  • source (series int/float) 待执行的系列值。
  • length (series int) K线数量(长度).

备注 两个 args 版本:source 是一个系列,length 是返回的K线数。 一个 arg 版本:length 是返回的K线数。算法使用high作为 source 系列。

另见 ta.lowest ta.highest ta.lowestbars ta.barssince ta.valuewhen

ta.stoch

随机指标。计算方程:100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length))。

ta.stoch(source, high, low, length) 

返回值 随机

参数

  • source (series int/float) 源系列。
  • high (series int/float) 高系列
  • low (series int/float) 低系列
  • length (series int) 长度(K线数量)

另见 ta.cog

ta.supertrend

超级趋势指标。超级趋势指标是一个跟随趋势的指标。

ta.supertrend(factor, atrPeriod) 

例子

[supertrend, direction] = ta.supertrend(3, 10)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

// The same on Pine
pine_supertrend(factor, atrPeriod) =>
    src = hl2
    atr = ta.atr(atrPeriod)
    upperBand = src + factor * atr
    lowerBand = src - factor * atr
    prevLowerBand = nz(lowerBand[1])
    prevUpperBand = nz(upperBand[1])

    lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
    upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
    int direction = na
    float superTrend = na
    prevSuperTrend = superTrend[1]
    if na(atr[1])
        direction := 1
    else if prevSuperTrend == prevUpperBand
        direction := close > upperBand ? -1 : 1
    else
        direction := close < lowerBand ? 1 : -1
    superTrend := direction == -1 ? lowerBand : upperBand
    [superTrend, direction]

[pineSupertrend, pineDirection] = pine_supertrend(3, 10)
plot(pineDirection < 0 ? pineSupertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(pineDirection > 0 ? pineSupertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

返回值 两个超趋势系列的元组:超趋势线和趋势方向。可能的值为 1(向下方向)和 -1(向上方向)。

参数

  • factor (series int/float) ATR将乘以的乘数。
  • atrPeriod (simple int) 平均真实波幅长度。

另见 ta.macd

ta.lowest

过去k线的给定数目的最低值。

ta.lowest(source, length) 
ta.lowest(length) 

返回值 系列中的最低值。

参数

  • source (series int/float) 待执行的系列值。
  • length (series int) K线数量(长度).

备注 两个 args 版本:source 是一个系列,length 是返回的K线数。 一个 arg 版本:length 是返回的K线数。算法使用low作为source系列。

另见 ta.highest ta.lowestbars ta.highestbars ta.valuewhen ta.barssince

ta.lowestbars

过去k线的给定数目的最低值偏移。

ta.lowestbars(source, length) 
ta.lowestbars(length) 

返回值 偏移到最低k线。

参数

  • source (series int/float) 待执行的系列值。
  • length (series int) 返回K线数。

备注 两个 args 版本:source 是一个系列,length 是返回的K线数。 一个 arg 版本:length 是返回的K线数。算法使用low作为source系列。

另见 ta.lowest ta.highest ta.highestbars ta.barssince ta.valuewhen

ta.valuewhen

返回第n次最近出现的“condition”为true的K线的“source”系列值。

ta.valuewhen(condition, source, occurrence) 

例子

slow = ta.sma(close, 7)
fast = ta.sma(close, 14)
// Get value of `close` on second most recent cross
plot(ta.valuewhen(ta.cross(slow, fast), close, 1))

参数

  • condition (series bool) 要搜索的条件。
  • source (series int/float/bool/color) 要从满足条件的K线返回的值。
  • occurrence (simple int) 条件的出现。编号从0开始并按时间回溯,因此“0”是最近出现的“condition”,“1”是第二个最近出现的,依此类推。必须是整数 >= 0。

备注 此功能需要在每根K线上执行。不建议在for或while循环结构中使用它,因为它的行为可能出乎意料。请注意,使用此功能可能会导致指标重绘。

另见 ta.lowestbars ta.highestbars ta.barssince ta.highest ta.lowest

ta.vwap

成交量加权平均价格

ta.vwap(source) 

返回值 成交量加权平均

参数

  • source (series int/float) 源系列。

另见 ta.vwap

ta.vwma

vwma 函数返回 length K线的 source 的成交量加权移动平均值。等同于:sma(source * volume, length) / sma(volume, length)。

ta.vwma(source, length) 

例子

plot(ta.vwma(close, 15))

// same on pine, but less efficient
pine_vwma(x, y) =>
    ta.sma(x * volume, y) / ta.sma(volume, y)
plot(pine_vwma(close, 15))

返回值 lengthK线返回的source的成交量加权移动平均线。

参数

  • source (series int/float) 待执行的系列值。
  • length (series int) K线数量(长度).

另见 ta.sma ta.ema ta.rma ta.wma ta.swma ta.alma

ta.wpr

威廉姆斯指标Williams %R。。该振荡指标显示当前收盘价与过去“一段时间内”的高/低价之间的关系。

ta.wpr(length) 

例子

plot(ta.wpr(14), title="%R", color=color.new(#ff6d00, 0))

返回值 Williams %R。

参数

  • length (series int) K线数量。

另见 ta.mfi ta.cmo

plot

plot

在图表上绘制一系列数据。

plot(series, title, color, linewidth, style, trackprice, histbase, offset, join, editable, show_last, display) 

例子

plot(high+low, title='Title', color=color.new(#00ffaa, 70), linewidth=2, style=plot.style_area, offset=15, trackprice=true)

// You may fill the background between any two plots with a fill() function:
p1 = plot(open)
p2 = plot(close)
fill(p1, p2, color=color.new(color.green, 90))

返回值 可用于fill的绘图对象。

参数

  • series (series int/float) 要绘制的数据系列。 必要参数。
  • title (const string) 绘图标题。
  • color (series color) 绘图的颜色。您可以使用如’color = red’或’color =#ff001a’的常量以及如 'color = close >= open ? green : red’的复杂表达式。 可选参数。
  • linewidth (input int) 绘制线的宽度。默认值为1。不适用于每种样式。
  • style (plot_style) plot类型。可能的值有:plot.style_line、plot.style_stepline、plot.style_stepline_diamond、plot.style_histogram、plot.style_cross、plot.style_area、plot.style_columns、plot.style_circles、plot.style_linebr、plot.style_areabr。默认值为plot.style_line。
  • trackprice (input bool) 如果为true,则水平价格线将显示在最后一个指标值的水平。默认为false。
  • histbase (input int/float) 以plot.style_histogram,plot.style_columns或plot.style_area样式绘制图时,用作参考水平的价格值。默认值为0.0。
  • offset (series int) 在k线特定数量上向左或向右移动绘图。 默认值为0。
  • join (input bool) 如果为true,则绘图点将与线连接,仅适用于plot.style_cross和plot.style_circles样式。 默认值为false。
  • editable (const bool) 如果为true,则绘图样式可在格式对话框中编辑。 默认值为true。
  • show_last (input int) 如已设置,则定义在图表上绘制的k线数(从最后k线返回过去)。
  • display (plot_display) 控制显示绘图的位置。可能的值为:display.none、display.all。预设值为display.all。
  • overlay (const bool) FMZ平台扩展的参数,用于设置当前函数在主图(设置true)或者副图(设置false)上画图显示,默认值为false。不指定该参数则按照strategy或者indicator中的overlay参数设置,strategy或者indicator没有设置overlay参数,则按照默认参数处理。

另见 plotshape plotchar bgcolor

plotshape

在图表上绘制可视形状。

plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display) 

例子

data = close >= open
plotshape(data, style=shape.xcross)

参数

  • series (series bool) 作为形状绘制的一系列数据 。 除了location.absolute之外,系列被视为所有位置值的一系列布尔值。 必要参数。
  • title (const string) 绘图标题。
  • style (input string) 绘图类型。可能的值有:shape.xcross,shape.cross,shape.triangleup,shape.triangledown,shape.flag,shape.circle,shape.arrowup,shape.arrowdown,shape.labelup,shape.labeldown,shape.square,shape.diamond。 默认值为shape.xcross。
  • location (input string) 形状在图表上的位置。 可能的值有:location.abovebar,location.belowbar,location.top,location.bottom,location.absolute。 默认值为location.abovebar。
  • color (series color) 形状的颜色。 您可以使用如’color = red’或’color =#ff001a’的常量以及如 'color = close >= open ? green : red’的复杂表达式。 可选参数。
  • offset (series int) 在k线特定数量上向左或向右移动形状。 默认值为0。
  • text (const string) 文字以形状显示。 您可以使用多行文本,分隔行使用’\n’转义序列。示例:‘line one\nline two’。
  • textcolor (series color) 文字的颜色。 您可以使用如 ‘textcolor=red’ 或’textcolor=#ff001a’ 的常量,以及如’textcolor = close >= open ? green : red’的复杂表达式。 可选参数。
  • editable (const bool) 如果为true,则plotshape样式可在格式对话框中编辑。 默认值为true。
  • show_last (input int) 如已设置,则定义在图表上绘制的形状数(从最后k线返回过去)。
  • size (const string) 图表上字符的大小。 可能的值有: size.auto, size.tiny, size.small, size.normal, size.large, size.huge。默认值为size.auto
  • display (plot_display) 控制显示绘图的位置。可能的值为:display.none、display.all。预设值为display.all。
  • overlay (const bool) FMZ平台扩展的参数,用于设置当前函数在主图(设置true)或者副图(设置false)上画图显示,默认值为false。不指定该参数则按照strategy或者indicator中的overlay参数设置,strategy或者indicator没有设置overlay参数,则按照默认参数处理。

另见 plot plotchar bgcolor

plotchar

在图表上使用任何给定的Unicode字符绘制可视形状。

plotchar(series, title, char, location, color, offset, text, textcolor, editable, size, show_last, display) 

例子

data = close >= open
plotchar(data, char='❄')

参数

  • series (series bool) 作为形状绘制的一系列数据 。 除了location.absolute之外,系列被视为所有位置值的一系列布尔值。 必要参数。
  • title (const string) 绘图标题。
  • char (input string) 作为视觉形状使用的字符
  • location (input string) 形状在图表上的位置。 可能的值有:location.abovebar,location.belowbar,location.top,location.bottom,location.absolute。 默认值为location.abovebar。
  • color (series color) 形状的颜色。 您可以使用如’color = red’或’color =#ff001a’的常量以及如 'color = close >= open ? green : red’的复杂表达式。 可选参数。
  • offset (series int) 在k线特定数量上向左或向右移动形状。 默认值为0。
  • text (const string) 文字以形状显示。 您可以使用多行文本,分隔行使用’\n’转义序列。示例:‘line one\nline two’。
  • textcolor (series color) 文字的颜色。 您可以使用如 ‘textcolor=red’ 或’textcolor=#ff001a’ 的常量,以及如’textcolor = close >= open ? green : red’的复杂表达式。 可选参数。
  • editable (const bool) 如果为true,则plotchar样式可在格式对话框中编辑。 默认值为true。
  • show_last (input int) 如已设置,则定义在图表上绘制的图表数(从最后k线返回过去)。
  • size (const string) 图表上字符的大小。 可能值有:size.auto,size.tiny,size.small,size.normal,size.large,size.huge。 默认值为size.auto
  • display (plot_display) 控制显示绘图的位置。可能的值为:display.none、display.all。预设值为display.all。
  • overlay (const bool) FMZ平台扩展的参数,用于设置当前函数在主图(设置true)或者副图(设置false)上画图显示,默认值为false。不指定该参数则按照strategy或者indicator中的overlay参数设置,strategy或者indicator没有设置overlay参数,则按照默认参数处理。

另见 plot plotshape bgcolor

plotcandle

在图表上绘制蜡烛。

plotcandle(open, high, low, close, title, color, wickcolor, editable, show_last, bordercolor, display)

例子

indicator("plotcandle example", overlay=true)
plotcandle(open, high, low, close, title='Title', color = open < close ? color.green : color.red, wickcolor=color.black)

参数

  • open (series int/float) 数据开放系列用作蜡烛开放值。必要参数。
  • high (series int/float) 高系列数据用作蜡烛的高值。必要参数。
  • low (series int/float) 低系列数据被用作蜡烛的低值。 必要参数。
  • close (series int/float) 关闭系列数据作为关闭k线的值。 必要参数。
  • title (const string) plotcandle的标题。 可选参数。
  • color (series color) 蜡烛的颜色。您可以使用如’color = red’或’color =#ff001a’的常量以及像’color = close >= open ? green : red’的复杂表达式。可选参数。
  • wickcolor (series color) 蜡烛灯芯的颜色。一个可选参数。
  • editable (const bool) 如果为true,则plotcandle样式可在格式对话框中编辑。 默认值为true。
  • show_last (input int) 如已设置,则定义在图表上绘制的蜡烛数(从最后k线返回过去)。
  • bordercolor (series color) 蜡烛的边框颜色。一个可选参数。
  • display (plot_display) 控制显示绘图的位置。可能的值为:display.none、display.all。预设值为display.all。
  • overlay (const bool) FMZ平台扩展的参数,用于设置当前函数在主图(设置true)或者副图(设置false)上画图显示,默认值为false。不指定该参数则按照strategy或者indicator中的overlay参数设置,strategy或者indicator没有设置overlay参数,则按照默认参数处理。

备注 如果开高低收都是NaN,那么K线不需要显示出来。 开、高、低、收的最大值将被设置为“高”,最小值被设置为“低”。

另见 plotbar

plotarrow

在图表上绘制向上和向下箭头:向上箭头绘制在每个正值指示器上,而向下箭头绘制在每个负值上。 如果指标返回na,则不会绘制箭头。 箭头具有不同的高度,指标的绝对值越大,绘制箭头越长。

plotarrow(series, title, colorup, colordown, offset, minheight, maxheight, editable, show_last, display)

例子

codiff = close - open
plotarrow(codiff, colorup=color.new(color.teal,40), colordown=color.new(color.orange, 40), overlay=true)

参数

  • series (series int/float) 要绘制成箭头的数据系列。 必要参数。
  • title (const string) 绘图标题。
  • colorup (series color) 向上箭头的颜色。可选参数。
  • colordown (series color) 向下箭头的颜色。可选参数。
  • offset (series int) 在K线特定数量上向左或向右移动箭头。 默认值为0。
  • minheight (input int) 以像素为单位最小可能的箭头高度。默认值为5。
  • maxheight (input int) 以像素为单位的最大可能的箭头高度。默认值为100
  • editable (const bool) 如果为true,则plotarrow样式可在格式对话框中编辑。 默认值为true。
  • show_last (input int) 如已设置,则定义在图表上绘制的箭数(从最后k线返回过去)。
  • display (plot_display) 控制显示绘图的位置。可能的值为:display.none、display.all。预设值为display.all。
  • overlay (const bool) FMZ平台扩展的参数,用于设置当前函数在主图(设置true)或者副图(设置false)上画图显示,默认值为false。不指定该参数则按照strategy或者indicator中的overlay参数设置,strategy或者indicator没有设置overlay参数,则按照默认参数处理。

另见 plot plotshape plotchar barcolor bgcolor

array

array.pop

该函数从阵列中删除最后一个元素并返回其值。

array.pop(id)

例子

// array.pop example
a = array.new_float(5,high)
removedEl = array.pop(a)
plot(array.size(a))
plot(removedEl)

返回值 被删除元素的值。

参数

  • id (any array type) 阵列对象。

另见 array.new_float array.set array.push array.remove array.insert array.shift

array.shift

该函数删除阵列的第一个元素并返回其值。

array.shift(id)

例子

// array.shift example
a = array.new_float(5,high)
removedEl = array.shift(a)
plot(array.size(a))
plot(removedEl)

返回值 被删除元素的值。

参数

  • id (any array type) 阵列对象。

另见 array.unshift array.set array.push array.remove array.includes

array.unshift

该函数将值插入阵列的初始位置。

array.unshift(id, value)

例子

// array.unshift example
a = array.new_float(5, 0)
array.unshift(a, open)
plot(array.get(a, 0))

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 要添加到阵列初始位置的值。

另见 array.shift array.set array.insert array.remove array.indexof

array.size

该函数返回阵列中元素的数量。

array.size(id)

例子

// array.size example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
// note that changes in slice also modify original array
slice = array.slice(a, 0, 5)
array.push(slice, open)
// size was changed in slice and in original array
plot(array.size(a))
plot(array.size(slice))

返回值 阵列中元素的数量。

参数

  • id (any array type) 阵列对象。

另见 array.new_float array.sum array.slice array.sort

array.slice

该函数从现有阵列创建分片。如果分片中的对象发生更改,则更改将同时应用于新阵列和原始阵列。

array.slice(id, index_from, index_to)

例子

// array.slice example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
// take elements from 0 to 4
// *note that changes in slice also modify original array 
slice = array.slice(a, 0, 5)
plot(array.sum(a) / 10)
plot(array.sum(slice) / 5)

返回值 阵列分片的浅拷贝。

参数

  • id (any array type) 阵列对象。
  • index_from (series int) 从零开始的索引以开始提取。
  • index_to (series int) 从零开始的索引在完成提取之前。该函数提取此索引之前的元素。

另见 array.new_float array.get array.sort

array.abs

返回一个阵列,其中包含原始阵列中每个元素的绝对值。

array.abs(id)

参数

  • id (int[]/float[]) 阵列对象。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.binary_search

该函数返回值的索引,如果未找到该值,则返回-1。要搜索的阵列必须按升序排序。

array.binary_search(id, val)

例子

// array.binary_search
a = array.from(5, -2, 0, 9, 1)
array.sort(a) // [-2, 0, 1, 5, 9]
position = array.binary_search(a, 0) // 1
plot(position)

参数

  • id (int[]/float[]) 阵列对象。
  • val (series int/float) 在阵列中搜索的值。

备注 二进制搜索适用于按升序预先排序的阵列。它首先将阵列中间的元素与目标值进行比较。如果元素与目标值匹配,则返回其在阵列中的位置。如果元素的值大于目标值,则在阵列的下半部分继续搜索。如果元素的值小于目标值,则在阵列的上半部分继续搜索。通过递归地执行此操作,该算法逐渐消除了阵列中目标值不能位于的越来越小的部分。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.binary_search_leftmost

如果找到值,该函数将返回该值的索引。当未找到值时,该函数返回下一个最小元素的索引,如果它在阵列中,则在值所在位置的左侧。要搜索的阵列必须按升序排序。

array.binary_search_leftmost(id, val)

例子

// array.binary_search_leftmost
a = array.from(5, -2, 0, 9, 1)
array.sort(a) // [-2, 0, 1, 5, 9]
position = array.binary_search_leftmost(a, 3) // 2
plot(position)

参数

  • id (int[]/float[]) 阵列对象。
  • val (series int/float) 在阵列中搜索的值。

备注 二进制搜索适用于按升序预先排序的阵列。它首先将阵列中间的元素与目标值进行比较。如果元素与目标值匹配,则返回其在阵列中的位置。如果元素的值大于目标值,则在阵列的下半部分继续搜索。如果元素的值小于目标值,则在阵列的上半部分继续搜索。通过递归地执行此操作,该算法逐渐消除了阵列中目标值不能位于的越来越小的部分。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.binary_search_rightmost

如果找到该值,该函数将返回该值的索引。当未找到该值时,该函数返回该值在阵列中所在位置右侧的元素的索引。阵列必须按升序排序。

array.binary_search_rightmost(id, val)

例子

// array.binary_search_rightmost
a = array.from(5, -2, 0, 9, 1)
array.sort(a) // [-2, 0, 1, 5, 9]
position = array.binary_search_rightmost(a, 3) // 3
plot(position)

参数

  • id (int[]/float[]) 阵列对象。
  • val (series int/float) 在阵列中搜索的值。

备注 二进制搜索按升序对已排序的阵列起作用。它首先将阵列中间的元素与目标值进行比较。如果元素与目标值匹配,则返回其在阵列中的位置。如果元素的值大于目标值,则在阵列的下半部分继续搜索。如果元素的值小于目标值,则在阵列的上半部分继续搜索。通过递归地执行此操作,该算法逐渐消除了阵列中目标值不能位于的越来越小的部分。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.sort

该函数对阵列的元素进行排序。

array.sort(id, order)

例子

// array.sort example
a = array.new_float(0,0)
for i = 0 to 5
    array.push(a, high[i])
array.sort(a, order.descending)
if barstate.islast
    runtime.log(str.tostring(a))

参数

  • id (int[]/float[]/string[]) 阵列对象。
  • order (sort_order) 排序顺序:order.ascending(默认)或order.descending。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.sort_indices

返回一个索引阵列,当用于索引原始阵列时,将按其排序顺序访问其元素。它不会修改原始阵列。

array.sort_indices(id, order)

例子

// array.sort_indices
a = array.from(5, -2, 0, 9, 1)
sortedIndices = array.sort_indices(a) // [1, 2, 4, 0, 3]
indexOfSmallestValue = array.get(sortedIndices, 0) // 1
smallestValue = array.get(a, indexOfSmallestValue) // -2
plot(smallestValue)

参数

  • id (int[]/float[]/string[]) 阵列对象。
  • order (sort_order) 排序顺序:order.ascending 或 order.descending。可选。默认值为 order.ascending。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.clear

该函数从阵列中删除所有元素。

array.clear(id)

例子

// array.clear example
a = array.new_float(5,high)
array.clear(a)
array.push(a, close)
plot(array.get(a,0))
plot(array.size(a))

参数

  • id (any array type) 阵列对象。

另见 array.new_float array.insert array.push array.remove array.pop

array.concat

该函数用于合并两个阵列。它将所有元素从第二个阵列推送到第一个阵列,然后返回第一个阵列。

array.concat(id1, id2)

例子

// array.concat example
a = array.new_float(0,0)
b = array.new_float(0,0)
for i = 0 to 4
    array.push(a, high[i])
    array.push(b, low[i])
c = array.concat(a,b)
plot(array.size(a))
plot(array.size(b))
plot(array.size(c))

返回值 第一个阵列具有来自第二个阵列的合并元素。

参数

  • id1 (any array type) 第一个阵列对象。
  • id2 (any array type) 第二个阵列对象。

另见 array.new_float array.insert array.slice

array.copy

该函数创建现有阵列的副本。

array.copy(id)

例子

// array.copy example
length = 5
a = array.new_float(length, close)
b = array.copy(a)
a := array.new_float(length, open)
plot(array.sum(a) / length)
plot(array.sum(b) / length)

返回值 阵列的副本。

参数

  • id (any array type) 阵列对象。

另见 array.new_float array.get array.slice array.sort

array.stdev

该函数返回阵列元素的标准差。

array.stdev(id, biased)

例子

// array.stdev example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.stdev(a))

返回值 阵列元素的标准差。

参数

  • id (int[]/float[]) 阵列对象。
  • biased (series bool) 确定应该使用哪个估计。可选。默认值为true。

备注 如果biased为true,函数将使用对整个总体的有偏估计进行计算,如果为false - 对样本的无偏估计。

另见 array.new_float array.max array.min array.avg

array.standardize

该函数返回标准化元素的阵列。

array.standardize(id)

例子

// array.standardize example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
b = array.standardize(a)
plot(array.min(b))
plot(array.max(b))

返回值 标准化元素的阵列。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.max array.min array.mode array.avg array.variance array.stdev

array.variance

该函数返回阵列元素的方差。

array.variance(id, biased)

例子

// array.variance example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.variance(a))

返回值 阵列元素的方差。

参数

  • id (int[]/float[]) 阵列对象。
  • biased (series bool) 确定应该使用哪个估计。可选。默认值为true。

备注 如果biased为true,函数将使用对整个总体的有偏估计进行计算,如果为false - 对样本的无偏估计。

另见 array.new_float array.stdev array.min array.avg array.covariance

array.covariance

该函数返回两个阵列的协方差。

array.covariance(id1, id2, biased)

例子

// array.covariance example
a = array.new_float(0)
b = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
    array.push(b, open[i])
plot(array.covariance(a, b))

返回值 两个阵列的协方差。

参数

  • id1 (int[]/float[]) 阵列对象。
  • id2 (int[]/float[]) 阵列对象。
  • biased (series bool) 确定应该使用哪个估计。可选。默认值为true。

备注 如果biased为true,函数将使用对整个总体的有偏估计进行计算,如果为false - 对样本的无偏估计。

另见 array.new_float array.max array.stdev array.avg array.variance

array.fill

该函数将阵列的元素设置为单个值。如果未指定索引,则设置所有元素。如果仅提供起始索引(默认为0),则设置从该索引开始的元素。如果同时使用两个索引参数,则会设置从开始索引到但不包括结束索引的元素(默认值为na)。

array.fill(id, value, index_from, index_to)

例子

// array.fill example
a = array.new_float(10)
array.fill(a, close)
plot(array.sum(a))

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 用于填充阵列的值。
  • index_from (series int) 起始索引,默认为0。
  • index_to (series int) 结束索引,默认为na。必须大于要设置的最后一个元素的索引。

另见 array.new_float array.set array.slice

array.includes

如果在阵列中找到该值,则该函数返回true,否则返回false。

array.includes(id, value)

例子

// array.includes example
a = array.new_float(5,high)
p = close
if array.includes(a, high)
    p := open
plot(p)

返回值 如果在阵列中找到该值,则为true,否则为false。

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 要在阵列中搜索的值。

另见 array.new_float array.indexof array.shift array.remove array.insert

array.insert

该函数通过在适当位置添加新元素来更改阵列的内容。

array.insert(id, index, value)

例子

// array.insert example
a = array.new_float(5, close)
array.insert(a, 0, open)
plot(array.get(a, 5))

参数

  • id (any array type) 阵列对象。
  • index (series int) 插入值的索引。
  • value (series <type of the array's elements>) 要添加到阵列的值。

另见 array.new_float array.set array.push array.remove array.pop array.unshift

array.join

该函数通过连接阵列的所有元素来建立并返回新字符串,用指定的分隔符字符串分隔。

array.join(id, separator)

例子

// array.join example
a = array.new_float(5, 5)
runtime.log(array.join(a, ","))

参数

  • id (int[]/float[]/string[]) 阵列对象。
  • separator (series string) 用于分隔每个阵列元素的字符串。

另见 array.new_float array.set array.insert array.remove array.pop array.unshift

array.lastindexof

此函数返回值最后一次出现的索引。如果找不到该值,则返回 -1。

array.lastindexof(id, value)

例子

// array.lastindexof example
a = array.new_float(5,high)
index = array.lastindexof(a, high)
plot(index)

返回值 元素的索引。

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 要在阵列中搜索的值。

另见 array.new_float array.set array.push array.remove array.insert

array.max

该函数返回最大值,或给定阵列中的第n个最大值。

array.max(id, nth)

例子

// array.max
a = array.from(5, -2, 0, 9, 1)
secondHighest = array.max(a, 2) // 1
plot(secondHighest)

返回值 阵列中的最大值或第n个最大值。

参数

  • id (int[]/float[]) 阵列对象。
  • nth (series int) 返回的第n个最大值,其中0是最大值。可选。默认为零。

另见 array.new_float array.min array.sum

array.min

该函数返回最小值,或给定序列中的第n个最小值。

array.min(id, nth)

例子

// array.min
a = array.from(5, -2, 0, 9, 1)
secondLowest = array.min(a, 1) // 0
plot(secondLowest)

返回值 阵列中的最小值或第n个最小值。

参数

  • id (int[]/float[]) 阵列对象。
  • nth (series int) 要返回的第n个最小值,其中0是最小值。可选。默认为零。

另见 array.new_float array.max array.sum

array.median

该函数返回阵列元素的中位数。

array.median(id)

例子

// array.median example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.median(a))

返回值 阵列元素的中位数。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.avg array.variance array.min

array.mode

该函数返回阵列元素的模式。如果有多个具有相同频率的值,则返回最小值。

array.mode(id)

例子

// array.mode example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.mode(a))

返回值 阵列元素的模式。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.new_float array.avg array.variance array.min

array.percentile_linear_interpolation

返回数组值的指定百分比(百分位数)小于或等于它的值,使用线性插值。

array.percentile_linear_interpolation(id, percentage) 

参数

  • id (int[]/float[]) 阵列对象。
  • percentage (series int/float) 必须等于或小于返回值的值的百分比。

备注 在统计数据中,百分位是出现在某个分数或低于某个分数的排名项目的百分比。此测量显示低于您测量的百分等级的标准频率分布中的分数百分比。线性插值估计两个排名之间的值。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.percentile_nearest_rank

使用最近秩方法返回指定百分比的数组值(百分位数)小于或等于它的值。

array.percentile_nearest_rank(id, percentage) 

参数

  • id (int[]/float[]) 阵列对象。
  • percentage (series int/float) 必须等于或小于返回值的值的百分比。

备注 在统计数据中,百分位是出现在某个分数或低于某个分数的排名项目的百分比。 此测量显示低于您正在测量的百分排名的标准频率分布中的分数百分比。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.percentrank

返回阵列中值的百分位排名。

array.percentrank(id, index) 

参数

  • id (int[]/float[]) 阵列对象。
  • index (series int) 计算其百分排名的值。

备注 百分位排名是数组中有多少元素小于或等于参考值的百分比。

另见 array.new_float array.insert array.slice array.reverse order.ascending order.descending

array.range

该函数返回给定数组的最小值和最大值之间的差。

array.range(id) 

例子

// array.range example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.range(a))

返回值 数组中最小值和最大值之间的差。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.new_float array.min array.max array.sum

array.remove

该函数通过删除具有指定索引的元素来更改阵列的内容。

array.remove(id, index)

例子

// array.remove example
a = array.new_float(5,high)
removedEl = array.remove(a, 0)
plot(array.size(a))
plot(removedEl)

返回值 被删除元素的值。

参数

  • id (any array type) 阵列对象。
  • index (series int) 要删除的元素索引。

另见 array.new_float array.set array.push array.insert array.pop array.shift

array.reverse

此函数反转阵列。第一个阵列元素变成最后一个,最后一个阵列元素变成第一个。

array.reverse(id)

例子

// array.reverse example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.get(a, 0))
array.reverse(a)
plot(array.get(a, 0))

参数

  • id (any array type) 阵列对象。

另见 array.new_float array.sort array.push array.set array.avg

array.from

该函数采用以下类型之一的可变数量的参数:int、float、bool、string、line、color、linefill,并返回相应类型的阵列。

array.from(arg0, arg1, ...)

例子

// array.from_example
arr = array.from("Hello", "World!") // arr (string[]) will contain 2 elements: {Hello}, {World!}.
plot(close)

返回值 阵列元素的值。

参数

  • arg0, arg1, ... (series int/float/bool/color/string/line/linefill) 数组参数。

array.new

该函数创建一个新的<type>元素数组对象。

array.new(size, initial_value)

例子

// array.new<string> example
a = array.new<string>(1, "Hello, World!")
runtime.log(array.get(a, 0))

例子

// array.new<color> example
a = array.new<color>()
array.push(a, color.red)
array.push(a, color.green)
plot(close, color = array.get(a, close > open ? 1 : 0))

例子

// array.new<float> example
length = 5
var a = array.new<float>(length, close)
if array.size(a) == length
    array.remove(a, 0)
    array.push(a, close)
plot(array.sum(a) / length, "SMA")

例子

// array.new<line> example
// draw last 15 lines
var a = array.new<line>()
array.push(a, line.new(bar_index - 1, close[1], bar_index, close))
if array.size(a) > 15
    ln = array.shift(a)
    line.delete(ln)

返回值 可与其他阵列一起使用的阵列对象的ID。*()函数。

参数

  • size (series int) 序列的初始大小。可选。默认值为0。
  • initial_value (series <type>) 所有序列元素的初始值。可选。默认值为“na”。

备注 阵列索引从0开始。 如果要初始化一个阵列并同时指定其所有元素,请使用函数array.from。

另见 array.from array.push array.get array.size array.remove array.shift array.sum

array.new_bool

此函数创建一个由bool类型的元素组成的新阵列对象。

array.new_bool(size, initial_value)

例子

// array.new_bool example
length = 5
a = array.new_bool(length, close > open)
plot(array.get(a, 0) ? close : open)

返回值 可与其他阵列一起使用的阵列对象的ID。*()函数。

参数

  • size (series int) 序列的初始大小。可选。默认值为0。
  • initial_value (series bool) 所有序列元素的初始值。可选。默认值为“na”。

备注 阵列索引从0开始。

另见 array.new_float array.get array.slice array.sort

array.new_float

此函数创建一个新的浮点型元素阵列对象。

array.new_float(size, initial_value)

例子

// array.new_float example
length = 5
a = array.new_float(length, close)
plot(array.sum(a) / length)

返回值 可与其他阵列一起使用的阵列对象的ID。*()函数。

参数

  • size (series int) 序列的初始大小。可选。默认值为0。
  • initial_value (series int/float) 所有序列元素的初始值。可选。默认值为“na”。

备注 阵列索引从0开始。

另见 array.new_bool array.get array.slice array.sort

array.new_int

该函数创建一个由int类型的元素组成的新阵列对象。

array.new_int(size, initial_value)

例子

// array.new_int example
length = 5
a = array.new_int(length, int(close))
plot(array.sum(a) / length)

返回值 可与其他阵列一起使用的阵列对象的ID。*()函数。

参数

  • size (series int) 序列的初始大小。可选。默认值为0。
  • initial_value (series int) 所有序列元素的初始值。可选。默认值为“na”。

备注 阵列索引从0开始。

另见 array.new_float array.get array.slice array.sort

array.new_string

该函数创建一个字符串类型元素的新阵列对象。

array.new_string(size, initial_value)

例子

// array.new_string example
length = 5
a = array.new_string(length, "text")
runtime.log(array.get(a, 0))

返回值 可与其他阵列一起使用的阵列对象的ID。*()函数。

参数

  • size (series int) 序列的初始大小。可选。默认值为0。
  • initial_value (series string) 所有序列元素的初始值。可选。默认值为“na”。

备注 阵列索引从0开始。

另见 array.new_float array.get array.slice

array.get

该函数返回指定索引处元素的值。

array.get(id, index)

例子

// array.get example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i] - open[i])
plot(array.get(a, 9))

返回值 阵列元素的值。

参数

  • id (any array type) 阵列对象。
  • index (series int) 要返回其值的元素的索引。

另见 array.new_float array.set array.slice array.sort

array.push

该函数将一个值附加到阵列。

array.push(id, value)

例子

// array.push example
a = array.new_float(5, 0)
array.push(a, open)
plot(array.get(a, 5))

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 添加到阵列末尾的元素值。

另见 array.new_float array.set array.insert array.remove array.pop array.unshift

array.set

该函数将元素的值设置为指定的索引。

array.set(id, index, value) 

例子

// array.set example
a = array.new_float(10)
for i = 0 to 9
    array.set(a, i, close[i])
plot(array.sum(a) / 10)

参数

  • id (any array type) 阵列对象。
  • index (series int) 要修改元素的索引。
  • value (series <type of the array's elements>) 要设置的新值。

另见 array.new_float array.get array.slice

array.sum

该函数返回阵列元素的总和。

array.sum(id) 

例子

// array.sum example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.sum(a))

返回值 阵列元素的总和。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.new_float array.max array.min

array.avg

该函数返回阵列元素的均值。

array.avg(id)

例子

// array.avg example
a = array.new_float(0)
for i = 0 to 9
    array.push(a, close[i])
plot(array.avg(a))

返回值 阵列元素的均值。

参数

  • id (int[]/float[]) 阵列对象。

另见 array.new_float array.max array.min array.stdev

array.indexof

此函数返回值首次出现的索引。如果找不到该值,则返回 -1。

array.indexof(id, value)

例子

// array.indexof example
a = array.new_float(5,high)
index = array.indexof(a, high)
plot(index)

返回值 元素的索引。

参数

  • id (any array type) 阵列对象。
  • value (series <type of the array's elements>) 要在阵列中搜索的值。

另见 array.lastindexof array.get array.lastindexof array.remove array.insert

strategy

strategy相关的内置函数中,止损点数、止盈点数定义为价格一跳的倍数。例如strategy.exit函数的profitloss参数以点表示止损、止盈,参数profit设置为10,即价格一跳乘以10作为止盈价差,价格一跳即内置变量syminfo.mintick

strategy

该函数设置了多个策略属性。 注意,传参仅支持titleshorttitleoverlaypyramidingdefault_qty_typedefault_qty_value参数,其它参数可以通过PINE语言策略的界面参数设置。

strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule, margin_long, margin_short, explicit_plot_zorder, max_lines_count, max_labels_count, max_boxes_count, risk_free_rate) 

例子

strategy("Strategy", overlay = true)

// Enter long by market if current open is greater than previous high.
strategy.entry("Long", strategy.long, 1, when = open > high[1])
// Generate a full exit bracket (profit 10 points, loss 5 points per contract) from the entry named "Long".
strategy.exit("Exit", "Long", profit = 10, loss = 5)

参数

  • title (const string) 将在指标/策略插件中看到的指标标题。参数是必需的。
  • shorttitle (const string) 将在图表图例中看到的指标短标题。参数是可选的。
  • overlay (const bool) 如果为true,则该指标将被添加为主要系列的叠加层。如果为false - 它将被添加到单独的图表窗格中。默认为false。
  • format (const string) 价格轴上格式化指标值的类型可能的值为:format.inherit、format.price、format.volume。默认为format.inherit。
  • precision (const int) 价格轴上指标值的浮点数后的位数。必须是非负整数且不大于16。如果省略,则使用父系列的格式。如果format为format.inherit并且设置了此参数,则format变为format.price。
  • scale (scale_type) 指标应跟随价格坐标。可能的值为:scale.right,scale.left,scale.none。值scale.none只能只能与’overlay=true’设置结合使用。
  • pyramiding (const int) 同一方向允许的最大数量。如果该值为0,则只能打开同一方向的一个入场订单,任何其他入场订单将被拒绝。默认值为0。
  • calc_on_order_fills (const bool) 额外的intrabar订单计算。如果参数被设置为“true”,那么一旦K线内在订单后填满,策略就会重新计算(不仅仅在关闭k线之时)。默认值为“false”。
  • calc_on_every_tick (const bool) 额外的intrabar策略计算。如果参数为“true”,策略将实时计算每个刻度,而不关闭k线。该参数不影响历史数据的策略计算。默认值为“false”。
  • max_bars_back (const int) 可用于历史参考策略的最大蜡烛数。 如果在脚本代码中引用了变量的历史数据(使用了’[]'运算符),则此参数将应用于脚本中的每个内置变量或用户变量。 Pine脚本中的可变缓冲区大小通常是自动检测的。 然而,在某些情况下这是不可能的,这就是参数允许用户手动设置该值的下限的原因。 注意:使用max_bars_back函数而不是参数是最佳的,因为它仅适用于一个变量。
  • backtest_fill_limits_assumption (const int) 限价单执行假设。只有当市价超过限价单水平指定的tick数时,限价单才会在intrabar成交。
  • default_qty_type (const string) 确定用于 qty 参数的值在strategy.entry或strategy.order函数中表示的内容。可能的值是:strategy.fixed表示合约/股票/手数,strategy.cash表示货币金额,或strategy.percent_of_equity表示可用权益的百分比。
  • default_qty_value (const int/float) strategy.entry或strategy.order函数的默认交易数量,当它们的 ‘qty’ 参数未定义时,其单位由与 ‘default_qty_type’ 参数一起使用的参数确定。
  • currency (const string) 此策略的帐户货币。可选。默认值是图表上商品的货币。可能的值: currency.NONE, currency.USD, currency.EUR, currency.AUD, currency.GBP, currency.NZD, currency.CAD, currency.CHF, currency.HKD, currency.JPY, currency.NOK, currency.SEK, currency.SGD, currency.TRY, currency.ZAR, currency.BTC, currency.ETH, currency.MYR, currency.KRW。
  • slippage (const int) 以tick为报价单位的滑点,会从买/卖市价单或止损单的成交价格中增加/减去。如果mintick = 0.01并且滑点= 5,则总滑点将为5 * 0.01 = 0.05。
  • commission_type (const string) 每个订单的佣金类型。 允许的值为:strategy.commission.percent(订单现金量的百分比),strategy.commission.cash_per_contract(以每份合约的账户货币显示金额),strategy.commission.cash_per_order (按每个订单的账户货币显示金额)。
  • commission_value (const int/float) 订单佣金值。取决于所选择的类型 (佣金类型)包括百分比或金额。
  • process_orders_on_close (const bool) 设置为“true”时,会在蜡烛图收盘并完成策略计算后生成执行订单的其他尝试。 如果订单是市价订单,则经纪商模拟器会在下一个蜡烛图开盘前执行它们。 如果订单是限价单,则只

更多内容