forge.ta

Forge API 1

Indicator functions, their classes and the missing-value helpers (contract C3).

Naming convention (04 IND-029, written once): functions are short and lower case (``ta.rsi``); indicator classes are CapWords (``RSI``); PEP 8 throughout; parameters run source first, then periods, then methods (``ta.ma(source, period, method)``), the order MetaTrader 5 uses.

Missing values are ``NaN`` in arrays and ``None`` for a scalar that has no value (contract C1 section 2). ``fg.nz`` and ``fg.isna`` resolve here, so strategies and indicators share one missing-value helper (contract C2 section 1).

Time: bar times are ``bars.time`` (open) and ``bars.time_close``, int64 nanoseconds UTC (contract C1 section 2). ``ta.hour``, ``ta.dayofweek`` and ``ta.month`` read them in a zone and ``ta.timestamp`` builds one. On non-time bars (Renko and the like) a bar's own times are not the market's, so read ``bars.real.time`` for time logic (IND-194).

Built-in library: every function is ``forge_indicators.<name>``, and every class wraps one and is generated from ``forge_indicators.REGISTRY`` (contract C3 section 4). ``ta.sma`` is the package's function, so the moving average on a chart is the one that was tested.

NameKindSummary
isnafunctionTrue where a value is missing: ``None`` or ``NaN``.
nzfunctionReplace a missing value with ``value`` (default 0).
ACclassHow fast the Awesome oscillator is speeding up or slowing down.
ADRclassThe average high to low range of recent trading days.
ADXclassHow strong the trend is, whatever its direction.
ALMAclassGaussian weighted average whose peak you can move toward the newest bar.
AOclassMomentum from the gap between a fast and a slow average of the median price.
ATRclassThe average true range over a period, Wilder smoothed or simple.
AccDistclassVolume weighted by where the close sits in the bar.
AlligatorclassThree smoothed lines that show when a trend is asleep or waking up.
AroonclassHow recently the highest high and the lowest low happened.
BWMFIclassPrice range per unit of volume, with Bill Williams' four colours.
BearsPowerclassThe bar's low against an EMA of closes.
BollingerBandsclassA moving average with bands set by the standard deviation.
BollingerPercentBclassWhere the price sits between the Bollinger Bands.
BollingerWidthclassThe distance between the Bollinger Bands relative to the middle line.
BullsPowerclassThe bar's high against an EMA of closes.
CCIclassDistance from the average in units of mean deviation.
CMOclassUp moves against down moves over a period, from -100 to 100.
ChaikinOscillatorclassThe fast average of A/D minus its slow average.
ChangeclassValue now minus the value a number of bars ago.
CumclassThe total of every value from the first bar.
DEMAclassExponential average with part of its lag removed.
DMIclassTrend direction as two lines, with the strength of the trend.
DarkCloudCoverclassA fall that closes deep into the previous rise.
DeMarkerclassPressure from higher highs against lower lows, from 0 to 1.
DelayclassThe series moved a number of bars back.
DojiclassA bar whose body is tiny against its range.
DonchianclassHighest high and lowest low of the last N bars, with their midpoint.
DragonflyDojiclassA doji that opens and closes near its high.
EMAclassAverage that weights recent values more, each step closing part of the gap to the price.
EfficiencyRatioclassHow directly the price moved: 1 for a straight line, near 0 for noise.
EngulfingclassA body that covers the previous opposite body.
EnvelopesclassA moving average with a band a set distance above and below it.
EveningDojiStarclassAn evening star whose middle bar is a doji.
EveningStarclassA long rise, a small star, then a fall into the rise.
FRAMAclassAverage that follows trends closely and flattens in chop, from the fractal dimension.
FairValueGapsclassThree-candle imbalances, shown until price fills them.
FallingclassTrue after a number of falls in a row.
ForceIndexclassVolume times the change of a moving average of price.
FractalsclassSwing highs and lows, shown two bars after they form.
GatorclassHow far apart the Alligator's jaw, teeth and lips are.
GravestoneDojiclassA doji that opens and closes near its low.
HMAclassFast, smooth average built from two weighted averages.
HammerclassA long lower wick after a fall.
HangingManclassA long lower wick after a rise.
HaramiclassA small body inside the previous long body.
HeikinAshiclassSmoothed candles that make trends easier to read.
HighestclassThe highest value over a number of bars.
HighestBarsclassHow many bars ago the highest value of the window was.
IchimokuclassFive lines that show trend, momentum and support in one view.
InsideBarclassA bar whose range sits within the previous bar's range.
InvertedHammerclassA long upper wick after a fall.
KAMAclassAverage that speeds up when the price trends and slows down when it chops.
KeltnerclassAn EMA with bands set by the average true range.
KeltnerWidthclassThe distance between the Keltner bands relative to the middle line.
KillzonesclassNamed session windows, each in its own time zone, shaded on the chart and usable as filters.
LinRegclassLeast squares line fitted to the last N values, read at the newest bar.
LinRegInterceptclassWhere the fitted line starts, at the oldest bar of the window.
LinRegSlopeclassHow much the fitted line rises or falls per bar.
LiquidityclassEqual highs and lows (EQH, EQL), resting liquidity above swing highs and below swing lows, and the sweeps that take it.
LogReturnclassThe natural log of the value over the previous value.
LowestclassThe lowest value over a number of bars.
LowestBarsclassHow many bars ago the lowest value of the window was.
MAclassAny of the eight moving averages, chosen by name.
MACDclassThe gap between a fast and a slow EMA, with a signal line and histogram.
MFIclassRSI built from price times volume, from 0 to 100.
MarketStructureclassConfirmed swings labelled HH, HL, LH and LL, with breaks of structure (BOS) and changes of character (CHoCH), for internal and swing structure.
MarubozuclassA bar with almost no wicks, rising or falling.
MedianclassMiddle value of the last N values, so one spike cannot move it.
MidPointclassHalfway between the highest and lowest value of a window.
MidPriceclassHalfway between the highest high and the lowest low of a window.
MomentumclassPrice now against price a number of bars ago.
MorningDojiStarclassA morning star whose middle bar is a doji.
MorningStarclassA long fall, a small star, then a rise into the fall.
OBVclassVolume added on up closes and taken away on down closes.
OpeningRangeclassThe high and low of the first minutes of a session, with breakout signals.
OrderBlocksclassThe last opposite candle before a break of structure, kept until price trades back through it.
OsMAclassThe MACD histogram: MACD minus its signal line.
OutsideBarclassA bar whose range covers the previous bar's range.
PercentRankclassWhere the value sits among its previous values, from 0 to 100.
PeriodOpenclassThe opening price of the current day, week or month.
PiercingclassA rise that closes deep into the previous fall.
PivotHighclassA swing high, shown once enough bars after it prove it was the highest.
PivotLowclassA swing low, shown once enough bars after it prove it was the lowest.
PivotPointsclassSupport and resistance levels projected from the previous day, week or month.
PremiumDiscountclassThe upper and lower halves of the active swing range, split at equilibrium.
PriorLevelsclassThe previous day, week or month open, high, low and close (PDH, PDL), carried forward.
RMAclassWilder's smoothing: a slow average seeded with the mean of the first N values.
ROCclassChange over a number of bars as a percent, fraction or ratio.
RSIclassMomentum bounded 0 to 100, from average gains against average losses.
RVIclassThe close against the open, scaled by the range, with a signal line.
RisingclassTrue after a number of rises in a row.
SARclassTrailing stop-and-reverse level that speeds up as the trend runs.
SMAclassAverage of the last N values, each weighted equally.
SessionRangeclassThe high and low of the Asia, London and New York sessions, boxed while each runs.
ShootingStarclassA long upper wick after a rise.
SpinningTopclassA small body with a longer wick on each side.
StdDevclassHow far values spread around their average over a period.
StochRSIclassThe stochastic oscillator applied to RSI.
StochasticclassWhere the close sits in the recent high to low range, with a signal line.
SumclassThe sum of the last values over a number of bars.
SuperTrendclassTrend-following line built from the average true range.
TEMAclassExponential average with most of its lag removed.
TRIXclassThe one-bar change of a triple smoothed EMA.
ThreeBlackCrowsclassThree falling bars, each opening inside the last body.
ThreeInsideclassA harami confirmed by the third bar.
ThreeOutsideclassAn engulfing confirmed by the third bar.
ThreeWhiteSoldiersclassThree rising bars, each opening inside the last body.
TrueRangeclassThe largest of the bar's range and its gaps from the previous close.
VIDYAclassExponential average that speeds up when momentum is strong.
VWAPclassThe average price weighted by volume since the session, week, month or a chosen time.
VWMAclassAverage that weights each price by the volume traded at it.
VarianceclassThe square of the standard deviation over a period.
VolumesclassVolume per bar, tick or real as the feed carries it.
WMAclassAverage that weights the newest value N times and the oldest once.
WilliamsRclassWhere the close sits in the recent range, from 0 down to -100.
ZigZagclassSwing highs and lows, each shown only once a reversal has confirmed it.
acfunctionAccelerator oscillator: the Awesome oscillator minus its own ``signal_period`` average.
accdistfunctionAccumulation and distribution: a running total of volume weighted by the close's position.
adrfunctionAverage daily range: the mean high to low range of the last ``days`` finished trading days.
adxfunctionThe ADX line of ``dmi``: how strong the trend is, whatever its direction.
alligatorfunctionBill Williams' Alligator: ``jaw``, ``teeth`` and ``lips``.
almafunctionArnaud Legoux average: Gaussian weights over ``window`` bars.
aofunctionAwesome oscillator: the fast average of the median price minus the slow one.
aroonfunctionAroon: how recently the highest high and the lowest low of the last ``period + 1`` bars came.
atrfunctionAverage true range, Wilder smoothed (``wilder``) or a simple mean (``sma``).
barssincefunctionHow many bars ago the condition last held: 0 on a bar where it holds.
bbfunctionBollinger Bands: a simple average with bands ``deviations`` population deviations away.
bb_percentfunctionBollinger Bands %B: ``(source - lower) / (upper - lower)``.
bbwfunctionBollinger Bands width: ``(upper - lower) / middle``.
bears_powerfunctionBears power: the bar's low minus an EMA of the closes.
bulls_powerfunctionBulls power: the bar's high minus an EMA of the closes.
bw_mfifunctionMarket facilitation index: ``mfi = (high - low) / volume``, in price units.
ccifunctionCommodity channel index: distance from the average in units of mean deviation.
chaikin_oscfunctionChaikin oscillator: the fast average of accumulation and distribution minus the slow one.
changefunctionValue now minus the value ``period`` bars ago.
cmofunctionChande momentum oscillator: up moves against down moves over ``period`` bars, -100 to 100.
correlationfunctionRolling correlation of two series over the last ``period`` bars, from -1 to 1.
crossfunction1 on a bar where ``a`` crosses above ``b``, -1 where it crosses below, 0 elsewhere.
crossoverfunctionTrue on the bar where ``a`` goes from at or below ``b`` to above it.
crossunderfunctionTrue on the bar where ``a`` goes from at or above ``b`` to below it.
cumfunctionThe running total of the source from the first bar.
dark_cloud_coverfunctionDark cloud cover: a fall that closes deep into the previous rise.
dayofweekfunctionThe weekday of ``t`` in ``tz``, Monday 0 to Sunday 6 (the engine clock's convention).
delayfunctionThe source ``n`` bars ago: ``value[i] = source[i - n]``.
demafunctionDouble exponential average: ``2 * EMA - EMA(EMA)``, the second stage seeded at bar ``period - 1``.
demarkerfunctionDeMarker: pressure from higher highs against lower lows, from 0 to 1.
dmifunctionDirectional movement: ``plus_di``, ``minus_di`` and ``adx``.
dojifunctionDoji: a bar whose body is tiny against its range.
donchianfunctionDonchian channel: highest high and lowest low of the last ``period`` bars, and their mean.
dragonfly_dojifunctionDragonfly doji: a doji that opens and closes near its high.
efficiency_ratiofunctionNet move over ``period`` bars divided by the path length.
emafunctionExponential average: ``k = 2 / (period + 1)``, seeded with the first price.
engulfingfunctionEngulfing: a body that covers the previous opposite body.
envelopesfunctionA moving average with a band above and below it.
evening_doji_starfunctionEvening doji star: an evening star whose middle bar is a doji.
evening_starfunctionEvening star: a long rise, a small star, then a fall into the rise.
fair_value_gapsfunctionThree-candle gaps, newest first in five slots per side, until price fills them.
fallingfunctionTrue when each of the last ``period`` bars is below the bar before it.
forcefunctionForce index: the volume times the change of a moving average of the price.
fractalsfunctionWilliams fractals: ``up`` (swing high) and ``down`` (swing low), written two bars late.
framafunctionFractal adaptive average of the close (Ehlers).
gatorfunctionGator oscillator: the gaps between the Alligator's lines, above and below 0.
gravestone_dojifunctionGravestone doji: a doji that opens and closes near its low.
hammerfunctionHammer: a long lower wick after a fall.
hanging_manfunctionHanging man: a long lower wick after a rise.
haramifunctionHarami: a small body inside the previous long body.
heikin_ashifunctionHeikin-Ashi candles: ``ha_open``, ``ha_high``, ``ha_low`` and ``ha_close``.
highestfunctionThe highest value of the last ``period`` bars, the current bar included.
highest_barsfunctionHow many bars ago the highest value of the last ``period`` bars was, 0 for the current bar.
hmafunctionHull average: ``wma(2 * wma(x, half) - wma(x, period), root)``.
hourfunctionThe hour (0 to 23) of nanosecond UTC times ``t`` in the zone ``tz``.
ichimokufunctionTenkan, kijun, senkou A and B, and chikou, undisplaced.
inside_barfunctionInside bar: a bar whose range sits within the previous bar's range.
inverted_hammerfunctionInverted hammer: a long upper wick after a fall.
kamafunctionKaufman adaptive average.
kcfunctionKeltner channel: an EMA of closes with bands ``atr_factor`` average true ranges away.
kcwfunctionKeltner channel width: ``(upper - lower) / middle``.
killzonesfunctionFour named windows, each true on the bars that open inside it.
linregfunctionThe regression line at the newest bar of the window: ``a + b * (period - 1)``.
linreg_interceptfunctionThe regression line at the oldest bar of the window.
linreg_slopefunctionThe slope of the regression line: its change per bar.
liquidityfunctionEqual highs and lows, resting liquidity above swing highs and below swing lows, and sweeps.
log_returnfunctionThe natural log of the value over the previous value: ``ln(source[i] / source[i-1])``.
lowestfunctionThe lowest value of the last ``period`` bars, the current bar included.
lowest_barsfunctionHow many bars ago the lowest value of the last ``period`` bars was, 0 for the current bar.
lwmafunctionLinearly weighted average: weight ``period`` on the newest value down to 1 on the oldest.
mafunctionThe moving average named by ``method``: one of sma, ema, smma, lwma, wma, hma, dema, tema.
macdfunctionMACD: the fast EMA minus the slow EMA, its signal line and the gap between them.
market_structurefunctionSwings labelled HH, HL, LH and LL, with breaks of structure and changes of character.
marubozufunctionMarubozu: a bar with almost no wicks.
max2functionThe larger of two series bar by bar, or of a series and a number.
medianfunctionMedian of the last ``period`` values.
mfifunctionMoney flow index: RSI built from the typical price times volume, from 0 to 100.
midpointfunctionHalfway between the highest and the lowest value of the last ``period`` bars.
midpricefunctionHalfway between the highest high and the lowest low of the last ``period`` bars.
min2functionThe smaller of two series bar by bar, or of a series and a number.
momfunctionPrice now against price ``period`` bars ago.
monthfunctionThe month (1 to 12) of ``t`` in ``tz``.
morning_doji_starfunctionMorning doji star: a morning star whose middle bar is a doji.
morning_starfunctionMorning star: a long fall, a small star, then a rise into the fall.
obvfunctionOn-balance volume: a running total that starts with the first bar's volume.
opening_rangefunctionThe high and low of the first minutes of a session, and the closes that cross them.
order_blocksfunctionThe last opposite candle before each break of structure, kept until price goes through it.
osmafunctionOsMA: the MACD line minus its signal line.
outside_barfunctionOutside bar: a bar whose range covers the previous bar's range.
percentrankfunctionThe share of the previous ``period`` values at or below the current value.
period_openfunctionThe open of the current day, week or month on every bar of it.
piercingfunctionPiercing line: a rise that closes deep into the previous fall.
pivot_highfunctionThe high of a swing high, written ``right`` bars after the swing.
pivot_lowfunctionThe low of a swing low, written ``right`` bars after the swing (the mirror of pivot_high).
pivot_pointsfunctionPivot points for ``kind`` from the previous ``period`` (``D``, ``W`` or ``M``).
premium_discountfunctionThe upper and lower halves of the active swing range, split at equilibrium.
prior_levelsfunctionThe previous day's, week's or month's open, high, low and close on every bar.
risingfunctionTrue when each of the last ``period`` bars is above the bar before it.
rmafunctionWilder's smoothed average: seeded with the mean of the first ``period`` values.
rocfunctionChange over ``period`` bars, as a percent, a fraction or a ratio.
rsifunctionRelative strength index from average gains against average losses, 0 to 100.
rvifunctionRelative vigor index: the close against the open, scaled by the range, with a signal line.
sarfunctionParabolic stop and reverse.
session_rangefunctionThe Asia, London and New York sessions: a box while each runs, its levels once it ends.
shooting_starfunctionShooting star: a long upper wick after a rise.
smafunctionMean of the last ``period`` values, each window summed from scratch.
smmafunctionWilder's smoothed average: seeded with the mean of the first ``period`` values.
spinning_topfunctionSpinning top: a small body with a longer wick on each side.
stdevfunctionStandard deviation of the last ``period`` values around their moving average at this bar.
stochfunctionStochastic oscillator: ``k`` is the slowed %K and ``d`` its simple average.
stoch_rsifunctionThe stochastic oscillator applied to the relative strength index.
sumfunctionThe sum of the last ``period`` values.
supertrendfunctionSuperTrend: a line ``factor`` average true ranges from the bar's midpoint that only ratchets.
temafunctionTriple exponential average: ``3 * E1 - 3 * E2 + E3``.
three_black_crowsfunctionThree black crows: three falling bars, each opening inside the last body.
three_insidefunctionThree inside: a harami confirmed by the third bar.
three_outsidefunctionThree outside: an engulfing confirmed by the third bar.
three_white_soldiersfunctionThree white soldiers: three rising bars, each opening inside the last body.
timestampfunctionNanoseconds UTC of a local time in ``tz``.
trfunctionTrue range: the bar's range widened to take in the gap from the previous close.
trixfunctionTRIX: the one-bar change of a triple smoothed EMA, as a fraction and not a percent.
valuewhenfunctionThe source on the bar where the condition last held, or the ``occurrence``-th time before.
variancefunctionVariance: the mean squared distance of the last ``period`` values from their average.
vidyafunctionChande's variable index dynamic average.
volumesfunctionThe volume of each bar, and whether it is above the previous bar's.
vwapfunctionVolume-weighted average price from each anchor, with bands at its weighted deviation.
vwmafunctionVolume weighted average: ``sum(price * volume) / sum(volume)`` over the last ``period`` bars.
wilderfunctionWilder's smoothed average: seeded with the mean of the first ``period`` values.
wmafunctionLinearly weighted average: weight ``period`` on the newest value down to 1 on the oldest.
wprfunctionWilliams %R: where the close sits in the recent range, from 0 down to -100.
zigzagfunctionSwing highs and lows, written only once a reversal confirms them.