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¶
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¶
Return True for each element where close is above other.
See combine_objs().
close_below method¶
Return True for each element where close is below other.
See combine_objs().
close_crossed_above method¶
Return True for each element where close is crossed_above other.
See combine_objs().
close_crossed_below method¶
Return True for each element where close is crossed_below other.
See combine_objs().
close_equal method¶
Return True for each element where close is equal other.
See combine_objs().
close_stats method¶
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¶
Return entries AND other.
See combine_objs().
entries_or method¶
Return entries OR other.
See combine_objs().
entries_stats method¶
Stats of entries as signals.
entries_xor method¶
Return entries XOR other.
See combine_objs().
entry_place_func_nb class variable¶
entry_price property¶
Input array.
entry_price_above method¶
Return True for each element where entry_price is above other.
See combine_objs().
entry_price_below method¶
Return True for each element where entry_price is below other.
See combine_objs().
entry_price_crossed_above method¶
Return True for each element where entry_price is crossed_above other.
See combine_objs().
entry_price_crossed_below method¶
Return True for each element where entry_price is crossed_below other.
See combine_objs().
entry_price_equal method¶
Return True for each element where entry_price is equal other.
See combine_objs().
entry_price_stats method¶
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:GenExContextorGenEnExContext- Signal context.
entry_price:arrayoffloat-
Entry price.
Utilizes flexible indexing.
open:arrayoffloat-
Open price.
Utilizes flexible indexing. If Nan and
is_entry_openis True, defaults to entry price. high:arrayoffloat-
High price.
Utilizes flexible indexing. If NaN, gets calculated from open and close.
low:arrayoffloat-
Low price.
Utilizes flexible indexing. If NaN, gets calculated from open and close.
close:arrayoffloat-
Close price.
Utilizes flexible indexing. If Nan and
is_entry_openis False, defaults to entry price. stop_price_out:arrayoffloat-
Array where hit price of each exit will be stored.
Must be of the full shape.
stop_type_out:arrayofint-
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:arrayoffloat-
Stop loss as a percentage.
Utilizes flexible indexing. Set an element to
np.nanto disable. tsl_th:arrayoffloat-
Take profit threshold as a percentage for the trailing stop loss.
Utilizes flexible indexing. Set an element to
np.nanto disable. tsl_stop:arrayoffloat-
Trailing stop loss as a percentage for the trailing stop loss.
Utilizes flexible indexing. Set an element to
np.nanto disable. tp_stop:arrayoffloat-
Take profit as a percentage.
Utilizes flexible indexing. Set an element to
np.nanto disable. reverse:arrayoffloat-
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¶
Return exits AND other.
See combine_objs().
exits_or method¶
Return exits OR other.
See combine_objs().
exits_stats method¶
Stats of exits as signals.
exits_xor method¶
Return exits XOR other.
See combine_objs().
high property¶
Input array.
high_above method¶
Return True for each element where high is above other.
See combine_objs().
high_below method¶
Return True for each element where high is below other.
See combine_objs().
high_crossed_above method¶
Return True for each element where high is crossed_above other.
See combine_objs().
high_crossed_below method¶
Return True for each element where high is crossed_below other.
See combine_objs().
high_equal method¶
Return True for each element where high is equal other.
See combine_objs().
high_stats method¶
Stats of high as generic.
low property¶
Input array.
low_above method¶
Return True for each element where low is above other.
See combine_objs().
low_below method¶
Return True for each element where low is below other.
See combine_objs().
low_crossed_above method¶
Return True for each element where low is crossed_above other.
See combine_objs().
low_crossed_below method¶
Return True for each element where low is crossed_below other.
See combine_objs().
low_equal method¶
Return True for each element where low is equal other.
See combine_objs().
low_stats method¶
Stats of low as generic.
open property¶
Input array.
open_above method¶
Return True for each element where open is above other.
See combine_objs().
open_below method¶
Return True for each element where open is below other.
See combine_objs().
open_crossed_above method¶
Return True for each element where open is crossed_above other.
See combine_objs().
open_crossed_below method¶
Return True for each element where open is crossed_below other.
See combine_objs().
open_equal method¶
Return True for each element where open is equal other.
See combine_objs().
open_stats method¶
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:FigureorFigureWidget- Figure to add traces to.
**layout_kwargs- Keyword arguments for layout.
Usage
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¶
Return True for each element where stop_price is above other.
See combine_objs().
stop_price_below method¶
Return True for each element where stop_price is below other.
See combine_objs().
stop_price_crossed_above method¶
Return True for each element where stop_price is crossed_above other.
See combine_objs().
stop_price_crossed_below method¶
Return True for each element where stop_price is crossed_below other.
See combine_objs().
stop_price_equal method¶
Return True for each element where stop_price is equal other.
See combine_objs().
stop_price_stats method¶
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:
stop_type_stats method¶
Stats of stop_type based on the following mapping:
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.