The resource loading... loading...

FMZ PINE Script Doc

Author: Inventors quantify - small dreams, Created: 2022-04-28 16:05:05, Updated: 2024-10-12 17:25:27

le of const string values: [val1, val2, …]) A list of options to choose from.

  • tooltip (const string) The string that will be shown to the user when hovering over the tooltip icon.
  • inline (const string) Combines all the input calls using the same argument in one line. The string used as an argument is not displayed. It is only used to identify inputs belonging to the same line.
  • group (const string) Creates a header above all inputs using the same group argument string. The string is also used as the header’s text.
  • confirm (const bool) If true, then user will be asked to confirm input value before indicator is added to chart. Default value is false.

Remarks Result of input.timeframe function always should be assigned to a variable, see examples above.

See also input.bool input.int input.float input.string input.source input.color input

input.integer

Not available.

input.resolution

Not available.

ta

ta.alma

Arnaud Legoux Moving Average. It uses Gaussian distribution as weights for moving average.

ta.alma(series, length, offset, sigma) 
ta.alma(series, length, offset, sigma, floor) 

Example

plot(ta.alma(close, 9, 0.85, 6))

// same on pine, but much less efficient
pine_alma(series, windowsize, offset, sigma) =>
    m = offset * (windowsize - 1)
    //m = math.floor(offset * (windowsize - 1)) // Used as m when math.floor=true
    s = windowsize / sigma
    norm = 0.0
    sum = 0.0
    for i = 0 to windowsize - 1
        weight = math.exp(-1 * math.pow(i - m, 2) / (2 * math.pow(s, 2)))
        norm := norm + weight
        sum := sum + series[windowsize - i - 1] * weight
    sum / norm
plot(pine_alma(close, 9, 0.85, 6))

Returns Arnaud Legoux Moving Average.

Arguments

  • series (series int/float) Series of values to process.
  • length (series int) Number of bars (length).
  • offset (simple int/float) Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0).
  • sigma (simple int/float) Changes the smoothness of ALMA. The larger sigma the smoother ALMA.
  • floor (simple bool) An optional argument. Specifies whether the offset calculation is floored before ALMA is calculated. Default value is false.

See also ta.sma ta.ema ta.rma ta.wma ta.vwma ta.swma

ta.sma

The sma function returns the moving average, that is the sum of last y values of x, divided by y.

ta.sma(source, length) 

Example

plot(ta.sma(close, 15))

// same on pine, but much less efficient
pine_sma(x, y) =>
    sum = 0.0
    for i = 0 to y - 1
        sum := sum + x[i] / y
    sum
plot(pine_sma(close, 15))

Returns Simple 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.ema ta.rma ta.wma ta.vwma ta.swma ta.alma

ta.cog

The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.

ta.cog(source, length) 

Example

plot(ta.cog(close, 10))

// the same on pine
pine_cog(source, length) =>
    sum = math.sum(source, length)
    num = 0.0
    for i = 0 to length - 1
        price = source[i]
        num := num + price * (i + 1)
    -num / sum

plot(pine_cog(close, 10))

Returns Center of Gravity.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

See also ta.stoch

ta.dev

Measure of difference between the series and it’s ta.sma

ta.dev(source, length) 

Example

plot(ta.dev(close, 10))

// the same on pine
pine_dev(source, length) =>
    mean = ta.sma(source, length)
    sum = 0.0
    for i = 0 to length - 1
        val = source[i]
        sum := sum + math.abs(val - mean)
    dev = sum/length
plot(pine_dev(close, 10))

Returns Deviation 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.variance ta.stdev

ta.stdev

ta.stdev(source, length, biased) 

Example

plot(ta.stdev(close, 5))

//the same on pine
isZero(val, eps) => math.abs(val) <= eps

SUM(fst, snd) =>
    EPS = 1e-10
    res = fst + snd
    if isZero(res, EPS)
        res := 0
    else
        if not isZero(res, 1e-4)
            res := res
        else
            15

pine_stdev(src, length) =>
    avg = ta.sma(src, length)
    sumOfSquareDeviations = 0.0
    for i = 0 to length - 1
        sum = SUM(src[i], -avg)
        sumOfSquareDeviations := sumOfSquareDeviations + sum * sum

    stdev = math.sqrt(sumOfSquareDeviations / length)
plot(pine_stdev(close, 5))

Returns Standard deviation.

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.variance

ta.ema

The ema function returns the exponentially weighted moving average. In ema weighting factors decrease exponentially. It calculates by using a formula: EMA = alpha * source + (1 - alpha) * EMA[1], where alpha = 2 / (length + 1).

ta.ema(source, length) 

Example

plot(ta.ema(close, 15))

//the same on pine
pine_ema(src, length) =>
    alpha = 2 / (length + 1)
    sum = 0.0
    sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_ema(close,15))

Returns Exponential moving average of source with alpha = 2 / (length + 1).

Arguments

  • source (series int/float) Series of values to process.
  • length (simple int) Number of bars (length).

Remarks Please note that using this variable/function can cause indicator repainting.

See also ta.sma ta.rma ta.wma ta.vwma ta.swma ta.alma

ta.wma

The wma function returns weighted moving average of source for length bars back. In wma weighting factors decrease in arithmetical progression.

ta.wma(source, length) 

Example

plot(ta.wma(close, 15))

// same on pine, but much less efficient
pine_wma(x, y) =>
    norm = 0.0
    sum = 0.0
    for i = 0 to y - 1
        weight = (y - i) * y
        norm := norm + weight
        sum := sum + x[i] * weight
    sum / norm
plot(pine_wma(close, 15))

Returns 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.vwma ta.swma ta.alma

ta.swma

Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6].

ta.swma(source)

Example

plot(ta.swma(close))

// same on pine, but less efficient
pine_swma(x) =>
    x[3] * 1 / 6 + x[2] * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6
plot(pine_swma(close))

Returns Symmetrically weighted moving average.

Arguments

  • source (series int/float) Source series.

See also ta.sma ta.ema ta.rma ta.wma ta.vwma ta.alma

ta.hma

The hma function returns the Hull Moving Average.

ta.hma(source, length)

Example

src = input(defval=close, title="Source")
length = input(defval=9, title="Length")
hmaBuildIn = ta.hma(src, length)
plot(hmaBuildIn, title="Hull MA", color=#674EA7)

Returns Hull moving average of ‘source’ for ‘length’ bars back.

Arguments

  • source (series int/float) Series of values to process.
  • length (simple int) Number of bars.

See also ta.ema ta.rma ta.wma ta.vwma ta.sma

ta.rma

Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.

ta.rma(source, length)

Example

plot(ta.rma(close, 15))

//the same on pine
pine_rma(src, length) =>
  alpha = 1/length
  sum = 0.0
  sum := na(sum[1]) ? ta.sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_rma(close, 15))

Returns Exponential moving average of source with alpha = 1 / length.

Arguments

  • source (series int/float) Series of values to process.
  • length (simple int) Number of bars (length).

See also ta.sma ta.ema ta.wma ta.vwma ta.swma ta.alma ta.rsi

ta.rsi

Relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars.

ta.rsi(source, length)

Example

plot(ta.rsi(close, 7))

// same on pine, but less efficient
pine_rsi(x, y) => 
    u = math.max(x - x[1], 0) // upward ta.change
    d = math.max(x[1] - x, 0) // downward ta.change
    rs = ta.rma(u, y) / ta.rma(d, y)
    res = 100 - 100 / (1 + rs)
    res

plot(pine_rsi(close, 7))

Returns Relative strength index.(RSI)

Arguments

  • source (series int/float) Series of values to process.
  • length (simple int) Number of bars (length).

See also ta.rma

ta.tsi

True strength index. It uses moving averages of the underlying momentum of a financial instrument.

ta.tsi(source, short_length, long_length)

Returns True strength index. A value in range [-1, 1].

Arguments

  • source (series int/float) Source series.
  • short_length (simple int) Short length.
  • long_length (simple int) Long length.

ta.roc

Function roc (rate of change) showing the difference between current value of source and the value of source that was length days ago. It is calculated by the formula: 100 * change(src, length) / src[length].

ta.roc(source, length)

Returns The rate of change of source for length bars back.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

ta.range

Returns the difference between the min and max values in a series.

ta.range(source, length)

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

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

ta.macd

MACD (moving average convergence/divergence). It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock’s price.

ta.macd(source, fastlen, slowlen, siglen) 

Example

[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot(macdLine, color=color.blue)
plot(signalLine, color=color.orange)
plot(histLine, color=color.red, style=plot.style_histogram)

If you need only one value, use placeholders ‘_’ like this:

Example

[_, signalLine, _] = ta.macd(close, 12, 26, 9)
plot(signalLine, color=color.orange)

Returns Tuple of three MACD series: MACD line, signal line and histogram line.

Arguments

  • source (series int/float) Series of values to process.
  • fastlen (simple int) Fast Length argument.
  • slowlen (simple int) Slow Length argument.
  • siglen (simple int) Signal Length argument.

See also ta.sma ta.ema

ta.mode

Returns the mode of the series. If there are several values with the same frequency, it returns the smallest value.

ta.mode(source, length)

Returns The mode of the series.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

ta.median

Returns the median of the series.

ta.median(source, length) 

Returns The median of the series.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

ta.linreg

Linear regression curve. A line that best fits the prices specified over a user-defined time period. It is calculated using the least squares method. The result of this function is calculated using the formula: linreg = intercept + slope * (length - 1 - offset), where intercept and slope are the values calculated with the least squares method on source series.

ta.linreg(source, length, offset) 

Returns Linear regression curve.

Arguments

  • source (series int/float) Source series.
  • length (series int)
  • offset (simple int) Offset.

ta.bb

Bollinger Bands. A Bollinger Band is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of the security’s price, but can be adjusted to user preferences.

ta.bb(series, length, mult) 

Example

[middle, upper, lower] = ta.bb(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)

// the same on pine
f_bb(src, length, mult) =>
    float basis = ta.sma(src, length)
    float dev = mult * ta.stdev(src, length)
    [basis, basis + dev, basis - dev]

[pineMiddle, pineUpper, pineLower] = f_bb(close, 5, 4)

plot(pineMiddle)
plot(pineUpper)
plot(pineLower)

Returns Bollinger Bands.

Arguments

  • series (series int/float) Series of values to process.
  • length (series int) Number of bars (length).
  • mult (simple int/float) Standard deviation factor.

See also ta.sma ta.stdev ta.kc

ta.bbw

Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the lower Bollinger Bands divided by the middle band.

ta.bbw(series, length, mult) 

Example

plot(ta.bbw(close, 5, 4), color=color.yellow)

// the same on pine
f_bbw(src, length, mult) =>
    float basis = ta.sma(src, length)
    float dev = mult * ta.stdev(src, length)
    ((basis + dev) - (basis - dev)) / basis

plot(f_bbw(close, 5, 4))

Returns Bollinger Bands Width.

Arguments

  • series (series int/float) Series of values to process.
  • length (series int) Number of bars (length).
  • mult (simple int/float) Standard deviation factor.

See also ta.bb ta.sma ta.stdev

ta.cci

The CCI (commodity channel index) is calculated as the difference between the typical price of a commodity and its simple moving average, divided by the mean absolute deviation of the typical price. The index is scaled by an inverse factor of 0.015 to provide more readable numbers.

ta.cci(source, length) 

Returns Commodity channel index of source for length bars back.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

ta.change

The difference between the current value and the previous value, source - source [length].

ta.change(source, length) 
ta.change(source) 

Returns The result of subtraction.

Arguments

  • source (series int/float) Source series.
  • length (series int) Offset from the current bar to the previous bar. Optional, if not given, length=1 is used.

See also ta.mom ta.cross

ta.mom

Momentum of source price and source price length bars ago. This is simply a difference: source - source[length].

ta.mom(source, length) 

Returns Momentum of source price and source price length bars ago.

Arguments

  • source (series int/float) Series of values to process.
  • length (series int) Offset from the current bar to the previous bar.

See also ta.change

ta.cmo

Chande Momentum Oscillator. Calculates the difference between the sum of recent gains and the sum of recent losses and then divides the result by the sum of all price movement over the same period.

ta.cmo(series, length) 

Example

plot(ta.cmo(close, 5), color=color.yellow)

// the same on pine
f_cmo(src, length) =>
    float mom = ta.change(src)
    float sm1 = math.sum((mom >= 0) ? mom : 0.0, length)
    float sm2 = math.sum((mom >= 0) ? 0.0 : -mom, length)
    100 * (sm1 - sm2) / (sm1 + sm2)

plot(f_cmo(close, 5))

Returns Chande Momentum Oscillator.

Arguments

  • series (series int/float) Series of values to process.
  • length (series int) Number of bars (length).

See also ta.rsi ta.stoch math.sum

ta.percentile_linear_interpolation

Calculates percentile using method of linear interpolation between the two nearest ranks.

ta.percentile_linear_interpolation(source, length, percentage) 

Returns P-th percentile of source series for length bars back.

Arguments

  • source (series int/float) Series of values to process (source).
  • length (series int) Number of bars back (length).
  • percentage (simple int/float) Percentage, a number from range 0…100.

Remarks Note that a percentile calculated using this method will NOT always be a member of the input data set.

See also ta.percentile_nearest_rank

ta.percentile_nearest_rank

Calculates percentile using method of Nearest Rank.

ta.percentile_nearest_rank(source, length, percentage) 

Returns P-th percentile of source series for length bars back.

Arguments

  • source (series int/float) Series of values to process (source).
  • length (series int) Number of bars back (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

ta.percentrank

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

ta.variance

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

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

ta.mfi

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

ta.kc

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

ta.kcw

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

ta.correlation

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

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

ta.crossover

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.

ta.crossunder

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.

ta.atr

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

ta.sar

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.

ta.barssince

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

ta.cum

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

ta.dmi

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

ta.falling

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

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

ta.pivothigh

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.

ta.pivotlow

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.

ta.highest

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

ta.highestbars

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

ta.stoch

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

ta.supertrend

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 ATR

See also ta.macd

ta.lowest

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

ta.lowestbars

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

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

ta.vwap

Volume weighted average price.

ta.vwap(source) 

Returns Volume weighted average.

Arguments

  • source (series int/float) Source series.

See also ta.vwap

ta.vwma

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

ta.wpr

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

plot

plot

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

plotshape

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

plotchar

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

plotcandle

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

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


More

The 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?