Skip to content

More indicators with TAP

TAP is the technical-analysis library behind the supplied indicator functions. In Python you can also import its Atom-compatible interface explicitly. This gives you access to functions beyond the small set automatically supplied as strategy globals.

Use tap.atom for Atom price series and bars. It adapts results to the same [0] current / [1] previous convention used throughout this Python guide. The top-level tap interface and its utility functions have different input/output conventions; do not substitute them into these examples.

Injected functions and explicit imports

Choose a style deliberately. The supplied component helpers are convenient for a single line. An explicit TAP call gives you the original indicator result, which can contain several lines.

Inside a Python strategy Result
macd(close, 12, 26, 9) The supplied MACD line series.
macd_signal(close, 12, 26, 9) The supplied signal-line series.
ta.macd(close, 12, 26, 9) after import tap.atom as ta A container with macd, signal, histogram series.
adx(bars, 14) The supplied ADX line series.
ta.adx(bars, 14) A container with adx, plus_di, minus_di series.
ta.rsi(close, period=14) A single RSI series; [0] reads now.

Use a namespace alias such as ta to make the explicit style visible. Importing macd directly over the supplied name changes its return shape to the container version.

Read several lines from one result

After import tap.atom as ta, the following fragment belongs inside on_tick() once there is enough valid input history:

import tap.atom as ta

result = ta.macd(close, fast_period=12, slow_period=26, signal_period=9)
macd_now = result["macd"][0]
signal_now = result["signal"][0]
histogram_now = result["histogram"][0]

The string key selects a line; the integer selects a history offset within that line. result["signal"][1] is the previous signal reading. Do not compare the entire container with a threshold or assume result[0] means its current numeric value.

Other multi-line results use their own named keys:

Explicit call Selectable keys
ta.bollinger_bands(close, 20, 2) upper, middle, lower
ta.stochastic(bars, 14, 3) k, d
ta.aroon(bars, 25) aroon_up, aroon_down, aroon_oscillator
ta.donchian_channel(bars, 20) upper, middle, lower
ta.keltner_channel(bars, 20, 10, 2) upper, middle, lower
ta.trix(close, 14, 9) trix, signal
ta.supertrend(bars, period=10, multiplier=3) supertrend, upper_band, lower_band, direction

A result container is a set of calculations, not a set of order instructions. Its direction or price line affects trading only through a rule you write.

A complete Supertrend strategy

Supertrend is available through an explicit TAP import even though it is not one of the automatically supplied TradeScript functions. This example requests ten units while the calculated direction is positive and exits a long when it turns negative.

from math import isfinite
import tap.atom as ta

symbol = "TCS"

def on_tick():
    if len(close) < 30:
        return
    result = ta.supertrend(bars, period=10, multiplier=3.0)
    direction = result["direction"][0]
    level = result["supertrend"][0]
    if not (isfinite(direction) and isfinite(level)):
        return
    if position.is_flat and direction > 0:
        long(10)
    elif position.is_long and direction < 0:
        close()

period=10 controls the ATR window; multiplier=3.0 controls its band distance. direction is +1 or −1 after valid initialisation. level is a price; reading it does not place a protective stop. The 30-bar guard and finite checks keep this example out of its initial missing-value region, but are not a universal warmup rule for other calculations.

This is a state-based entry and exit, not a crossing-only event. It does not add another ten units on every positive-direction bar because entry requires a flat position. The script declares no separate price stop.

How broad is the library?

The checked TAP source catalog contains 198 entries: 166 core indicators and 32 utilities. Its Atom-compatible namespace exports 162 callable names, including aliases. That export count is a different surface from the source catalog; not every core entry or utility is an Atom-compatible function.

The platform automatically supplies 42 selected base names and 17 component functions. An explicit Python import can reach additional Atom-compatible exports in the installed TAP version. This does not make those names available as TradeScript shorthand, and it does not mean every exported function has been verified as a causal trading signal.

Some functions return a price series, some return multiple lines, and some perform pattern or whole-history analysis. Before using an additional function, check its actual arguments, output keys, required fields and whether its historical values use later observations. A function being importable is not sufficient evidence that it can be used unchanged in an on-bar signal.

If an import or calculation fails

  • Import fails: the running environment must include the Invsto TAP integration; another package named tap is not a substitute. There is no installation command to paste into a strategy.
  • High, low or volume is missing: pass bars and confirm those fields are supplied. A single close series cannot supply other market fields.
  • A comparison fails on a container: select a named line first, then read its current value.
  • Readings are missing: check the actual lookback and input values. The known modified_rsi missing-reading issue affects both supplied and explicitly imported forms; extra warmup does not fix it.
  • Python gives a different result from TradeScript: compare the same input bars, settings and selected component. A supplied primary line and a raw multi-line result are different objects.

For normal day-to-day calls, return to the Python indicator library. For position quantity and order behaviour, see open and close positions.