Skip to content

ohlcstx module

Module with OHLCSTX.


ohlcstx_config ReadonlyConfig

Factory config for OHLCSTX.


ohlcstx_func_config ReadonlyConfig

Exit function config for OHLCSTX.


OHLCSTX class

OHLCSTX(
    wrapper,
    input_list,
    input_mapper,
    in_output_list,
    output_list,
    param_list,
    mapper_list,
    short_name,
    **kwargs
)

Exit signal generator based on OHLC and stop values.

Generates exits based on entries and ohlc_stop_place_nb.

Hint

All parameters can be either a single value (per frame) or a NumPy array (per row, column, or element). To generate multiple combinations, pass them as lists.

Warning

Searches for an exit after each entry. If two entries come one after another, no exit can be placed. Consider either cleaning up entry signals prior to passing, or using OHLCSTCX.

Usage

Test each stop type:

>>> from vectorbtpro import *

>>> entries = pd.Series([True, False, False, False, False, False])
>>> price = pd.DataFrame({
...     'open': [10, 11, 12, 11, 10, 9],
...     'high': [11, 12, 13, 12, 11, 10],
...     'low': [9, 10, 11, 10, 9, 8],
...     'close': [10, 11, 12, 11, 10, 9]
... })
>>> ohlcstx = vbt.OHLCSTX.run(
...     entries,
...     price['open'],
...     price['open'],
...     price['high'],
...     price['low'],
...     price['close'],
...     sl_stop=[0.1, np.nan, np.nan, np.nan],
...     tsl_th=[np.nan, np.nan, 0.2, np.nan],
...     tsl_stop=[np.nan, 0.1, 0.3, np.nan],
...     tp_stop=[np.nan, np.nan, np.nan, 0.1],
...     is_entry_open=True
... )

>>> ohlcstx.entries
ohlcstx_sl_stop      0.1    NaN    NaN    NaN
ohlcstx_tsl_th       NaN    NaN    0.2    NaN
ohlcstx_tsl_stop     NaN    0.1    0.3    NaN
ohlcstx_tp_stop      NaN    NaN    NaN    0.1
0                   True   True   True   True
1                  False  False  False  False
2                  False  False  False  False
3                  False  False  False  False
4                  False  False  False  False
5                  False  False  False  False

>>> ohlcstx.exits
ohlcstx_sl_stop      0.1    NaN    NaN    NaN
ohlcstx_tsl_th       NaN    NaN    0.2    NaN
ohlcstx_tsl_stop     NaN    0.1    0.3    NaN
ohlcstx_tp_stop      NaN    NaN    NaN    0.1
0                  False  False  False  False
1                  False  False  False   True
2                  False  False  False  False
3                  False   True  False  False
4                   True  False   True  False
5                  False  False  False  False

>>> ohlcstx.stop_price
ohlcstx_sl_stop    0.1   NaN  NaN   NaN
ohlcstx_tsl_th     NaN   NaN  0.2   NaN
ohlcstx_tsl_stop   NaN   0.1  0.3   NaN
ohlcstx_tp_stop    NaN   NaN  NaN   0.1
0                  NaN   NaN  NaN   NaN
1                  NaN   NaN  NaN  11.0
2                  NaN   NaN  NaN   NaN
3                  NaN  11.7  NaN   NaN
4                  9.0   NaN  9.1   NaN
5                  NaN   NaN  NaN   NaN

>>> ohlcstx.stop_type_readable
ohlcstx_sl_stop     0.1   NaN   NaN   NaN
ohlcstx_tsl_th      NaN   NaN   0.2   NaN
ohlcstx_tsl_stop    NaN   0.1   0.3   NaN
ohlcstx_tp_stop     NaN   NaN   NaN   0.1
0                  None  None  None  None
1                  None  None  None    TP
2                  None  None  None  None
3                  None   TSL  None  None
4                    SL  None   TTP  None
5                  None  None  None  None

Superclasses

Inherited members

Subclasses

  • vectorbtpro.signals.generators.ohlcstx._OHLCSTX

apply_func method

OHLCSTX.apply_func(
    i,
    entries,
    entry_price,
    open,
    high,
    low,
    close,
    stop_price,
    stop_type,
    sl_stop,
    tsl_th,
    tsl_stop,
    tp_stop,
    reverse,
    exit_args,
    wait,
    until_next,
    skip_until_exit
)

Apply function.


close class property

Input array.


close_above method

OHLCSTX.close_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where close is above other.

See combine_objs.


close_below method

OHLCSTX.close_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where close is below other.

See combine_objs.


close_crossed_above method

OHLCSTX.close_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where close is crossed_above other.

See combine_objs.


close_crossed_below method

OHLCSTX.close_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where close is crossed_below other.

See combine_objs.


close_equal method

OHLCSTX.close_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where close is equal other.

See combine_objs.


close_stats method

OHLCSTX.close_stats(
    *args,
    **kwargs
)

Stats of close as generic.


custom_func method

SignalFactory.with_place_func.<locals>.custom_func(
    input_list,
    in_output_list,
    param_list,
    *args,
    input_shape=None,
    place_args=None,
    entry_place_args=None,
    exit_place_args=None,
    entry_args=None,
    exit_args=None,
    cache_args=None,
    entry_kwargs=None,
    exit_kwargs=None,
    cache_kwargs=None,
    return_cache=False,
    use_cache=None,
    execute_kwargs=None,
    **_kwargs
)

Custom function.


entries class property

Input array.


entries_and method

OHLCSTX.entries_and(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return entries AND other.

See combine_objs.


entries_or method

OHLCSTX.entries_or(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return entries OR other.

See combine_objs.


entries_stats method

OHLCSTX.entries_stats(
    *args,
    **kwargs
)

Stats of entries as signals.


entries_xor method

OHLCSTX.entries_xor(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return entries XOR other.

See combine_objs.


entry_place_func_nb NoneType

Entry placement function.


entry_price class property

Input array.


entry_price_above method

OHLCSTX.entry_price_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where entry_price is above other.

See combine_objs.


entry_price_below method

OHLCSTX.entry_price_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where entry_price is below other.

See combine_objs.


entry_price_crossed_above method

OHLCSTX.entry_price_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where entry_price is crossed_above other.

See combine_objs.


entry_price_crossed_below method

OHLCSTX.entry_price_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where entry_price is crossed_below other.

See combine_objs.


entry_price_equal method

OHLCSTX.entry_price_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where entry_price is equal other.

See combine_objs.


entry_price_stats method

OHLCSTX.entry_price_stats(
    *args,
    **kwargs
)

Stats of entry_price as generic.


exit_place_func_nb method

OHLCSTX.exit_place_func_nb(
    c,
    entry_price,
    open,
    high,
    low,
    close,
    stop_price_out,
    stop_type_out,
    sl_stop,
    tsl_th,
    tsl_stop,
    tp_stop,
    reverse,
    is_entry_open=False
)

Exit placement function.


exits class property

Output array.


exits_and method

OHLCSTX.exits_and(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return exits AND other.

See combine_objs.


exits_or method

OHLCSTX.exits_or(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return exits OR other.

See combine_objs.


exits_stats method

OHLCSTX.exits_stats(
    *args,
    **kwargs
)

Stats of exits as signals.


exits_xor method

OHLCSTX.exits_xor(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return exits XOR other.

See combine_objs.


high class property

Input array.


high_above method

OHLCSTX.high_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where high is above other.

See combine_objs.


high_below method

OHLCSTX.high_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where high is below other.

See combine_objs.


high_crossed_above method

OHLCSTX.high_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where high is crossed_above other.

See combine_objs.


high_crossed_below method

OHLCSTX.high_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where high is crossed_below other.

See combine_objs.


high_equal method

OHLCSTX.high_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where high is equal other.

See combine_objs.


high_stats method

OHLCSTX.high_stats(
    *args,
    **kwargs
)

Stats of high as generic.


low class property

Input array.


low_above method

OHLCSTX.low_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where low is above other.

See combine_objs.


low_below method

OHLCSTX.low_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where low is below other.

See combine_objs.


low_crossed_above method

OHLCSTX.low_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where low is crossed_above other.

See combine_objs.


low_crossed_below method

OHLCSTX.low_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where low is crossed_below other.

See combine_objs.


low_equal method

OHLCSTX.low_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where low is equal other.

See combine_objs.


low_stats method

OHLCSTX.low_stats(
    *args,
    **kwargs
)

Stats of low as generic.


open class property

Input array.


open_above method

OHLCSTX.open_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where open is above other.

See combine_objs.


open_below method

OHLCSTX.open_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where open is below other.

See combine_objs.


open_crossed_above method

OHLCSTX.open_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where open is crossed_above other.

See combine_objs.


open_crossed_below method

OHLCSTX.open_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where open is crossed_below other.

See combine_objs.


open_equal method

OHLCSTX.open_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where open is equal other.

See combine_objs.


open_stats method

OHLCSTX.open_stats(
    *args,
    **kwargs
)

Stats of open as generic.


plot method

_bind_ohlcstx_plot.<locals>.plot(
    column=None,
    ohlc_kwargs=None,
    entry_price_kwargs=None,
    entry_trace_kwargs=None,
    exit_trace_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot OHLC, OHLCSTX.entries and OHLCSTX.exits.

Args

ohlc_kwargs : dict
Keyword arguments passed to OHLCVDFAccessor.plot.
entry_trace_kwargs : dict
Keyword arguments passed to SignalsAccessor.plot_as_entries for OHLCSTX.entries.
exit_trace_kwargs : dict
Keyword arguments passed to SignalsAccessor.plot_as_exits for OHLCSTX.exits.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments for layout.

Usage

>>> ohlcstx.iloc[:, 0].plot().show()


reverse_list class property

List of reverse values.


run class method

OHLCSTX.run(
    entries,
    entry_price,
    open=nan,
    high=nan,
    low=nan,
    close=nan,
    sl_stop=Default(value=nan),
    tsl_th=Default(value=nan),
    tsl_stop=Default(value=nan),
    tp_stop=Default(value=nan),
    reverse=Default(value=False),
    stop_price=nan,
    stop_type=-1,
    short_name='ohlcstx',
    hide_params=None,
    hide_default=True,
    **kwargs
)

Run OHLCSTX indicator.

  • Inputs: entries, entry_price, open, high, low, close
  • In-place outputs: stop_price, stop_type
  • Parameters: sl_stop, tsl_th, tsl_stop, tp_stop, reverse
  • Outputs: exits

Pass a list of parameter names as hide_params to hide their column levels, or True to hide all. Set hide_default to False to show the column levels of the parameters with a default value.

Other keyword arguments are passed to IndicatorBase.run_pipeline.


run_combs class method

OHLCSTX.run_combs(
    entries,
    entry_price,
    open=nan,
    high=nan,
    low=nan,
    close=nan,
    sl_stop=Default(value=nan),
    tsl_th=Default(value=nan),
    tsl_stop=Default(value=nan),
    tp_stop=Default(value=nan),
    reverse=Default(value=False),
    stop_price=nan,
    stop_type=-1,
    r=2,
    param_product=False,
    comb_func=itertools.combinations,
    run_unique=True,
    short_names=None,
    hide_params=None,
    hide_default=True,
    **kwargs
)

Create a combination of multiple OHLCSTX indicators using function comb_func.

  • Inputs: entries, entry_price, open, high, low, close
  • In-place outputs: stop_price, stop_type
  • Parameters: sl_stop, tsl_th, tsl_stop, tp_stop, reverse
  • Outputs: exits

comb_func must accept an iterable of parameter tuples and r. Also accepts all combinatoric iterators from itertools such as itertools.combinations. Pass r to specify how many indicators to run. Pass short_names to specify the short name for each indicator. Set run_unique to True to first compute raw outputs for all parameters, and then use them to build each indicator (faster).

Other keyword arguments are passed to OHLCSTX.run.

Note

This method should only be used when multiple indicators are needed. To test multiple parameters, pass them as lists to OHLCSTX.run.


sl_stop_list class property

List of sl_stop values.


stop_price class property

In-place output array.


stop_price_above method

OHLCSTX.stop_price_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where stop_price is above other.

See combine_objs.


stop_price_below method

OHLCSTX.stop_price_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where stop_price is below other.

See combine_objs.


stop_price_crossed_above method

OHLCSTX.stop_price_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where stop_price is crossed_above other.

See combine_objs.


stop_price_crossed_below method

OHLCSTX.stop_price_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where stop_price is crossed_below other.

See combine_objs.


stop_price_equal method

OHLCSTX.stop_price_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where stop_price is equal other.

See combine_objs.


stop_price_stats method

OHLCSTX.stop_price_stats(
    *args,
    **kwargs
)

Stats of stop_price as generic.


stop_type class property

In-place output array.


stop_type_readable class property

stop_type in readable format based on the following mapping:

{
    0: 'SL',
    1: 'TSL',
    2: 'TTP',
    3: 'TP',
    4: 'TD',
    5: 'DT',
    -1: None
}

stop_type_stats method

OHLCSTX.stop_type_stats(
    *args,
    **kwargs
)

Stats of stop_type based on the following mapping:

{
    0: 'SL',
    1: 'TSL',
    2: 'TTP',
    3: 'TP',
    4: 'TD',
    5: 'DT',
    -1: None
}

tp_stop_list class property

List of tp_stop values.


tsl_stop_list class property

List of tsl_stop values.


tsl_th_list class property

List of tsl_th values.