Skip to content

Events#

Additional functions that attempt to identify states (above/below) or events (crossing).




Above

Determines if each x value is above (or >=) each y value.

Parameters:

Name Type Description Default
x Series

x

required
y Series

y

required
asint bool

Returns as Int.

True
offset Int

Post shift. Default: 0

None

Returns:

Type Description
Series

State where x >= y.

Example
x = Series([4, 2, 0, -1, 1])
y = Series([1, 1, 1, 1, 1])

x_above_y = ta.above(x, y)
# x_above_y = Series([1, 1, 0, 0, 1])




Above Value

Determines if each x value is above (or >=) a constant value.

Parameters:

Name Type Description Default
x Series

x

required
value IntFloat

Value to compare with x.

required
asint bool

Returns as Int.

True

Returns:

Type Description
Series

State where x >= y.

Example
x = Series([4, 2, 0, -1, 1])
x_above_1 = ta.above_value(x, 1)
# x_above_1 = Series([1, 1, 0, 0, 1])




Below

Determines if each x value is below (or <=) each y value.

Parameters:

Name Type Description Default
x Series

x

required
y Series

y

required
asint bool

Returns as Int.

True
offset Int

Post shift. Default: 0

None

Returns:

Type Description
Series

State where x <= y.

Example
x = Series([4, 2, 0, -1, 1])
y = Series([1, 1, 1, 1, 1])

x_below_y = ta.below(x, y)
# x_below_y = Series([0, 0, 1, 1, 1])




Below Value

Determines if each x value is below (or <=) a constant value.

Parameters:

Name Type Description Default
x Series

x

required
value IntFloat

Value to compare with x.

required
asint bool

Returns as Int.

True
offset Int

Post shift. Default: 0

None

Returns:

Type Description
Series

State where x <= y.

Example
x = Series([4, 2, 0, -1, 1])
x_below_1 = ta.below_value(x, 1)
# x_below_1 = Series([0, 0, 1, 1, 1])


NOTICE

Thanks to all those that have sponsored and dontated to the library in the past! Your support has been greatly appreciated! 🙏

However, future releases are on definite hold until 100+ donations of $150+ have been received via Buy Me a Coffee.

Help keep this library and application the best in it's class!




Cross

Determines where x crosses y, either above or below, strictly (equal) or not.

Parameters:

Name Type Description Default
x Series

x

required
y Series

y

required
above bool

Check above. Check below, set above=False

True
equal bool

At least/most, =, check.

True
asint bool

Returns as Int.

True
offset Int

Post shift. Default: 0

None

Returns:

Type Description
Series

Values where x crosses y.

Example
x = Series([4, 2, 0, -1, 1])
y = Series([1, 1, 1, 1, 1])

# Cross Above Examples
x_xae_y = ta.cross(x, y, above=True, equal=True)
# x_xae_y = Series([0, 0, 0, 0, 1])

x_xa_y = ta.cross(x, y, above=True, equal=False)
# x_xa_y = Series([0, 0, 0, 0, 0])

# Cross Below Examples
x_xbe_y = ta.cross(x, y, above=False, equal=True)
# x_xbe_y = Series([0, 0, 1, 0, 1])

x_xb_y = ta.cross(x, y, above=False, equal=False)
# x_xb_y = Series([0, 0, 1, 0, 0])




Cross Value

Determines where x crosses a constant value, either above or below, strictly (equal) or not.

Parameters:

Name Type Description Default
x Series

x

required
value IntFloat

Value to compare with x.

required
above bool

Check above. Check below, set above=False

True
equal bool

At least/most, =, check.

True
asint bool

Returns as Int.

True
offset Int

Post shift. Default: 0

None

Returns:

Type Description
Series

Values where x crosses y.

Example
x = Series([4, 2, 0, -1, 1])

# Cross Above Examples
x_xae_y = ta.cross_value(x, 1, above=True, equal=True)
# x_xae_y = Series([0, 0, 0, 0, 1])

x_xa_y = ta.cross_value(x, 1, above=True, equal=False)
# x_xa_y = Series([0, 0, 0, 0, 0])

# Cross Below Examples
x_xbe_y = ta.cross_value(x, 1, above=False, equal=True)
# x_xbe_y = Series([0, 0, 1, 0, 1])

x_xb_y = ta.cross_value(x, 1, above=False, equal=False)
# x_xb_y = Series([0, 0, 1, 0, 0])




Trend Signals

This function creates Trend, Trades, Entries and Exit values per bar when given a trend condition e.g. trend = close > sma(close, 50).

Source
  • Kevin Johnson

Parameters:

Name Type Description Default
trend Series

trend Series. Boolean or integer values of 0 and 1

required
asbool bool

Return booleans. Default: False

None
trade_offset value

Shift trade entries/exits with live: 0 and backesting: 1. Default: 0

None
drift int

Difference amount. Default: 1

None
offset int

Post shift. Default: 0

None

Other Parameters:

Name Type Description
fillna value

pd.DataFrame.fillna(value)

Returns:

Type Description
DataFrame

4 columns

Column Detail
  • Trends (trend: 1, no trend: 0)
  • Trades (Enter: 1, Exit: -1, Otherwise: 0)
  • Entries (entry: 1, nothing: 0)
  • Exits (exit: 1, nothing: 0)
Details

A trend is a state or condition, that is as simple as Close > MA or something more complex that has boolean or integer (trend: 1, no trend: 0) values.

VectorBT
  • For backtesting, set trade_offset=1.
  • Setting asbool=True is useful for backtesting with vectorbt's Portfolio.from_signal(close, entries, exits) method.
Example

These are two different outcomes for each (long/short) position and depends on the source and it's behavior.

Signals when Close > SMA50(Close)

ta.tsignals(close > ta.sma(close, 50), asbool=False)

Signals when EMA(Close, 8) > EMA(Close, 21)

ta.tsignals(ta.ema(close, 8) > ta.ema(close, 21), asbool=True)
Warning

Check ALL outcomes BEFORE making an Issue




Cross Signals

This function creates Trend, Trades, Entries and Exits values per bar for crossing events.

Sources
  • Kevin Johnson

Parameters:

Name Type Description Default
source Series

source Signal

required
xa Series

Series the Signal crosses above if above=True

required
xb Series

Series the Signal crosses below if above=True

required
above bool

The source crossing; below is False. Default: True

True
long bool

The source position; short is False. Default: True

True
offset int

Post shift. Default: 0

None
asbool bool

Return booleans. Default: False

None
trade_offset value

Shift trade entries/exits with live: 0 and backesting: 1. Default: 0

None

Other Parameters:

Name Type Description
fillna value

pd.DataFrame.fillna(value)

Returns:

Type Description
DataFrame

4 columns

Column Detail
  • Trends (trend: 1, no trend: 0)
  • Trades (Enter: 1, Exit: -1, Otherwise: 0)
  • Entries (entry: 1, nothing: 0)
  • Exits (exit: 1, nothing: 0)
VectorBT
  • For backtesting, set trade_offset=1.
  • Setting asbool=True is useful for backtesting with vectorbt's Portfolio.from_signal(close, entries, exits) method.
Example

These are two different outcomes for each (long/short) position and depends on the source and it's behavior.

rsi = df.ta.rsi()

When RSI crosses above 20 and then below 80 in a long position:

ta.xsignals(source=rsi, xa=20, xb=80, above=True, long=True)
# Simpler
# ta.xsignals(rsi, 20, 80, True, True)

When RSI crosses below 20 and then above 80 in a long position:

ta.xsignals(source=rsi, xa=20, xb=80, above=False, long=True)
# Simpler
# ta.xsignals(rsi, 20, 80, False, True)
  • Similarly, short positions (long=False) also differ depending on above state.
Warning

Check ALL parameter combination outcomes BEFORE making an Issue.


NOTICE

Thanks to all those that have sponsored and dontated to the library in the past! Your support has been greatly appreciated! 🙏

However, future releases are on definite hold until 100+ donations of $150+ have been received via Buy Me a Coffee.

Help keep this library and application the best in it's class!





"Buy Me A Coffee"

ko-fi