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 |
| required |
y | Series |
| required |
asint | bool | Returns as | True |
offset | Int | Post shift. Default: | None |
Returns:
Type | Description |
---|---|
Series | State where |
Above Value
Determines if each x
value is above (or >=
) a constant value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Series |
| required |
value | IntFloat | Value to compare with | required |
asint | bool | Returns as | True |
Returns:
Type | Description |
---|---|
Series | State where |
Below
Determines if each x
value is below (or <=
) each y
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Series |
| required |
y | Series |
| required |
asint | bool | Returns as | True |
offset | Int | Post shift. Default: | None |
Returns:
Type | Description |
---|---|
Series | State where |
Below Value
Determines if each x
value is below (or <=
) a constant value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Series |
| required |
value | IntFloat | Value to compare with | required |
asint | bool | Returns as | True |
offset | Int | Post shift. Default: | None |
Returns:
Type | Description |
---|---|
Series | State where |
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 |
| required |
y | Series |
| required |
above | bool | Check above. Check below, set | True |
equal | bool | At least/most, | True |
asint | bool | Returns as | True |
offset | Int | Post shift. Default: | None |
Returns:
Type | Description |
---|---|
Series | Values where |
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 |
| required |
value | IntFloat | Value to compare with | required |
above | bool | Check above. Check below, set | True |
equal | bool | At least/most, | True |
asint | bool | Returns as | True |
offset | Int | Post shift. Default: | None |
Returns:
Type | Description |
---|---|
Series | Values where |
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 |
| required |
asbool | bool | Return booleans. Default: | None |
trade_offset | value | Shift trade entries/exits with live: | None |
drift | int | Difference amount. Default: | None |
offset | int | Post shift. Default: | None |
Other Parameters:
Name | Type | Description |
---|---|---|
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'sPortfolio.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 |
| required |
xa | Series | Series the Signal crosses above if | required |
xb | Series | Series the Signal crosses below if | required |
above | bool | The | True |
long | bool | The | True |
offset | int | Post shift. Default: | None |
asbool | bool | Return booleans. Default: | None |
trade_offset | value | Shift trade entries/exits with live: | None |
Other Parameters:
Name | Type | Description |
---|---|---|
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'sPortfolio.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 onabove
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!