Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
ohlcstx module

Module with OHLCSTX.

## ohlcstx_config ReadonlyConfig

Factory config for OHLCSTX.

## ohlcstx_func_config ReadonlyConfig

Exit function config for OHLCSTX.

## bind_ohlcstx_plot function

    bind_ohlcstx_plot(
        base_cls,
        entries_attr
    )

## OHLCSTX class

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

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

- Analyzable
- AttrResolverMixin
- Cacheable
- Chainable
- Comparable
- Configured
- ExtPandasIndexer
- HasSettings
- IndexingBase
- IndicatorBase
- PandasIndexer
- Pickleable
- PlotsBuilderMixin
- Prettified
- StatsBuilderMixin
- Wrapping
- `vectorbtpro.signals.generators.ohlcstx.ParamIndexer`

Inherited members

- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.replace()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexingBase.indexing_setter_func()
- IndicatorBase.cls_dir
- IndicatorBase.column_only_select
- IndicatorBase.column_stack()
- IndicatorBase.config
- IndicatorBase.dropna()
- IndicatorBase.group_select
- IndicatorBase.iloc
- IndicatorBase.in_output_names
- IndicatorBase.indexing_func()
- IndicatorBase.indexing_kwargs
- IndicatorBase.input_names
- IndicatorBase.lazy_output_names
- IndicatorBase.level_names
- IndicatorBase.loc
- IndicatorBase.output_flags
- IndicatorBase.output_names
- IndicatorBase.param_names
- IndicatorBase.plots_defaults
- IndicatorBase.range_only_select
- IndicatorBase.rec_state
- IndicatorBase.row_stack()
- IndicatorBase.run_pipeline()
- IndicatorBase.self_aliases
- IndicatorBase.short_name
- IndicatorBase.stats_defaults
- IndicatorBase.to_dict()
- IndicatorBase.to_frame()
- IndicatorBase.unpack()
- IndicatorBase.wrapper
- IndicatorBase.xloc
- PandasIndexer.xs()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.regroup()
- Wrapping.resample()
- Wrapping.resolve_column_stack_kwargs()
- Wrapping.resolve_row_stack_kwargs()
- Wrapping.resolve_self()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
- Wrapping.split()

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
    )

### close 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
    )

### entries 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 class variable

### entry_price 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
    )

`place_func_nb` that places an exit signal whenever a threshold is being hit using OHLC.

Compared to `stop_place_nb`, takes into account the whole bar, can check for both (trailing) stop loss and take profit simultaneously, and tracks hit price and stop type.

Note

Waiting time cannot be higher than 1.

Args

`c` :`GenExContext` or `GenEnExContext`
  Signal context.
`entry_price` :`array` of `float`

  Entry price.

  Utilizes flexible indexing.

`open` :`array` of `float`

  Open price.

  Utilizes flexible indexing. If Nan and `is_entry_open` is True, defaults to entry price.

`high` :`array` of `float`

  High price.

  Utilizes flexible indexing. If NaN, gets calculated from open and close.

`low` :`array` of `float`

  Low price.

  Utilizes flexible indexing. If NaN, gets calculated from open and close.

`close` :`array` of `float`

  Close price.

  Utilizes flexible indexing. If Nan and `is_entry_open` is False, defaults to entry price.

`stop_price_out` :`array` of `float`

  Array where hit price of each exit will be stored.

  Must be of the full shape.

`stop_type_out` :`array` of `int`

  Array where stop type of each exit will be stored.

  Must be of the full shape. 0 for stop loss, 1 for take profit.

`sl_stop` :`array` of `float`

  Stop loss as a percentage.

  Utilizes flexible indexing. Set an element to `np.nan` to disable.

`tsl_th` :`array` of `float`

  Take profit threshold as a percentage for the trailing stop loss.

  Utilizes flexible indexing. Set an element to `np.nan` to disable.

`tsl_stop` :`array` of `float`

  Trailing stop loss as a percentage for the trailing stop loss.

  Utilizes flexible indexing. Set an element to `np.nan` to disable.

`tp_stop` :`array` of `float`

  Take profit as a percentage.

  Utilizes flexible indexing. Set an element to `np.nan` to disable.

`reverse` :`array` of `float`

  Whether to do the opposite, i.e.: prices are followed downwards.

  Utilizes flexible indexing.

`is_entry_open` :`bool`

  Whether entry price comes right at or before open.

  If True, uses high and low of the entry bar. Otherwise, uses only close.

### exits 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 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 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 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 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 property

List of `sl_stop` values.

### stop_price 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 property

In-place output array.

### stop_type_readable 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 property

List of `tp_stop` values.

### tsl_stop_list property

List of `tsl_stop` values.

### tsl_th_list property

List of `tsl_th` values.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings