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
| Parameter | Required | Description |
|---|---|---|
| indicator Name | ✔ | Name of the indicator to compute. |
| name | ✔ | Attribute name to access later (self.<name>). |
**kwargs | depends | Inputs specific to the indicator (many accept callables). |
| Return | depends | Returns value if called outside |
Supported Indicators & Required Kwargs
Below is a complete list of supported indicators, their keyword arguments, and return types:
| Indicator Name | Required Kwargs |
|---|---|
sma / ema | close, length |
rsi | close, length |
macd | close, fast, slow, signal |
vwap | df (OHLCV) |
supertrend | high, low, close, length, multiplier |
parabolicSAR | high, low, start, increment, maximum |
cci | df, length, constant |
bbands | close, length, stdDev, mode |
stoch_oscillator | high, low, close, k, d, smooth_k |
stoch_rsi | close, length, rsi_length, k, d |
adx | high, low, close, length, length_signal |
donchian_channels | high, low, length |
williams_R | high, low, close, length |
fisher_transform | high, low, length |
hl2 / hlc3 | df |
prevDaysRange | df, currentDay, prevDays |
pivotpoints | df, currentDay |
orb | df, currentDay, length |
heikenashi | df |
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.