avatar of 发明者量化-小小梦 发明者量化-小小梦
关注 私信
4
关注
1271
关注者

FMZ PINE Script Doc

创建于: 2022-04-28 16:05:05, 更新于: 2025-08-21 13:53:57
comments   4
hits   3049

e ‘\n’ escape sequence. Example: ‘line one\nline two’. - textcolor (series color) Color of the text. You can use constants like ‘textcolor=color.red’ or ‘textcolor=#ff001a’ as well as complex expressions like ‘textcolor = close >= open ? color.green : color.red’. Optional argument. - editable (const bool) If true then plotchar style will be editable in Format dialog. Default is true. - show_last (input int) If set, defines the number of chars (from the last bar back to the past) to plot on chart. - size (const string) Size of characters on the chart. Possible values are: size.auto, size.tiny, size.small, size.normal, size.large, size.huge. Default is size.auto. - display (plot_display) Controls where the plot is displayed. Possible values are: display.none, display.all. Default is display.all. - overlay (const bool) is the extension argument of FMZ platform, it is used to set the current function to be displayed on the main image (set to true) or sub-image (set to false), the default value is false. If this argument is not specified, it will be set according to the overlay argument in strategy or indicator, if strategy or indicator does not set the overlay argument, it will be processed according to the default arguments.

See also


### plotcandle

Plots candles on the chart.

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


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

Arguments - open (series int/float) Open series of data to be used as open values of candles. Required argument. - high (series int/float) High series of data to be used as high values of candles. Required argument. - low (series int/float) Low series of data to be used as low values of candles. Required argument. - close (series int/float) Close series of data to be used as close values of candles. Required argument. - title (const string) Title of the plotcandles. Optional argument. - color (series color) Color of the candles. You can use constants like ‘color=color.red’ or ‘color=#ff001a’ as well as complex expressions like ‘color = close >= open ? color.green : color.red’. Optional argument. - wickcolor (series color) The color of the wick of candles. An optional argument. - editable (const bool) If true then plotcandle style will be editable in Format dialog. Default is true. - show_last (input int) If set, defines the number of candles (from the last bar back to the past) to plot on chart. - bordercolor (series color) The border color of candles. An optional argument. - display (plot_display) Controls where the plot is displayed. Possible values are: display.none, display.all. Default is display.all. - overlay (const bool) is the extension argument of FMZ platform, it is used to set the current function to be displayed on the main image (set to true) or sub-image (set to false), the default value is false. If this argument is not specified, it will be set according to the overlay argument in strategy or indicator, if strategy or indicator does not set the overlay argument, it will be processed according to the default arguments.

Remarks Even if one value of open, high, low or close equal NaN, then the bar need no draw. The maximal value of open, high, low or close will be set as “high”, and the minimal value will be set as “low”.

See also


### plotarrow

Plots up and down arrows on the chart. Up arrow is drawn at every indicator positive value, down arrow is drawn at every negative value. If indicator returns na then no arrow is drawn. Arrows has different height, the more absolute indicator value the longer arrow is drawn.

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


**Example**

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


**Arguments**
- ```series``` (series int/float) Series of data to be plotted as arrows. Required argument.
- ```title``` (const string) Title of the plot.
- ```colorup``` (series color) Color of the up arrows. Optional argument.
- ```colordown``` (series color) Color of the down arrows. Optional argument.
- ```offset``` (series int) Shifts arrows to the left or to the right on the given number of bars. Default is 0.
- ```minheight``` (input int) Minimal possible arrow height in pixels. Default is 5.
- ```maxheight``` (input int) Maximum possible arrow height in pixels. Default is 100.
- ```editable``` (const bool) If true then plotarrow style will be editable in Format dialog. Default is true.
- ```show_last``` (input int) If set, defines the number of arrows (from the last bar back to the past) to plot on chart.
- ```display``` (plot_display) Controls where the plot is displayed. Possible values are: display.none, display.all. Default is display.all.
- ```overlay``` (const bool) is the extension argument of FMZ platform, it is used to set the current function to be displayed on the main image (set to true) or sub-image (set to false), the default value is false. If this argument is not specified, it will be set according to the ```overlay``` argument in ```strategy``` or ```indicator```, if ```strategy``` or ```indicator``` does not set the ```overlay``` argument, it will be processed according to the default arguments.

**See also**
```plot``` ```plotshape``` ```plotchar``` ```barcolor``` ```bgcolor```

## array

### array.pop

The function removes the last element from an array and returns its value.

```array.pop(id)```

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

Returns The value of the removed element.

Arguments - id (any array type) An array object.

See also


### array.shift

The function removes an array's first element and returns its value.

```array.shift(id)```

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

Returns The value of the removed element.

Arguments - id (any array type) An array object.

See also


### array.unshift

The function inserts the value at the beginning of the array.

```array.unshift(id, value)```

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

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) The value to add to the start of the array.

See also


### array.size

The function returns the number of elements in an array.

```array.size(id)```

**Example**
```pine
// 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))

Returns The number of elements in the array.

Arguments - id (any array type) An array object.

See also


### array.slice

The function creates a slice from an existing array. If an object from the slice changes, the changes are applied to both the new and the original arrays.

array.slice(id, index_from, index_to)


**Example**
```pine
// 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)

Returns A shallow copy of an array’s slice.

Arguments - id (any array type) An array object. - index_from (series int) Zero-based index at which to begin extraction. - index_to (series int) Zero-based index before which to end extraction. The function extracts up to but not including the element with this index.

See also


### array.abs

Returns an array containing the absolute value of each element in the original array.

array.abs(id)


**Arguments**
- ```id``` (int[]/float[]) An array object.

**See also**
```array.new_float``` ```array.insert``` ```array.slice``` ```array.reverse``` ```order.ascending``` ```order.descending```

### array.binary_search

The function returns the index of the value, or -1 if the value is not found. The array to search must be sorted in ascending order.

array.binary_search(id, val)


**Example**
```pine
// 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)

Arguments - id (int[]/float[]) An array object. - val (series int/float) The value to search for in the array.

Remarks A binary search works on arrays pre-sorted in ascending order. It begins by comparing an element in the middle of the array with the target value. If the element matches the target value, its position in the array is returned. If the element’s value is greater than the target value, the search continues in the lower half of the array. If the element’s value is less than the target value, the search continues in the upper half of the array. By doing this recursively, the algorithm progressively eliminates smaller and smaller portions of the array in which the target value cannot lie.

See also


### array.binary_search_leftmost

The function returns the index of the value if it is found. When the value is not found, the function returns the index of the next smallest element to the left of where the value would lie if it was in the array. The array to search must be sorted in ascending order.

array.binary_search_leftmost(id, val)


**Example**
```pine
// 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)

Arguments - id (int[]/float[]) An array object. - val (series int/float) The value to search for in the array.

Remarks A binary search works on arrays pre-sorted in ascending order. It begins by comparing an element in the middle of the array with the target value. If the element matches the target value, its position in the array is returned. If the element’s value is greater than the target value, the search continues in the lower half of the array. If the element’s value is less than the target value, the search continues in the upper half of the array. By doing this recursively, the algorithm progressively eliminates smaller and smaller portions of the array in which the target value cannot lie.

See also


### array.binary_search_rightmost

The function returns the index of the value if it is found. When the value is not found, the function returns the index of the element to the right of where the value would lie if it was in the array. The array must be sorted in ascending order.

array.binary_search_rightmost(id, val)


**Example**
```pine
// 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)

Arguments - id (int[]/float[]) An array object. - val (series int/float) The value to search for in the array.

Remarks A binary search works on sorted arrays in ascending order. It begins by comparing an element in the middle of the array with the target value. If the element matches the target value, its position in the array is returned. If the element’s value is greater than the target value, the search continues in the lower half of the array. If the element’s value is less than the target value, the search continues in the upper half of the array. By doing this recursively, the algorithm progressively eliminates smaller and smaller portions of the array in which the target value cannot lie.

See also


### array.sort

The function sorts the elements of an array.

array.sort(id, order)


**Example**
```pine
// 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))

Arguments - id (int[]/float[]/string[]) An array object. - order (sort_order) The sort order: order.ascending (default) or order.descending.

See also


### array.sort_indices

Returns an array of indices which, when used to index the original array, will access its elements in their sorted order. It does not modify the original array.

array.sort_indices(id, order)


**Example**
```pine
// 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)

Arguments - id (int[]/float[]/string[]) An array object. - order (sort_order) The sort order: order.ascending or order.descending. Optional. The default is order.ascending.

See also


### array.clear

The function removes all elements from an array.

array.clear(id)


**Example**
```pine
// 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))

Arguments - id (any array type) An array object.

See also


### array.concat

The function is used to merge two arrays. It pushes all elements from the second array to the first array, and returns the first array.

array.concat(id1, id2)


**Example**
```pine
// 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))

Returns The first array with merged elements from the second array.

Arguments - id1 (any array type) The first array object. - id2 (any array type) The second array object.

See also


### array.copy

The function creates a copy of an existing array.

array.copy(id)


**Example**
```pine
// 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)

Returns A copy of an array.

Arguments - id (any array type) An array object.

See also


### array.stdev

The function returns the standard deviation of an array's elements.

array.stdev(id, biased)


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

Returns The standard deviation of the array’s elements.

Arguments - id (int[]/float[]) An array object. - biased (series bool) Determines which estimate should be used. Optional. The default is true.

Remarks If biased is true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.

See also


### array.standardize

The function returns the array of standardized elements.

array.standardize(id)


**Example**
```pine
// 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))

Returns The array of standardized elements.

Arguments - id (int[]/float[]) An array object.

See also


### array.variance

The function returns the variance of an array's elements.

array.variance(id, biased)


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

Returns The variance of the array’s elements.

Arguments - id (int[]/float[]) An array object. - biased (series bool) Determines which estimate should be used. Optional. The default is true.

Remarks If biased is true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.

See also


### array.covariance

The function returns the covariance of two arrays.

array.covariance(id1, id2, biased)


**Example**
```pine
// 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))

Returns The covariance of two arrays.

Arguments - id1 (int[]/float[]) An array object. - id2 (int[]/float[]) An array object. - biased (series bool) Determines which estimate should be used. Optional. The default is true.

Remarks If biased is true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.

See also


### array.fill

The function sets elements of an array to a single value. If no index is specified, all elements are set. If only a start index (default 0) is supplied, the elements starting at that index are set. If both index arguments are used, the elements from the starting index up to but not including the end index (default na) are set.

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


**Example**
```pine
// array.fill example
a = array.new_float(10)
array.fill(a, close)
plot(array.sum(a))

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) Value to fill the array with. - index_from (series int) Start index, default is 0. - index_to (series int) End index, default is na. Must be one greater than the index of the last element to set.

See also


### array.includes

The function returns true if the value was found in an array, false otherwise.

array.includes(id, value)


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

Returns True if the value was found in the array, false otherwise.

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) The value to search in the array.

See also


### array.insert

The function changes the contents of an array by adding new elements in place.

array.insert(id, index, value)


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

Arguments - id (any array type) An array object. - index (series int) The index at which to insert the value. - value (series <type of the array's elements>) The value to add to the array.

See also


### array.join

The function creates and returns a new string by concatenating all the elements of an array, separated by the specified separator string.

array.join(id, separator)


**Example**
```pine
// array.join example
a = array.new_float(5, 5)
runtime.log(array.join(a, ","))

Arguments - id (int[]/float[]/string[]) An array object. - separator (series string) The string used to separate each array element.

See also


### array.lastindexof

The function returns the index of the last occurrence of the value, or -1 if the value is not found.

array.lastindexof(id, value)


**Example**
```pine
// array.lastindexof example
a = array.new_float(5,high)
index = array.lastindexof(a, high)
plot(index)

Returns The index of an element.

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) The value to search in the array.

See also


### array.max

The function returns the greatest value, or the nth greatest value in a given array.

array.max(id, nth)


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

Returns The greatest or the nth greatest value in the array.

Arguments - id (int[]/float[]) An array object. - nth (series int) The nth greatest value to return, where zero is the greatest. Optional. The default is zero.

See also


### array.min

The function returns the smallest value, or the nth smallest value in a given array.

array.min(id, nth)


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

Returns The smallest or the nth smallest value in the array.

Arguments - id (int[]/float[]) An array object. - nth (series int) The nth smallest value to return, where zero is the smallest. Optional. The default is zero.

See also


### array.median

The function returns the median of an array's elements.

array.median(id)


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

Returns The median of the array’s elements.

Arguments - id (int[]/float[]) An array object.

See also


### array.mode

The function returns the mode of an array's elements. If there are several values with the same frequency, it returns the smallest value.

array.mode(id)


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

Returns The mode of the array’s elements.

Arguments - id (int[]/float[]) An array object.

See also


### array.percentile_linear_interpolation

Returns the value for which the specified percentage of array values (percentile) are less than or equal to it, using linear interpolation.

array.percentile_linear_interpolation(id, percentage)


**Arguments**
- ```id``` (int[]/float[]) An array object.
- ```percentage``` (series int/float) The percentage of values that must be equal or less than the returned value.

**Remarks**
In statistics, the percentile is the percent of ranking items that appear at or below a certain score. This measurement shows the percentage of scores within a standard frequency distribution that is lower than the percentile rank you're measuring. Linear interpolation estimates the value between two ranks.

**See also**
```array.new_float``` ```array.insert``` ```array.slice``` ```array.reverse``` ```order.ascending``` ```order.descending```

### array.percentile_nearest_rank

Returns the value for which the specified percentage of array values (percentile) are less than or equal to it, using the nearest-rank method.

array.percentile_nearest_rank(id, percentage)


**Arguments**
- ```id``` (int[]/float[]) An array object.
- ```percentage``` (series int/float) The percentage of values that must be equal or less than the returned value.

**Remarks**
In statistics, the percentile is the percent of ranking items that appear at or below a certain score. This measurement shows the percentage of scores within a standard frequency distribution that is lower than the percentile rank you're measuring.

**See also**
```array.new_float``` ```array.insert``` ```array.slice``` ```array.reverse``` ```order.ascending``` ```order.descending```

### array.percentrank

Returns the percentile rank of a value in the array.

array.percentrank(id, index)


**Arguments**
- ```id``` (int[]/float[]) An array object.
- ```index``` (series int) The value for which to calculate its percentile rank.

**Remarks**
Percentile rank is the percentage of how many elements in the array are less than or equal to the reference value.

**See also**
```array.new_float``` ```array.insert``` ```array.slice``` ```array.reverse``` ```order.ascending``` ```order.descending```

### array.range

The function returns the difference between the min and max values from a given array.

array.range(id)


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

Returns The difference between the min and max values in the array.

Arguments - id (int[]/float[]) An array object.

See also


### array.remove

The function changes the contents of an array by removing the element with the specified index.

```array.remove(id, index)```

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

Returns The value of the removed element.

Arguments - id (any array type) An array object. - index (series int) The index of the element to remove.

See also


### array.reverse

The function reverses an array. The first array element becomes the last, and the last array element becomes the first.

array.reverse(id)


**Example**
```pine
// 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))

Arguments - id (any array type) An array object.

See also


### array.from

The function takes a variable number of arguments with one of the types: int, float, bool, string, label, line, color, box, table, linefill, and returns an array of the corresponding type.

array.from(arg0, arg1, …)


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

Returns The array element’s value.

Arguments - arg0, arg1, ... (series int/float/bool/color/string/line/linefill) Array arguments.

array.new

The function creates a new array object of <type> elements.

array.new(size, initial_value)

Example

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

Example

// 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))

Example

// 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")

Example

// 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)

Returns The ID of an array object which may be used in other array.*() functions.

Arguments - size (series int) Initial size of an array. Optional. The default is 0. - initial_value (series &lt;type&gt;) Initial value of all array elements. Optional. The default is “na”.

Remarks An array index starts from 0. If you want to initialize an array and specify all its elements at the same time, then use the function array.from.

See also


### array.new_bool

The function creates a new array object of bool type elements.

array.new_bool(size, initial_value)


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

Returns The ID of an array object which may be used in other array.*() functions.

Arguments - size (series int) Initial size of an array. Optional. The default is 0. - initial_value (series bool) Initial value of all array elements. Optional. The default is “na”.

Remarks The array index starts at 0.

See also


### array.new_float

The function creates a new array object of float type elements.

array.new_float(size, initial_value)


**Example**
```pine
// array.new_float example
length = 5
a = array.new_float(length, close)
plot(array.sum(a) / length)

Returns The ID of an array object which may be used in other array.*() functions.

Arguments - size (series int) Initial size of an array. Optional. The default is 0. - initial_value (series int/float) Initial value of all array elements. Optional. The default is “na”.

Remarks An array index starts from 0.

See also


### array.new_int

The function creates a new array object of int type elements.

array.new_int(size, initial_value)


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

Returns The ID of an array object which may be used in other array.*() functions.

Arguments - size (series int) Initial size of an array. Optional. The default is 0. - initial_value (series int) Initial value of all array elements. Optional. The default is “na”.

Remarks An array index starts from 0.

See also


### array.new_string

The function creates a new array object of string type elements.

array.new_string(size, initial_value)


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

Returns The ID of an array object which may be used in other array.*() functions.

Arguments - size (series int) Initial size of an array. Optional. The default is 0. - initial_value (series string) Initial value of all array elements. Optional. The default is “na”.

Remarks An array index starts from 0.

See also


### array.get

The function returns the value of the element at the specified index.

```array.get(id, index)```

**Example**
```pine
// 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))

Returns The array element’s value.

Arguments - id (any array type) An array object. - index (series int) The index of the element whose value is to be returned.

See also


### array.push

The function appends a value to an array.

array.push(id, value)


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

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) The value of the element added to the end of the array.

See also


### array.set

The function sets the value of the element at the specified index.

array.set(id, index, value)


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

Arguments - id (any array type) An array object. - index (series int) The index of the element to be modified. - value (series <type of the array's elements>) The new value to be set.

See also


### array.sum

The function returns the sum of an array's elements.

array.sum(id)


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

Returns The sum of the array’s elements.

Arguments - id (int[]/float[]) An array object.

See also


### array.avg

The function returns the mean of an array's elements.

array.avg(id)


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

Returns Mean of array’s elements.

Arguments - id (int[]/float[]) An array object.

See also


### array.indexof

The function returns the index of the first occurrence of the value, or -1 if the value is not found.

array.indexof(id, value)


**Example**
```pine
// array.indexof example
a = array.new_float(5,high)
index = array.indexof(a, high)
plot(index)

Returns The index of an element.

Arguments - id (any array type) An array object. - value (series <type of the array's elements>) The value to search in the array.

See also


## strategy

In the built-in functions related to ```strategy```, the stop loss points and take profit points are defined as multiples of one price jump. For example, the ```profit``` and ```loss``` arguments of the ```strategy.exit``` function represent stop loss and take profit in points, and the argument ```profit``` is set to 10, that is the price jump is multiplied by 10 as the take profit spread, and the price jump is the built-in variable ```syminfo.mintick```.

### strategy

The function sets a number of strategy properties.
Note that only ```title```, ```shorttitle```, ```overlay```, ```pyramiding```, ```default_qty_type```, ```default_qty_value``` arguments are supported for passing arguments. Other arguments can be set through the interface arguments of the PINE language strategy.

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)


**Example**
```pine
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)

Arguments - title (const string) indicator title that would be seen in Indicators/Strategies widget. Argument IS REQUIRED. - shorttitle (const string) indicator short title that would be seen in the chart legend. Argument is optional. - overlay (const bool) if true the indicator will be added as an overlay for the main series. If false - it would be added on a separate chart pane. Default is false. - format (const string) type of formatting indicator values on the price axis. Possible values are: format.inherit, format.price, format.volume. Default is format.inherit. - precision (const int) number of digits after the floating point for indicator values on the price axis. Must be a non negative integer and not greater than 16. If omitted, using formatting from parent series. If format is format.inherit and this argument is set, then format becomes format.price. - scale (scale_type) price scale that the indicator should be attached to. Possible values are: scale.right, scale.left, scale.none. Value scale.none can be applied only in combination with ‘overlay=true’ setting. - pyramiding (const int) The maximum number of entries allowed in the same direction. If the value is 0, only one entry order in the same direction can be opened, and additional entry orders are rejected. The default value is 0. - calc_on_order_fills (const bool) Additional one time intrabar order calculation. If the argument is set to “true”, then the strategy is recalculated once intrabar after an order is filled (not only at close of the bar). The default value is “false”. - calc_on_every_tick (const bool) Additional intrabar strategy calculations. If the argument is “true”, then the strategy will calculate on every tick in real-time, rather than on bars’ closes. The argument does not affect strategy calculation on historical data. The default value is “false”. - max_bars_back (const int) Maximum number of bars available for a strategy for historical reference. This argument is applied to every built-in or user variable in the script if there is a reference to historical data of a variable in the script code (‘[]’ operator is used). Variable buffer sizes in the Pine Script are typically autodetected. This however is not possible in certain cases which is why the argument allows a user to manually set the lower bound of this value. NOTE: using of the max_bars_back function instead of the argument is optimal because it applies to only one variable. - backtest_fill_limits_assumption (const int) Limit order execution assumption. Limit orders are filled intrabar only if market price exceeds the limit order level by the specified number of ticks. - default_qty_type (const string) Determines what the value used for the qty argument represents in strategy.entry or strategy.order functions. Possible values are: strategy.fixed for contracts/shares/lots, strategy.cash for amounts in currency, or strategy.percent_of_equity for a percentage of the available equity. - default_qty_value (const int/float) The default quantity to trade in strategy.entry or strategy.order functions when their ‘qty’ argument is not defined, in units determined by the argument used with the ‘default_qty_type’ argument. - currency (const string) Account currency for this strategy. Optional. The default is the currency that the symbol on the chart is traded on. Possible values: 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) Slippage in ticks to be added to/subtracted from the fill price of buy/sell market or stop orders. If mintick=0.01 and slippage=5, the amount of slippage will be 50.01=0.05. - commission_type (const string) Commission type for an order. The allowed values are: strategy.commission.percent (a percentage of the cash volume of order), strategy.commission.cash_per_contract (money displayed in the account currency per contract), strategy.commission.cash_per_order (money displayed in the account currency per order). - commission_value (const int/float) Commission value for an order. Depending on the type selected (commission_type) includes percentage or money. - process_orders_on_close (const bool) When set to true, generates an additional attempt to execute orders after a bar closes and strategy calculations are completed. If the orders are market orders, the broker emulator executes them before the next bar’s open. If the orders are conditional on price, they will only be filled if the price conditions are met. This option is useful if you wish to close positions on the current bar. The default value is ‘false’. - close_entries_rule (const string) Determines the order in which orders are closed. Allowed values are: ‘FIFO’ or ‘ANY’. FIFO (First-In, First-Out) means that when several trades are open, the earliest trades must be closed first. This rule applies to stocks, futures and US forex (NFA Compliance Rule 2-43b). ‘ANY’ means that trades may be closed in any order; this is allowed in non-US forex. The default value is ‘FIFO’. - max_lines_count (const int) The number of last line drawings displayed. The default value is 50 and the maximum allowed is 500. - max_labels_count (const int) The number of last label drawings displayed. The default value is 50 and the maximum allowed is 500. - max_boxes_count (const int) The number of last box drawings displayed. The default value is 50 and the maximum allowed is 500. - margin_long (const int/float) Margin long is the percentage of the purchase price of a security that must be covered by cash or collateral for long positions. Must be a non-negative number. Optional. The default is 100. -~~ margin_short~~ (const int/float) Margin short is the percentage of the purchase price of a security that must be covered by cash or collateral for short positions. Must be a non-negative number. Optional. The default is 100. - explicit_plot_zorder (const bool) Specifies the order in which the indicator’s plots, fills, and hlines are rendered. If true, the plots will be drawn based on the order in which they appear in the indicator’s code, each newer plot being drawn above the previous ones. This only applies to plot() functions, fill, and hline. Optional. The default is false. - initial_capital (const int/float) The amount of funds initially available for the strategy to trade, in the currency defined in currency. Optional. The default is 1000000. - risk_free_rate (const int/float) The risk-free rate of return is the annual percentage change in the value of an investment with minimal or zero risk, used to calculate the Sharpe and Sortino ratios. The default value is 2.

Remarks Every strategy script must have one strategy call. Pine Script code that uses argument calc_on_every_tick = true could calculate differently on history and real-time data. When using non-standard types of chart as a basis for strategy, you need to realize that the result will be different. The orders will be executed at the prices of this chart (e.g.for Heikin Ashi it’ll take Heikin Ashi prices (the average ones) not the real market prices). Therefore we highly recommend you to use standard chart type for strategies.

See also


### strategy.entry

It is a command to enter market position. If an order with the same ID is already pending, it is possible to modify the order. If there is no order with the specified ID, a new order is placed. To deactivate an entry order, the command strategy.cancel or strategy.cancel_all should be used. In comparison to the function strategy.order, the function strategy.entry is affected by pyramiding and it can reverse market position correctly. If both 'limit' and 'stop' arguments are 'NaN', the order type is market order.

strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, when, alert_message)


**Example**
```pine
strategy(title = "simple strategy entry example")
strategy.entry("enter long", strategy.long, 1, when = open > high[1]) // enter long by market if current open great then previous high
strategy.entry("enter short", strategy.short, 1, when = open < low[1]) // enter short by market if current open less then previous low

Arguments - id (series string) A required argument. The order identifier. It is possible to cancel or modify an order by referencing its identifier. - direction (strategy_direction) A required argument. Market position direction: ‘strategy.long’ is for long, ‘strategy.short’ is for short. - qty (series int/float) An optional argument. Number of contracts/shares/lots/units to trade. The default value is ‘NaN’. - limit (series int/float) An optional argument. Limit price of the order. If it is specified, the order type is either ‘limit’, or ‘stop-limit’. ‘NaN’ should be specified for any other order type. - stop (series int/float) An optional argument. Stop price of the order. If it is specified, the order type is either ‘stop’, or ‘stop-limit’. ‘NaN’ should be specified for any other order type. - oca_name (series string) An optional argument. Name of the OCA group the order belongs to. If the order should not belong to any particular OCA group, there should be an empty string. Note that FMZ does not support this argument.~~ - oca_type (input string) An optional argument. Type of the OCA group. The allowed values are: strategy.oca.none - the order should not belong to any particular OCA group; strategy.oca.cancel - the order should belong to an OCA group, where as soon as an order is filled, all other orders of the same group are cancelled; strategy.oca.reduce - the order should belong to an OCA group, where if X number of contracts of an order is filled, number of contracts for each other order of the same OCA group is decreased by X. Note that FMZ does not support this argument. - comment (series string) An optional argument. Additional notes on the order. - when (series bool) An optional argument. Condition of the order. The order is placed if condition is ‘true’. If condition is ‘false’, nothing happens (the previously placed order with the same ID is not cancelled). Default value is ‘true’. - alert_message (series string) An optional argument which replaces the {{strategy.order.alert_message}} placeholder when it is used in the “Create Alert” dialog box’s “Message” field.

strategy.close

It is a command to exit from the entry with the specified ID. If there were multiple entry orders with the same ID, all of them are exited at once. If there are no open entries with the specified ID by the moment the command is triggered, the command will not come into effect. The command uses market order. Every entry is closed by a separate market order.

strategy.close(id, when, comment, qty, qty_percent, alert_message) 

Example

strategy("closeEntry Demo", overlay=false)
strategy.entry("buy", strategy.long, when = open > close)
strategy.close("buy", when = open < close, qty_percent = 50, comment = "close buy entry for 50%")
plot(strategy.position_size)

Arguments - id (series string) A required argument. The order identifier. It is possible to close an order by referencing its identifier. - when (series bool) An optional argument. Condition of the command. - qty (series int/float) An optional argument. Number of contracts/shares/lots/units to exit a trade with. The default value is ‘NaN’. - qty_percent (series int/float) Defines the percentage (0-100) of the position to close. Its priority is lower than that of the ‘qty’ argument. Optional. The default is 100. - comment (series string) An optional argument. Additional notes on the order. - alert_message (series string) An optional argument which replaces the {{strategy.order.alert_message}} placeholder when it is used in the “Create Alert” dialog box’s “Message” field.

strategy.close_all

Exits the current market position, making it flat.

` strategy.close_all(when, comment, alert_message)

相关推荐
全部留言
avatar of 乞丐
乞丐
为何策略广场复制的pine策略无法实盘
2022-05-07 11:06:48
avatar of 发明者量化-小小梦
发明者量化-小小梦
好的,我们检查下。
2022-05-07 19:51:17
avatar of 乞丐
乞丐
张超大佬的Optimized Trend Tracker
2022-05-07 14:22:43
avatar of 发明者量化-小小梦
发明者量化-小小梦
您好,请问具体是哪个策略呢?
2022-05-07 11:13:23