k (length).
percentage
(simple int/float) Percentage, a number from range 0…100.Remarks Using the Nearest Rank method on lengths less than 100 bars back can result in the same number being used for more than one percentile. A percentile calculated using the Nearest Rank method will always be a member of the input data set. The 100th percentile is defined to be the largest value in the input data set.
See also
ta.percentile_linear_interpolation
Percent rank is the percents of how many previous values was less than or equal to the current value of given series.
ta.percentrank(source, length)
Returns
Percent rank of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Variance is the expectation of the squared deviation of a series from its mean (ta.sma), and it informally measures how far a set of numbers are spread out from their mean.
ta.variance(source, length, biased)
Returns
Variance of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).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
ta.dev
ta.stdev
ta.tr(handle_na)
Returns True range. It is math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1])).
Arguments
handle_na
(simple bool) How NaN values are handled. if true, and previous day’s close is NaN then tr would be calculated as current day high-low. Otherwise (if false) tr would return NaN in such cases. Also note, that ta.atr uses ta.tr(true).Remarks
ta.tr(false)
is exactly the same as ta.tr
.
See also
ta.atr
Money Flow Index. The Money Flow Index (MFI) is a technical oscillator that uses price and volume for identifying overbought or oversold conditions in an asset.
ta.mfi(series, length)
Example
plot(ta.mfi(hlc3, 14), color=color.yellow)
// the same on pine
pine_mfi(src, length) =>
float upper = math.sum(volume * (ta.change(src) <= 0.0 ? 0.0 : src), length)
float lower = math.sum(volume * (ta.change(src) >= 0.0 ? 0.0 : src), length)
mfi = 100.0 - (100.0 / (1.0 + upper / lower))
mfi
plot(pine_mfi(hlc3, 14))
Returns Money Flow Index.
Arguments
series
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.rsi
math.sum
Keltner Channels. Keltner channel is a technical analysis indicator showing a central moving average line plus channel lines at a distance above and below.
ta.kc(series, length, mult)
ta.kc(series, length, mult, useTrueRange)
Example
[middle, upper, lower] = ta.kc(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
// the same on pine
f_kc(src, length, mult, useTrueRange) =>
float basis = ta.ema(src, length)
float span = (useTrueRange) ? ta.tr : (high - low)
float rangeEma = ta.ema(span, length)
[basis, basis + rangeEma * mult, basis - rangeEma * mult]
[pineMiddle, pineUpper, pineLower] = f_kc(close, 5, 4, true)
plot(pineMiddle)
plot(pineUpper)
plot(pineLower)
Returns Keltner Channels.
Arguments
series
(series int/float) Series of values to process.length
(simple int) Number of bars (length).mult
(simple int/float) Standard deviation factor.useTrueRange
(simple bool) An optional argument. Specifies if True Range is used; default is true. If the value is false, the range will be calculated with the expression (high - low).See also
ta.ema
ta.atr
ta.bb
Keltner Channels Width. The Keltner Channels Width is the difference between the upper and the lower Keltner Channels divided by the middle channel.
ta.kcw(series, length, mult)
ta.kcw(series, length, mult, useTrueRange)
Example
plot(ta.kcw(close, 5, 4), color=color.yellow)
// the same on pine
f_kcw(src, length, mult, useTrueRange) =>
float basis = ta.ema(src, length)
float span = (useTrueRange) ? ta.tr : (high - low)
float rangeEma = ta.ema(span, length)
((basis + rangeEma * mult) - (basis - rangeEma * mult)) / basis
plot(f_kcw(close, 5, 4, true))
Returns Keltner Channels Width.
Arguments
series
(series int/float) Series of values to process.length
(simple int) Number of bars (length).mult
(simple int/float) Standard deviation factor.useTrueRange
(simple bool) An optional argument. Specifies if True Range is used; default is true. If the value is false, the range will be calculated with the expression (high - low).See also
ta.kc
ta.ema
ta.atr
ta.bb
Correlation coefficient. Describes the degree to which two series tend to deviate from their ta.sma values.
ta.correlation(source1, source2, length)
Returns Correlation coefficient.
Arguments
source1
(series int/float) Source series.source2
(series int/float) Target series.length
(series int) Length (number of bars back).See also
request.security
ta.cross(source1, source2)
Returns true if two series have crossed each other, otherwise false.
Arguments
source1
(series int/float) First data series.source2
(series int/float) Second data series.See also
ta.change
The source1
-series is defined as having crossed over source2
-series if, on the current bar, the value of source1
is greater than the value of source2
, and on the previous bar, the value of source1
was less than the value of source2
.
ta.crossover(source1, source2)
Returns
true if source1
crossed over source2
otherwise false.
Arguments
source1
(series int/float) First data series.source2
(series int/float) Second data series.The source1
-series is defined as having crossed under source2
-series if, on the current bar, the value of source1
is less than the value of source2
, and on the previous bar, the value of source1
was greater than the value of source2
.
ta.crossunder(source1, source2)
Returns
true if source1
crossed under source2
otherwise false.
Arguments
source1
(series int/float) First data series.source2
(series int/float) Second data series.Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close[1]), abs(low - close[1])).
ta.atr(length)
Example
plot(ta.atr(14))
//the same on pine
pine_atr(length) =>
trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
//true range can be also calculated with ta.tr(true)
ta.rma(trueRange, length)
plot(pine_atr(14))
Returns Average true range. (ATR)
Arguments length (simple int) Length (number of bars back).
See also
ta.tr
ta.rma
Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find potential reversals in the market price direction of traded goods.
ta.sar(start, inc, max)
Example
plot(ta.sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)
// The same on Pine
pine_sar(start, inc, max) =>
var float result = na
var float maxMin = na
var float acceleration = na
var bool isBelow = na
bool isFirstTrendBar = false
if bar_index == 1
if close > close[1]
isBelow := true
maxMin := high
result := low[1]
else
isBelow := false
maxMin := low
result := high[1]
isFirstTrendBar := true
acceleration := start
result := result + acceleration * (maxMin - result)
if isBelow
if result > low
isFirstTrendBar := true
isBelow := false
result := math.max(high, maxMin)
maxMin := low
acceleration := start
else
if result < high
isFirstTrendBar := true
isBelow := true
result := math.min(low, maxMin)
maxMin := high
acceleration := start
if not isFirstTrendBar
if isBelow
if high > maxMin
maxMin := high
acceleration := math.min(acceleration + inc, max)
else
if low < maxMin
maxMin := low
acceleration := math.min(acceleration + inc, max)
if isBelow
result := math.min(result, low[1])
if bar_index > 1
result := math.min(result, low[2])
else
result := math.max(result, high[1])
if bar_index > 1
result := math.max(result, high[2])
result
plot(pine_sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)
Returns Parabolic SAR.
Arguments
start
(simple int/float) Start.inc
(simple int/float) Increment.max
(simple int/float) Maximum.Counts the number of bars since the last time the condition was true.
ta.barssince(condition)
Example
// get number of bars since last color.green bar
plot(ta.barssince(close >= open))
Returns Number of bars since condition was true.
Remarks If the condition has never been met prior to the current bar, the function returns na. Please note that using this variable/function can cause indicator repainting.
See also
ta.lowestbars
ta.highestbars
ta.valuewhen
ta.highest
ta.lowest
Cumulative (total) sum of source
. In other words it’s a sum of all elements of source
.
ta.cum(source)
Returns Total sum series.
Arguments
source
(series int/float)See also
math.sum
The dmi function returns the directional movement index(DMI).
ta.dmi(diLength, adxSmoothing)
Example
len = input.int(17, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(len, lensig)
plot(adx, color=color.red, title="ADX")
plot(diplus, color=color.blue, title="+DI")
plot(diminus, color=color.orange, title="-DI")
Returns Tuple of three DMI series: Positive Directional Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).
Arguments
diLength
(simple int) DI Period.adxSmoothing
(simple int) ADX Smoothing Period.See also
ta.rsi
ta.tsi
ta.mfi
Test if the source
series is now falling for length
bars long.
ta.falling(source, length)
Returns
true if current source
value is less than any previous source
value for length
bars back, false otherwise.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.rising
Test if the source
series is now rising for length
bars long.
ta.rising(source, length)
Returns
true if current source
is greater than any previous source
for length
bars back, false otherwise.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.falling
This function returns price of the pivot high point. It returns ‘NaN’, if there was no pivot high point.
ta.pivothigh(source, leftbars, rightbars)
ta.pivothigh(leftbars, rightbars)
Example
leftBars = input(2)
rightBars=input(2)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_cross, linewidth=3, color= color.red, offset=-rightBars)
Returns Price of the point or ‘NaN’.
Arguments
source
(series int/float) An optional argument. Data series to calculate the value. ‘High’ by default.leftbars
(series int/float) Left strength.rightbars
(series int/float) Right length.Remarks If arguments ‘leftbars’ or ‘rightbars’ are series you should use max_bars_back function for the ‘source’ variable.
This function returns price of the pivot low point. It returns ‘NaN’, if there was no pivot low point.
ta.pivotlow(source, leftbars, rightbars)
ta.pivotlow(leftbars, rightbars)
Example
leftBars = input(2)
rightBars=input(2)
pl = ta.pivotlow(close, leftBars, rightBars)
plot(pl, style=plot.style_cross, linewidth=3, color= color.blue, offset=-rightBars)
Returns Price of the point or ‘NaN’.
Arguments
source
(series int/float) An optional argument. Data series to calculate the value. “Low” by default.leftbars
(series int/float) Left strength.rightbars
(series int/float) Right length.Remarks If arguments ‘leftbars’ or ‘rightbars’ are series you should use max_bars_back function for the ‘source’ variable.
Highest value for a given number of bars back.
ta.highest(source, length)
ta.highest(length)
Returns Highest value in the series.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Remarks
Two args version: source
is a series and length
is the number of bars back.
One arg version: length
is the number of bars back. Algorithm uses high as a source
series.
See also
ta.lowest
ta.lowestbars
ta.highestbars
ta.valuewhen
ta.barssince
Highest value offset for a given number of bars back.
ta.highestbars(source, length)
ta.highestbars(length)
Returns Offset to the highest bar.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Remarks
Two args version: source
is a series and length
is the number of bars back.
One arg version: length
is the number of bars back. Algorithm uses high as a source
series.
See also
ta.lowest
ta.highest
ta.lowestbars
ta.barssince
ta.valuewhen
Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length)).
ta.stoch(source, high, low, length)
Returns Stochastic.
Arguments
source
(series int/float) Source series.high
(series int/float) Series of high.low
(series int/float) Series of low.length
(series int) Length (number of bars back).See also
ta.cog
The Supertrend Indicator. The Supertrend is a trend following indicator.
ta.supertrend(factor, atrPeriod)
Example
//@version=5
indicator("Pine Script™ Supertrend")
[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 Script™
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)
Returns Tuple of two supertrend series: supertrend line and direction of trend. Possible values are 1 (down direction) and -1 (up direction).
Arguments
factor
(series int/float) The multiplier by which the ATR will get multiplied.atrPeriod
(simple int) Length of ATRSee also
ta.macd
Lowest value for a given number of bars back.
ta.lowest(source, length)
ta.lowest(length)
Returns Lowest value in the series.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).Remarks
Two args version: source
is a series and length
is the number of bars back.
One arg version: length
is the number of bars back. Algorithm uses low as a source
series.
See also
ta.highest
ta.lowestbars
ta.highestbars
ta.valuewhen
ta.barssince
Lowest value offset for a given number of bars back.
ta.lowestbars(source, length)
ta.lowestbars(length)
Returns Offset to the lowest bar.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars back.Remarks
Two args version: source
is a series and length
is the number of bars back.
One arg version: length
is the number of bars back. Algorithm uses low as a source
series.
See also
ta.lowest
ta.highest
ta.highestbars
ta.barssince
ta.valuewhen
Returns the value of the “source” series on the bar where the “condition” was true on the nth most recent occurrence.
ta.valuewhen(condition, source, occurrence)
Example
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))
Arguments
condition
(series bool) The condition to search for.source
(series int/float/bool/color) The value to be returned from the bar where the condition is met.occurrence
(simple int) The occurrence of the condition. The numbering starts from 0 and goes back in time, so “0” is the most recent occurrence of “condition”, “1” is the second most recent and so forth. Must be an integer >= 0.Remarks This function requires execution on every bar. It is not recommended to use it inside a for or while loop structure, where its behavior can be unexpected. Please note that using this function can cause indicator repainting.
See also
ta.lowestbars
ta.highestbars
ta.barssince
ta.highest
ta.lowest
Volume weighted average price.
ta.vwap(source)
Returns Volume weighted average.
Arguments
source
(series int/float) Source series.See also
ta.vwap
The vwma function returns volume-weighted moving average of source
for length
bars back. It is the same as: sma(source * volume, length) / sma(volume, length).
ta.vwma(source, length)
Example
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))
Returns
Volume-weighted moving average of source
for length
bars back.
Arguments
source
(series int/float) Series of values to process.length
(series int) Number of bars (length).See also
ta.sma
ta.ema
ta.rma
ta.wma
ta.swma
ta.alma
Williams %R. The oscillator shows the current closing price in relation to the high and low of the past “period of time” bars.
ta.wpr(length)
Example
plot(ta.wpr(14), title="%R", color=color.new(#ff6d00, 0))
Returns Williams %R.
Arguments
length
(series int) Number of bars.See also
ta.mfi
ta.cmo
Plots a series of data on the chart.
plot(series, title, color, linewidth, style, trackprice, histbase, offset, join, editable, show_last, display)
Example
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))
Returns A plot object, that can be used in fill.
Arguments
series
(series int/float) Series of data to be plotted. Required argument.title
(const string) Title of the plot.color
(series color) Color of the plot. 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.linewidth
(input int) Width of the plotted line. Default value is 1. Not applicable to every style.style
(plot_style) Type of plot. Possible values are: 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. Default value is plot.style_line.trackprice
(input bool) If true then a horizontal price line will be shown at the level of the last indicator value. Default is false.histbase
(input int/float) The price value used as the reference level when rendering plot with plot.style_histogram, plot.style_columns or plot.style_area style. Default is 0.0.offset
(series int) Shifts the plot to the left or to the right on the given number of bars. Default is 0.join
(input bool) If true then plot points will be joined with line, applicable only to plot.style_cross and plot.style_circles styles. Default is false.editable
(const bool) If true then plot style will be editable in Format dialog. Default is true.show_last
(input int) If set, defines the number of bars (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
plotshape
plotchar
bgcolor
Plots visual shapes on the chart.
plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display)
Example
data = close >= open
plotshape(data, style=shape.xcross)
Arguments
series
(series bool) Series of data to be plotted as shapes. Series is treated as a series of boolean values for all location values except location.absolute. Required argument.title
(const string) Title of the plot.style
(input string) Type of plot. Possible values are: shape.xcross, shape.cross, shape.triangleup, shape.triangledown, shape.flag, shape.circle, shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown, shape.square, shape.diamond. Default value is shape.xcross.location
(input string) Location of shapes on the chart. Possible values are: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute. Default value is location.abovebar.color
(series color) Color of the shapes. 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.offset
(series int) Shifts shapes to the left or to the right on the given number of bars. Default is 0.text
(const string) Text to display with the shape. You can use multiline text, to separate lines use ‘\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 plotshape style will be editable in Format dialog. Default is true.show_last
(input int) If set, defines the number of shapes (from the last bar back to the past) to plot on chart.size
(const string) Size of shapes 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
plot
plotchar
bgcolor
Plots visual shapes using any given one Unicode character on the chart.
plotchar(series, title, char, location, color, offset, text, textcolor, editable, size, show_last, display)
Example
data = close >= open
plotchar(data, char='❄')
Arguments
series
(series bool) Series of data to be plotted as shapes. Series is treated as a series of boolean values for all location values except location.absolute. Required argument.title
(const string) Title of the plot.char
(input string) Character to use as a visual shape.location
(input string) Location of shapes on the chart. Possible values are: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute. Default value is location.abovebar.color
(series color) Color of the shapes. 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.offset
(series int) Shifts shapes to the left or to the right on the given number of bars. Default is 0.text
(const string) Text to display with the shape. You can use multiline text, to separate lines use ‘\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
plot
plotshape
bgcolor
Plots candles on the chart.
plotcandle(open, high, low, close, title, color, wickcolor, editable, show_last, bordercolor, display)
Example
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
plotbar
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
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
(`乞丐 为何策略广场复制的pine策略无法实盘
小小梦 好的,我们检查下。
乞丐 张超大佬的Optimized Trend Tracker
小小梦 您好,请问具体是哪个策略呢?