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
The function removes the last element from an array and returns its value.
array.pop(id)
Example
// 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.new_float
array.set
array.push
array.remove
array.insert
array.shift
The function removes an array’s first element and returns its value.
array.shift(id)
Example
// 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
array.set
array.push
array.remove
array.includes
The function inserts the value at the beginning of the array.
array.unshift(id, value)
Example
// 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.shift
array.set
array.insert
array.remove
array.indexof
The function returns the number of elements in an array.
array.size(id)
Example
// 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.new_float
array.sum
array.slice
array.sort
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
// 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.new_float
array.get
array.sort
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
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
// 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.new_float
array.insert
array.slice
array.reverse
order.ascending
order.descending
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
// 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.new_float
array.insert
array.slice
array.reverse
order.ascending
order.descending
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
// 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.new_float
array.insert
array.slice
array.reverse
order.ascending
order.descending
The function sorts the elements of an array.
array.sort(id, order)
Example
// 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.new_float
array.insert
array.slice
array.reverse
order.ascending
order.descending
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
// 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.new_float
array.insert
array.slice
array.reverse
order.ascending
order.descending
The function removes all elements from an array.
array.clear(id)
Example
// 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.new_float
array.insert
array.push
array.remove
array.pop
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
// 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.new_float
array.insert
array.slice
The function creates a copy of an existing array.
array.copy(id)
Example
// 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.new_float
array.get
array.slice
array.sort
The function returns the standard deviation of an array’s elements.
array.stdev(id, biased)
Example
// 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.new_float
array.max
array.min
array.avg
The function returns the array of standardized elements.
array.standardize(id)
Example
// 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.max
array.min
array.mode
array.avg
array.variance
array.stdev
The function returns the variance of an array’s elements.
array.variance(id, biased)
Example
// 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.new_float
array.stdev
array.min
array.avg
array.covariance
The function returns the covariance of two arrays.
array.covariance(id1, id2, biased)
Example
// 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.new_float
array.max
array.stdev
array.avg
array.variance
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
// 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.new_float
array.set
array.slice
The function returns true if the value was found in an array, false otherwise.
array.includes(id, value)
Example
// 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.new_float
array.indexof
array.shift
array.remove
array.insert
The function changes the contents of an array by adding new elements in place.
array.insert(id, index, value)
Example
// 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.new_float
array.set
array.push
array.remove
array.pop
array.unshift
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
// 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.new_float
array.set
array.insert
array.remove
array.pop
array.unshift
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
// 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.new_float
array.set
array.push
array.remove
array.insert
The function returns the greatest value, or the nth greatest value in a given array.
array.max(id, nth)
Example
// 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.new_float
array.min
array.sum
The function returns the smallest value, or the nth smallest value in a given array.
array.min(id, nth)
Example
// 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.new_float
array.max
array.sum
The function returns the median of an array’s elements.
array.median(id)
Example
// 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.avg
array.variance
array.min
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
// 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.new_float
array.avg
array.variance
array.min
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
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
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
The function returns the difference between the min and max values from a given array.
array.range(id)
Example
// 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.new_float
array.min
array.max
array.sum
The function changes the contents of an array by removing the element with the specified index.
array.remove(id, index)
Example
// 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.new_float
array.set
array.push
array.insert
array.pop
array.shift
The function reverses an array. The first array element becomes the last, and the last array element becomes the first.
array.reverse(id)
Example
// 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.new_float
array.sort
array.push
array.set
array.avg
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
// 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.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 <type>) 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.from
array.push
array.get
array.size
array.remove
array.shift
array.sum
The function creates a new array object of bool type elements.
array.new_bool(size, initial_value)
Example
// 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
array.get
array.slice
array.sort
The function creates a new array object of float type elements.
array.new_float(size, initial_value)
Example
// 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_bool
array.get
array.slice
array.sort
The function creates a new array object of int type elements.
array.new_int(size, initial_value)
Example
// 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_float
array.get
array.slice
array.sort
The function creates a new array object of string type elements.
array.new_string(size, initial_value)
Example
// 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.new_float
array.get
array.slice
The function returns the value of the element at the specified index.
array.get(id, index)
Example
// 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.new_float
array.set
array.slice
array.sort
The function appends a value to an array.
array.push(id, value)
Example
// 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.new_float
array.set
array.insert
array.remove
array.pop
array.unshift
The function sets the value of the element at the specified index.
array.set(id, index, value)
Example
// 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.new_float
array.get
array.slice
The function returns the sum of an array’s elements.
array.sum(id)
Example
// 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.new_float
array.max
array.min
The function returns the mean of an array’s elements.
array.avg(id)
Example
// 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.new_float
array.max
array.min
array.stdev
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
// 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
array.lastindexof
array.get
array.lastindexof
array.remove
array.insert
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
.
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
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
precision
scale
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
max_bars_back
backtest_fill_limits_assumption
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
slippage
commission_type
commission_value
process_orders_on_close
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
max_lines_count
max_labels_count
max_boxes_count
margin_long
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
false
.initial_capital
currency
. Optional. The default is 1000000.risk_free_rate
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
indicator
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
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
oca_type
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.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.Exits the current market position, making it flat.
strategy.close_all(when, comment, alert_message)
Example
strategy("closeAll Demo", overlay=false)
strategy.entry("buy", strategy.long, when = open > close)
strategy.close_all(when = open < close, comment = "close all entries")
plot(strategy.position_size)
Arguments
when
(series bool) An optional argument. Condition of the command.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.It is a command to exit either a specific entry, or whole market position. If an order with the same ID is already pending, it is possible to modify the order. If an entry order was not filled, but an exit order is generated, the exit order will wait till entry order is filled and then the exit order is placed. To deactivate an exit order, the command strategy.cancel or strategy.cancel_all should be used. If the function strategy.exit is called once, it exits a position only once. If you want to exit multiple times, the command strategy.exit should be called multiple times. If you use a stop loss and a trailing stop, their order type is ‘stop’, so only one of them is placed (the one that is supposed to be filled first). If all the following arguments ‘profit’, ‘limit’, ‘loss’, ‘stop’, ‘trail_points’, ‘trail_offset’ are ‘NaN’, the command will fail. To use market order to exit, the command strategy.close or strategy.close_all should be used.
strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, when, alert_message)
Example
strategy(title = "simple strategy exit example")
strategy.entry("long", strategy.long, 1, when = open > high[1]) // enter long by market if current open great then previous high
strategy.exit("exit", "long", profit = 10, loss = 5) // generate full exit bracket (profit 10 points, loss 5 points per contract) from entry with name "long"
Arguments
id
(series string) A required argument. The order identifier. It is possible to cancel or modify an order by referencing its identifier.from_entry
(series string) An optional argument. The identifier of a specific entry order to exit from it. To exit all entries an empty string should be used. The default values is empty string.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 of (0-100) the position to close. Its priority is lower than that of the ‘qty’ argument. Optional. The default is 100.profit
(series int/float) An optional argument. Profit target (specified in ticks). If it is specified, a limit order is placed to exit market position when the specified amount of profit (in ticks) is reached. The default value is ‘NaN’.limit
(series int/float) An optional argument. Profit target (requires a specific price). If it is specified, a limit order is placed to exit market position at the specified price (or better). Priority of the argument ‘limit’ is higher than priority of the argument ‘profit’ (‘limit’ is used instead of ‘profit’, if its value is not ‘NaN’). The default value is ‘NaN’.loss
(series int/float) An optional argument. Stop loss (specified in ticks). If it is specified, a stop order is placed to exit market position when the specified amount of loss (in ticks) is reached. The default value is ‘NaN’.stop
(series int/float) An optional argument. Stop loss (requires a specific price). If it is specified, a stop order is placed to exit market position at the specified price (or worse). Priority of the argument ‘stop’ is higher than priority of the argument ‘loss’ (‘stop’ is used instead of ‘loss’, if its value is not ‘NaN’). The defaulThe BeggarWhy the strategy of the square replica of the strategy of the pine can not be realized
Inventors quantify - small dreamsWell, let's have a look.
The BeggarChang's Optimized Trend Tracker is a great tool.
Inventors quantify - small dreamsHello, what exactly is the strategy?