millionchart
فارسی

Technical analysis reference

The 61 functions and 10 values of tech: signature, effects, phase, cost and tested examples.

Moving averages, oscillators, channels and statistics over series. Every function here keeps a state for each place it is written, so it advances only when execution reaches it: see E3302 and W3302 in the diagnostics.

Functions#

tech.alma#

tech.alma([source], [length], [bias], [sigma], [floor])

A moving average with Gaussian weights. bias moves the centre of the weights toward the newest bar and sigma sets how wide they are.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.atr#

tech.atr(length)

The average true range: the Wilder average of the true range (tech.tr) over length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: ATR channel, Status table, ATR stop and target, Lazy operators.

tech.avg_dev#

tech.avg_dev([source], [length])

The mean absolute deviation of source from its simple average over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.bars_since#

tech.bars_since(condition)

The number of bars since condition was last true; na until it has been true once.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.bb#

tech.bb(source, length, mult)

Bollinger Bands. Returns the middle line (a simple moving average) and the upper and lower bands, mult standard deviations above and below it.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a tuple of three series.

tech.bbw#

tech.bbw(source, length, mult)

The Bollinger Band width: upper band minus lower band, divided by the middle line.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.carry#

tech.carry([source])

The last value of source that was not na: it carries a value forward over gaps.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.cci#

tech.cci(source, length)

The commodity channel index: how far source is from its average, in units of the mean absolute deviation.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.change#

tech.change(source, [length])

The difference between source and its value length bars ago (one bar by default).

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.cmo#

tech.cmo(source, length)

The Chande momentum oscillator: the difference between the sum of gains and the sum of losses, divided by their total, times 100.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.cog#

tech.cog([source], [length])

The center of gravity oscillator of the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.correlation#

tech.correlation(source, other, length)

The Pearson correlation of two series over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.crosses#

tech.crosses(source, other)

True on the bar where source crosses other, in either direction.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of true and false.

tech.crosses_above#

tech.crosses_above(source, other)

True on the bar where source crosses above other.

tech.crosses_below#

tech.crosses_below(source, other)

True on the bar where source crosses below other.

tech.cum_sum#

tech.cum_sum(source)

The running total of source since the first bar.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.
  • Examples: On-balance volume.

tech.dmi#

tech.dmi([di_length], [adx_length])

The directional movement index. Returns +DI, -DI and the ADX, the average directional index that measures trend strength.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in di_length, adx_length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a tuple of three series.
  • Examples: ADX with directional indicators.

tech.ema#

tech.ema(source, length)

The exponential moving average. Each value is alpha * source + (1 - alpha) * previous, with alpha = 2 / (length + 1).

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: EMA pair with cross marks, ATR channel, Higher timeframe average, On-balance volume.

tech.highest#

tech.highest(source, [length])

The highest value of source over the last length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Donchian channel, Stochastic oscillator, Recent range drawing, Bars since a high.

tech.highest_offset#

tech.highest_offset(source, [length])

How many bars back the highest value of the window is.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.hma#

tech.hma(source, length)

The Hull moving average: a weighted average built to follow price closely with little lag.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.is_falling#

tech.is_falling(source, length)

True when source has fallen on each of the last length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of true and false.

tech.is_rising#

tech.is_rising(source, length)

True when source has risen on each of the last length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of true and false.

tech.kc#

tech.kc(source, length, mult, [use_true_range])

Keltner Channels. Returns the middle line (an exponential average) and the upper and lower lines, mult times a measure of range above and below it.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a tuple of three series.

tech.kcw#

tech.kcw([source], [length], [mult], [use_true_range])

The Keltner Channel width: upper line minus lower line, divided by the middle line.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.linreg#

tech.linreg([source], [length], [offset])

The value of the least-squares line fitted to the window, at the newest bar shifted by offset.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.lowest#

tech.lowest(source, [length])

The lowest value of source over the last length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Donchian channel, Stochastic oscillator, Recent range drawing, Donchian breakout strategy.

tech.lowest_offset#

tech.lowest_offset(source, [length])

How many bars back the lowest value of the window is.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.macd#

tech.macd(source, fast_length, slow_length, signal_length)

Moving Average Convergence Divergence. Returns the MACD line (fast EMA minus slow EMA), the signal line (an EMA of the MACD line) and the histogram (their difference).

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in fast_length, slow_length, signal_length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a tuple of three series.
  • Examples: MACD.

tech.median#

tech.median([source], [length])

The median of source over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.mfi#

tech.mfi(source, length)

The money flow index: a volume-weighted relative strength index of the typical price.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.mode#

tech.mode([source], [length])

The most frequent value of source over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.mom#

tech.mom(source, length)

Momentum: source minus source length bars ago.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.percent_rank#

tech.percent_rank(source, length)

The percent of the previous length values that are less than or equal to the current one.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.percentile#

tech.percentile([source], [length], [percent])

The value at the given percent of the window, interpolating between neighbours.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.percentile_nearest#

tech.percentile_nearest([source], [length], [percent])

The value at the given percent of the window, taking the nearest rank.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.pivot_high#

tech.pivot_high(source, left_bars, [right_bars])

The price of a swing high: a bar whose value is the highest of left_bars bars before it and right_bars after it. It is known right_bars bars late, and na on every other bar.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in left_bars, right_bars (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Swing pivots, Swing high path.

tech.pivot_levels#

tech.pivot_levels([kind], [anchor], [developing])

Pivot point levels computed from the previous period of anchor by the formula kind.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call; builds a new value whose size follows its arguments (counted in the memory ledger).
  • Phase: every bar.
  • Cost: one state per call site; allocates: the memory ledger counts what it builds.

tech.pivot_low#

tech.pivot_low(source, left_bars, [right_bars])

The price of a swing low, found the same way as tech.pivot_high.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in left_bars, right_bars (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Swing pivots.

tech.range#

tech.range([source], [length])

The highest value minus the lowest value of source over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.rci#

tech.rci([source], [length])

The rank correlation index of the window: how closely the price ranks follow the time order.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.rma#

tech.rma(source, length)

Wilder's running moving average, an exponential average with alpha = 1 / length. It is the smoothing behind tech.rsi and tech.atr.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: RSI written out.

tech.roc#

tech.roc(source, length)

Rate of change: the percent change of source over length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.rsi#

tech.rsi(source, length)

The relative strength index: 100 minus 100 divided by one plus the ratio of the Wilder average gain to the Wilder average loss. It lies between 0 and 100.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: RSI zones, RSI written out, Status table, RSI reversion strategy.

tech.running_max#

tech.running_max([source])

The highest value of source since the first bar.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.running_min#

tech.running_min([source])

The lowest value of source since the first bar.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.sample_when#

tech.sample_when(source, condition, occurrence)

The value of source on the bar where condition was true, looking back occurrence such bars (0 is the latest).

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call; builds a new value whose size follows its arguments (counted in the memory ledger).
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in occurrence (at most 8,192), so its memory follows that number and never the length of the chart; allocates: the memory ledger counts what it builds.
  • Returns: a series of numbers.

tech.sar#

tech.sar([start], [step], [max])

The parabolic stop and reverse: a trailing point that accelerates by step up to max in the direction of the trend.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.sma#

tech.sma(source, length)

The simple moving average: the mean of the last length values of source.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Simple moving average, Bollinger bands, Stochastic oscillator, Trend background.

tech.stdev#

tech.stdev(source, length, [biased])

The standard deviation of source over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Bollinger bands.

tech.stoch#

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

The raw stochastic: 100 times the close's distance above the lowest low of the window, divided by the range between the highest high and the lowest low.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.
  • Examples: Stochastic oscillator.

tech.sum#

tech.sum(source, length)

The sum of source over the last length bars.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.supertrend#

tech.supertrend([factor], [atr_length])

The supertrend: a line built from the average true range that flips side when the price crosses it. Returns the line and the direction.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in atr_length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a tuple of two series.

tech.swma#

tech.swma([source])

A moving average of the last four values with the weights 1, 2, 2, 1.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; a fixed window of 4 bars.
  • Returns: a series of numbers.

tech.tr#

tech.tr([handle_na])

The true range of the bar: the largest of the high minus the low, the high minus the previous close and the previous close minus the low (absolute values).

A function and also a value of the same name: tech.tr is the true range of the current bar.

  • Effects: none: the result depends on the arguments only.
  • Phase: every bar.
  • Cost: a fixed number of operations.
  • Returns: a series of numbers.

tech.tsi#

tech.tsi([source], [short_length], [long_length])

The true strength index: a double-smoothed momentum divided by the double-smoothed absolute momentum.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in short_length, long_length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.variance#

tech.variance(source, length, [biased])

The variance of source over the window.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.vwap#

tech.vwap([source], [anchor], [mult])

The volume-weighted average price, restarting at each anchor period.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site.
  • Returns: a series of numbers.

tech.vwma#

tech.vwma(source, length)

The volume-weighted moving average: the mean of source * volume over the window divided by the mean of volume.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.wma#

tech.wma(source, length)

The weighted moving average: the newest value of the window has the largest weight, falling linearly to the oldest.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

tech.wpr#

tech.wpr([length])

Williams %R: where the close sits in the range of the last length bars, on a scale from -100 to 0.

  • Effects: keeps a state for each place it is written (a call site) and advances it when execution reaches the call.
  • Phase: every bar.
  • Cost: one state per call site; it reads back the number of bars in length (at most 8,192), so its memory follows that number and never the length of the chart.
  • Returns: a series of numbers.

Values#

  • tech.accdist
  • tech.iii
  • tech.nvi
  • tech.obv
  • tech.pvi
  • tech.pvt
  • tech.tr
  • tech.vwap
  • tech.wad
  • tech.wvad