Trend indicators

The trend indicators: moving averages, bands and envelopes, Ichimoku, Parabolic SAR, ADX and the adaptive averages: formulas, lines, reading in a rule.

The trend indicators. All are drawn over the candles, on the price's scale, except ADX and Standard Deviation, which have panes of their own. What every entry takes for granted is on Indicators: reading a line by name and shift (reading a line), the Shift field and the lines drawn forward (lines drawn forward or back), and the first value and the warm-up, with bars counted from bar 0, the first bar the run loaded (the first value).

Where an indicator takes an applied price, every Candle Data price except OpenTime is offered, Volume included (indicators that read volume). Each entry gives its text form, its parameters in the order the text writes them, and its lines, numbered from 0 in the order the entry gives; it ends on how its values are verified (the record).

Adaptive Moving Average

AMA in the strategy text · one line over the candles

Kaufman's adaptive average: fast in a clean trend, slow in noise. Over the last N bars the efficiency ratio is the net move of the applied price, |price − price N bars ago|, divided by the sum of its N bar-to-bar moves: 1 in a straight run, near 0 in noise. It places a constant between the fast average's factor 2 ÷ (fast + 1) and the slow one's 2 ÷ (slow + 1), constant = ratio × (fast factor − slow factor) + slow factor, and each bar the line moves toward the price by the constant squared: AMA = previous + constant² × (price − previous).

  • One line (number 0), so a read names no line: ama[1]. The line starts from the price of bar N + 1 and has its first value on bar N + 2 (N + 2 + Shift with a Shift).
  • The sum of the moves starts from 1e-9, so a market that did not move over the period reads an efficiency of 0, not a division by zero. At an efficiency of 0 the constant is the slow factor, so the line keeps moving toward the price at the slow pace, by the slow factor squared.
  • It is recursive: a run's first values carry the starting price, whose share falls every bar by at least the smaller of the two factors squared (a fast period longer than the slow one is accepted) (recursive indicators).

AMA(period, fastPeriod, slowPeriod, shift, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st9 bars1 – 2,497 barsYes
Fast PeriodfastPeriod, 2nd2 bars1 – 2,500 barsYes
Slow PeriodslowPeriod, 3rd30 bars1 – 2,500 barsYes
Shiftshift, 4th0 bars0 – 1,000 barsNo
Applied PriceappliedPrice, 5thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The first value needs Period + 3 bars of history, so the period stops three bars short of 2,500.

Reading it in a rule. ama[0] is the bar that just closed; in an On Tick rule, the bar in progress so far. With a Shift above 0 it is a closed bar's value. A fast period longer than the slow one is accepted: the line is then fastest in noise.

Verified value by value against an independent reference (the record).

ADX

ADX in the strategy text · three lines in a pane of their own

The Average Directional Movement Index and its two directional lines, each from 0 to 100.

Line (number, name)What it isDrawnFirst value on bar
0 adx, ADXtrend strength: DX smoothedon its own bar2N − 1
1 plusDi, +DIthe push upward: 100 × smoothed +DM ÷ smoothed true rangeon its own barN
2 minusDi, −DIthe push downward: 100 × smoothed −DM ÷ smoothed true rangeon its own barN
  • On every bar after the first, the up move is high − previous high and the down move is previous low − low. A negative move counts as 0, the larger of the two is the bar's directional movement (+DM or −DM) and the other counts as 0; equal moves count as 0 on both sides. True range is ATR's: the largest of high − low, |high − previous close| and |low − previous close|.
  • Wilder (the default, the classic ADX): true range, +DM and −DM are each smoothed by Wilder's method (first value the plain average of the first N, then (previous × (N − 1) + value) ÷ N), and +DI = 100 × smoothed +DM ÷ smoothed true range, −DI likewise; both are 0 when the smoothed true range is 0.
  • Exponential: each bar's 100 × +DM ÷ true range and 100 × −DM ÷ true range (both 0 on a bar whose true range is 0) are smoothed with an EMA, k = 2 ÷ (N + 1), first value the average of the first N.
  • In both, DX = 100 × |+DI − −DI| ÷ (+DI + −DI), 0 when both are 0, and the ADX line is DX smoothed the same way. Every smoothing starts from the plain average of its first N inputs.

ADX(period, method), the method wilder or exponential:

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars1 – 2,500 barsYes
Smoothingmethod, 2ndWilderWilder, ExponentialNo

Reading it in a rule. adx.adx[0] in a candle-close rule (adx.adx[1] in an On Tick rule) is trend strength on the last closed bar, whatever its direction; adx.plusDi crosses above adx.minusDi is the classic directional signal. All three lines are recursive and the ADX line chains two smoothings, so give it about twice the lead-in of a single one (recursive indicators).

Verified value by value against an independent reference (the record).

Bollinger Bands

BB in the strategy text · three lines over the candles

A simple moving average of the applied price with a band the deviation times the standard deviation above and below it.

Line (number, name)What it isDrawnFirst value on bar
0 upper, Uppermiddle + deviation × σon its own bar (Shift: forward)N − 1 (N − 1 + Shift with a Shift)
1 middle, Middlethe SMA of the last N applied priceson its own bar (Shift: forward)N − 1 (N − 1 + Shift with a Shift)
2 lower, Lowermiddle − deviation × σon its own bar (Shift: forward)N − 1 (N − 1 + Shift with a Shift)

σ is the population standard deviation of the last N prices: divided by N, not N − 1.

BB(period, shift, deviation, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st20 bars1 – 2,500 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Deviationdeviation, 3rd2≥ 0Yes
Applied PriceappliedPrice, 4thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The table's bound is not the whole rule: Deviation must be above 0, so a Deviation of 0 is refused when you save.

Reading it in a rule. close > bands.upper is a close above the upper band; bands.middle[0] in a candle-close rule (bands.middle[1] in an On Tick rule) is the average on the last closed bar. The lines are numbered 0 upper, 1 middle, 2 lower.

Verified value by value against an independent reference (the record).

DEMA

DEMA in the strategy text · one line over the candles

The Double Exponential Moving Average: DEMA = 2 × EMA − EMA of that EMA, both of period N, k = 2 ÷ (N + 1). Less lag than an EMA of the same period; it overshoots sharp turns.

  • One line (number 0), so a read names no line: dema[1]. The first average starts on bar 0 from that bar's price and the second on bar N − 1 from the first's value there.
  • First value on bar 2 × (N − 1) (plus Shift with a Shift); the bars before it have no value.
  • It is recursive (recursive indicators).

DEMA(period, shift, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars2 – 1,250 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Applied PriceappliedPrice, 3rdCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The period is at least 2 (with a period of 1 the line would be the price) and at most half of 2,500, since two averages run in a row.

Reading it in a rule. dema[0] is the bar that just closed; in an On Tick rule, the bar in progress so far. With a Shift above 0 it is a closed bar's value.

Verified value by value against an independent reference (the record).

Envelopes

Envelopes in the strategy text · two lines over the candles

Two bands a fixed percentage above and below a moving average of the applied price.

Line (number, name)What it isDrawnFirst value on bar
0 upper, Upperaverage × (1 + deviation ÷ 100)on its own bar (Shift: forward)N − 1 (N − 1 + Shift with a Shift)
1 lower, Loweraverage × (1 − deviation ÷ 100)on its own bar (Shift: forward)N − 1 (N − 1 + Shift with a Shift)
  • The average is SMA, EMA, SMMA or LWMA. The exponential one starts from the first price and has no value until it has taken N prices, so every method's first band is on bar N − 1.
  • The deviation is a percentage of the average, not a multiple of the standard deviation as on Bollinger Bands: 0.1 puts the bands 0.1 % either side, about 11 pips on EURUSD at 1.10.
  • The linear-weighted method slides its sums from bar to bar (the linear-weighted drift).

Envelopes(period, shift, method, appliedPrice, deviation), the deviation from 0 to 100:

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars1 – 2,500 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Methodmethod, 3rdSmaSma, Ema, Smma, LwmaNo
Applied PriceappliedPrice, 4thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo
Deviationdeviation, 5th0.1 %0 – 100 %Yes

Reading it in a rule. close < env.lower is a close below the lower band. In an On Tick rule [0] moves with the price so far; with a Shift above 0 it is a closed bar's value.

Verified value by value against an independent reference (the record).

Fractal Adaptive Moving Average

FRAMA in the strategy text · one line over the candles

Ehlers' fractal adaptive average: its speed follows how rough the market is. Each bar, the window of the last 2N bars is cut into two halves of N bars:

  • N1 and N2 are each half's range (highest high − lowest low) divided by N, and N3 the whole window's range divided by 2N; the ranges always come from the highs and lows, whatever the applied price;
  • the fractal dimension is D = (log(N1 + N2) − log(N3)) ÷ log 2: 1 for a straight run, 2 for pure noise;
  • the factor is α = exp(−4.6 × (D − 1)): 1 in a straight run, about 0.01 in noise;
  • the line moves toward the applied price: FRAMA = α × price + (1 − α) × previous.

One line (number 0), so a read names no line: frama[1]. Its first value, on bar 2N − 1 (2N − 1 + Shift with a Shift), is that bar's price; the steps start on bar 2N. It is recursive: the starting price fades by at least 1 % a bar, the factor never falling below about 0.01 (recursive indicators).

FRAMA(period, shift, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars1 – 1,250 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Applied PriceappliedPrice, 3rdCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The window spans 2N bars, so the period is at most half of 2,500.

The factor is not capped at 1. When a gap separates two quiet halves of the window, the factor exceeds 1 and for one bar the line goes beyond the price. Measured on 14 November 2026: up to 1.14 on EURUSD H1, 6.4 on gold H1 and about 5,900 on EURUSD M1 around the daily rollover; Ehlers' original caps it at 1. A rule comparing the price with FRAMA can flip on such a bar.

Halves without range. Where both halves of the window have no range (every high and low of each half equal: the whole window flat, or two flat halves at different levels), the dimension would need the logarithm of zero. Here the factor is 1: the line takes that bar's price and carries on.

Reading it in a rule. frama[0] is the bar that just closed; in an On Tick rule, the bar in progress so far. With a Shift above 0 it is a closed bar's value.

Verified value by value against an independent reference (the record).

Ichimoku Kinko Hyo

Ichimoku in the strategy text · five lines over the candles

Five lines on the price's scale. Three are the midpoint of the highest high and the lowest low of a window of bars, (highest + lowest) ÷ 2, taken from the bars' own highs and lows; one is the midpoint of two of them; one is the close. It has no applied price and reads no volume.

Line (number, name)What it isDrawnFirst value on bar
0 tenkan, Tenkan-senthe midpoint of the last Tenkan barson its own barTenkan − 1
1 kijun, Kijun-senthe midpoint of the last Kijun barson its own barKijun − 1
2 senkouA, Senkou Span Athe midpoint of the Tenkan-sen and the Kijun-senKijun bars forwardmax(Tenkan, Kijun) − 1 + Kijun
3 senkouB, Senkou Span Bthe midpoint of the last Senkou B barsKijun bars forwardSenkou B − 1 + Kijun
4 chikou, Chikou Spanthe closeKijun bars back0 (the close of bar Kijun); a read holds it from [Kijun]; the newest Kijun bars never show one

Each line has no value until its window is full. With a Tenkan-sen longer than the Kijun-sen, Senkou Span A starts where both lines have a value.

Ichimoku(tenkanPeriod, kijunPeriod, senkouBPeriod), each period from 1 to 2,500 bars:

FieldIn the textDefaultValuesCan be swept
Tenkan-sentenkanPeriod, 1st9 bars1 – 2,500 barsYes
Kijun-senkijunPeriod, 2nd26 bars1 – 2,500 barsYes
Senkou Span BsenkouBPeriod, 3rd52 bars1 – 2,500 barsYes

The longest window plus the Kijun-sen may not pass 2,500 bars: the cloud is drawn Kijun bars forward, so it needs that much more history. A set beyond it is refused when you save.

Reading it in a rule.

  • ichi.tenkan and ichi.kijun at [0] are the bar that just closed; in an On Tick rule, the bar in progress so far.
  • ichi.senkouA[0] and ichi.senkouB[0] are the cloud as drawn on the current bar, computed Kijun bars ago: a closed bar's value even in an On Tick rule, so it does not move while the bar forms. "The close above the cloud" is close > ichi.senkouA and close > ichi.senkouB.
  • The cloud drawn ahead of the newest bar cannot be read (a negative shift is refused). What Senkou Span A will show Kijun bars from now is today's midpoint of the Tenkan-sen and the Kijun-sen, an Expression (ichi.tenkan + ichi.kijun) / 2; for Senkou Span B, the Tenkan-sen of a second Ichimoku whose Tenkan period is the Senkou B period.
  • ichi.chikou[s] is the close Kijun bars after bar s. A read nearer than [Kijun] can never hold a value (the close it needs has not happened yet) and is refused when you save and when a run starts, with a message naming the smallest read that can: [Kijun], [26] at the defaults. The strategy editor starts a Chikou read there and does not let it go nearer. ichi.chikou[Kijun] is the current close (in an On Tick rule, the bar in progress so far) and ichi.chikou[Kijun + n] is close[n], so the classic test "the lagging line above the price Kijun bars ago" is close > close[Kijun].
  • A Kijun-sen above 1,000 bars makes the Chikou span unreadable: its smallest read is past the deepest read allowed. The other four lines are unaffected.
  • In an optimization, a sweep of the Kijun-sen whose larger values would push a fixed Chikou read past its smallest valid position is refused when you create it, and so is a sweep whose longest window plus Kijun-sen would pass 2,500 bars. The message names the read, the value that breaks it and the largest value that works (indicators in a sweep).

Verified value by value against an independent reference (the record).

Moving Average

MA in the strategy text · one line over the candles

The average of the applied price over N bars, by one of four methods:

  • SMA: the mean of the last N prices;
  • EMA: k = 2 ÷ (N + 1), EMA = price × k + previous × (1 − k);
  • SMMA: (previous × (N − 1) + price) ÷ N;
  • LWMA: weights N … 1, the newest heaviest.

One line (number 0), so a read names no line: ma[1]. First value on bar N − 1 (N − 1 + Shift with a Shift). This indicator's EMA and SMMA start from the SMA of the first N bars of the history the run loaded, then recur; the EMAs inside the other indicators on these pages start from the first price instead. The LWMA keeps its own running sums (the linear-weighted drift). EMA and SMMA are recursive (recursive indicators).

MA(period, shift, method, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars1 – 2,500 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Methodmethod, 3rdSmaSma, Ema, Smma, LwmaNo
Applied PriceappliedPrice, 4thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

Reading it in a rule. ma[0] in a candle-close rule (ma[1] in an On Tick rule) is the average on the last closed bar; fast crosses above slow is the classic cross. With a Shift above 0, [0] is a closed bar's value. A shift written in the strategy cannot be a shared parameter, so a look-back you want to optimize is a Moving Average of period 1 whose Shift is the parameter: MA(1, lookback, sma, close) is the close lookback bars back.

Verified value by value against an independent reference (the record).

Parabolic SAR

SAR in the strategy text · one line over the candles

Wilder's stop-and-reverse level: under the price in an uptrend and over it in a downtrend, closing in as the trend extends. Each bar the line moves toward the trend's extreme point by the acceleration factor, SAR + AF × (EP − SAR), never inside the previous two bars' range; each new extreme adds Step to the factor up to Maximum; a cross reverses the trend, the line jumps to the extreme of the trend that ended and the factor goes back to Step. One line (number 0), so a read names no line: sar[1].

It has two methods, chosen in the Method field:

  • Wilder, the default: the first trend comes from the first two closes (up if the close is at or above the previous close), the line starts at the previous bar's low (up) or high (down), the extreme point is the two bars' highest high or lowest low, and the line has a value from bar 1. A bar is tested after the line has moved and been kept out of the last two bars' range, and the factor stops at Maximum.
  • MetaTrader: no value until the first bar whose high and low are both above, or both below, the previous bar's (on a market that never moves cleanly the line never starts); each bar is tested against the line as it stands, then the line moves (the move rounded once) and is kept out of the last two bars' range, and the bar is tested again; the factor grows only while the grown factor stays at or below Maximum.
  • The two differ mostly on the bar after a reversal: when that bar crosses the reversal level but not the reversal bar's own extreme, the MetaTrader method reverses again at once and Wilder does not, and the lines meet again later.

SAR(step, maximum, method), the method wilder or metaTrader; written without a method, SAR(step, maximum) is the Wilder method:

FieldIn the textDefaultValuesCan be swept
Stepstep, 1st0.020 – 1Yes
Maximummaximum, 2nd0.20 – 1Yes
Methodmethod, 3rdWilderWilder, MetaTraderNo

The table's bounds are not the whole rule: Step must be above 0 and Maximum at least Step and below 1, so a Step of 0 and a Maximum of 1 are refused when you save. The warm-up is sized so the starting bias is below one millionth, (1 − Step)^n ≤ 1e-6, and at least 64 bars; a Step so small that this warm-up passes 2,500 bars is refused when you save.

Reading it in a rule. close > sar holds while the trend is up; close crosses below sar is a reversal down.

Verified value by value against an independent reference (the record).

Standard Deviation

StdDev in the strategy text · one line in a pane of its own

How far the last N applied prices stray from their moving average: the square root of their mean squared distance from it, √(Σ (price − average)² ÷ N). In price units, never below 0.

  • One line (number 0), so a read names no line: stdDev[1]. First value on bar N − 1 for every method (N − 1 + Shift with a Shift).
  • The average is SMA, EMA, SMMA or LWMA (the exponential one from the first price), and the squared distances are added oldest first.
  • The linear-weighted method slides its sums (the linear-weighted drift).

StdDev(period, shift, method, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st20 bars2 – 2,500 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Methodmethod, 3rdSmaSma, Ema, Smma, LwmaNo
Applied PriceappliedPrice, 4thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The period is at least 2: a deviation over one bar is always 0.

Reading it in a rule. A volatility in price units: sd > sd[20] is volatility higher than 20 bars ago. A flat market reads 0.

Verified value by value against an independent reference (the record).

TEMA

TEMA in the strategy text · one line over the candles

The Triple Exponential Moving Average: TEMA = 3 × EMA1 − 3 × EMA2 + EMA3, three exponential averages of period N in a row (EMA2 averages EMA1, EMA3 averages EMA2). Even less lag than DEMA; it overshoots sharp turns.

  • One line (number 0), so a read names no line: tema[1]. The averages start on bars 0, N − 1 and 2N − 2 from the previous stage's value there.
  • First value on bar 3 × (N − 1) (plus Shift with a Shift); the bars before it have no value.
  • It is recursive (recursive indicators).

TEMA(period, shift, appliedPrice):

FieldIn the textDefaultValuesCan be swept
Periodperiod, 1st14 bars2 – 834 barsYes
Shiftshift, 2nd0 bars0 – 1,000 barsNo
Applied PriceappliedPrice, 3rdCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The period is at least 2 and at most about a third of 2,500, since three averages run in a row.

Reading it in a rule. tema[0] is the bar that just closed; in an On Tick rule, the bar in progress so far. With a Shift above 0 it is a closed bar's value.

Verified value by value against an independent reference (the record).

Variable Index Dynamic Average

VIDYA in the strategy text · one line over the candles

Chande's dynamic average: an exponential average whose pace follows momentum. The Chande Momentum Oscillator over the last N bar-to-bar moves is (rises − falls) ÷ (rises + falls); the factor is f = 2 ÷ (EMA period + 1) × |CMO|, and VIDYA = price × f + previous × (1 − f). The line follows a one-way market at the full exponential pace and stands still where rises and falls balance.

  • One line (number 0), so a read names no line: vidya[1]. Its first value, on bar N + 2 (N + 2 + Shift with a Shift), is that bar's price; the steps start on the bar after.
  • A window of N moves that are all zero reads |CMO| = 1: the line moves at the full pace toward a price that did not move.
  • It is recursive, and a bar whose rises and falls balance leaves the starting price's share where it was, so no bound on how fast the start fades holds in general (recursive indicators).

VIDYA(cmoPeriod, emaPeriod, shift, appliedPrice):

FieldIn the textDefaultValuesCan be swept
CMO PeriodcmoPeriod, 1st9 bars1 – 2,497 barsYes
EMA PeriodemaPeriod, 2nd12 bars1 – 2,500 barsYes
Shiftshift, 3rd0 bars0 – 1,000 barsNo
Applied PriceappliedPrice, 4thCloseClose, Open, High, Low, Median, Typical, Weighted, VolumeNo

The first value needs CMO period + 3 bars of history, so that period stops three bars short of 2,500.

Reading it in a rule. vidya[0] is the bar that just closed; in an On Tick rule, the bar in progress so far. With a Shift above 0 it is a closed bar's value.

Verified value by value against an independent reference (the record).

Questions?support@algotradinghub.io

Last updated Nov 15, 2026© 2026 AlgoTradingHub