Skip to main content

Indicators

The Indicators system in Buildalgos.com lets you define and cache technical indicators declaratively using applyIndicator(). You typically register them once in indicator_init() and then access the computed series via named attributes like self.<name>.

applyIndicator – Syntax & Parameters

def applyIndicator(
self,
indicatorName: str,
*,
name: str,
**kwargs
) -> pandas.Series | pandas.DataFrame
ParameterRequiredDescription
indicator NameName of the indicator to compute.
nameAttribute name to access later (self.<name>).
**kwargsdependsInputs specific to the indicator (many accept callables).
Returndepends

Returns value if called outside indicator_init();
otherwise stores to self.<name>.

Supported Indicators & Required Kwargs

Below is a complete list of supported indicators, their keyword arguments, and return types:

Indicator NameRequired Kwargs
sma / emaclose, length
rsiclose, length
macdclose, fast, slow, signal
vwapdf (OHLCV)
supertrendhigh, low, close, length, multiplier
parabolicSARhigh, low, start, increment, maximum
ccidf, length, constant
bbandsclose, length, stdDev, mode
stoch_oscillatorhigh, low, close, k, d, smooth_k
stoch_rsiclose, length, rsi_length, k, d
adxhigh, low, close, length, length_signal
donchian_channelshigh, low, length
williams_Rhigh, low, close, length
fisher_transformhigh, low, length
hl2 / hlc3df
prevDaysRangedf, currentDay, prevDays
pivotpointsdf, currentDay
orbdf, currentDay, length
heikenashidf

Why Use lambda for Inputs?

Use callables (like lambda: self.dt_SPOT['close']) instead of static series so that:

  • Data is evaluated on-demand, per-bar.
  • You always get the up-to-date value from the right bar in live or backtest mode.
  • It supports efficient caching and avoids unnecessary recomputation

Example:

def indicator_init(self):
# Register 21-period EMA of close prices
self.applyIndicator(
indicatorName="ema",
name="ema_21",
close=lambda: self.dt_SPOT["close"],
length=21
)

# Register MACD
self.applyIndicator(
indicatorName="macd",
name="macd_main",
close=lambda: self.dt_SPOT["close"],
fast=12,
slow=26,
signal=9
)

Now use:

if self.ema_21.iloc[-1] > self.dt_SPOT["close"].iloc[-1]:
# your logic here

Custom Indicators

You can create custom indicators using only Pandas and NumPy to ensure maximum compatibility and performance with the framework.