Skip to content

macd module

Module with MACD.


MACD class

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

Moving Average Convergence Divergence (MACD).

Is a trend-following momentum indicator that shows the relationship between two moving averages of prices.

See Moving Average Convergence Divergence – MACD.

Superclasses

Inherited members

Subclasses

  • vectorbtpro.indicators.custom.macd._MACD

apply_func method

MACD.apply_func(
    close,
    fast_window=12,
    slow_window=26,
    signal_window=9,
    wtype=2,
    macd_wtype=None,
    signal_wtype=None,
    minp=None,
    macd_minp=None,
    signal_minp=None,
    adjust=False,
    macd_adjust=None,
    signal_adjust=None
)

2-dim version of macd_1d_nb.


cache_func class variable


close property

Input array.


close_above method

MACD.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

MACD.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

MACD.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

MACD.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

MACD.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

MACD.close_stats(
    *args,
    **kwargs
)

Stats of close as generic.


custom_func method

IndicatorFactory.with_apply_func.<locals>.custom_func(
    input_tuple,
    in_output_tuple,
    param_tuple,
    *_args,
    input_shape=None,
    per_column=False,
    split_columns=False,
    skipna=False,
    return_cache=False,
    use_cache=True,
    jitted_loop=False,
    jitted_warmup=False,
    param_index=None,
    final_index=None,
    single_comb=False,
    execute_kwargs=None,
    **_kwargs
)

Custom function that forwards inputs and parameters to apply_func.


fast_window_list property

List of fast_window values.


hist property

Custom property.


hist_above method

MACD.hist_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where hist is above other.

See combine_objs().


hist_below method

MACD.hist_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where hist is below other.

See combine_objs().


hist_crossed_above method

MACD.hist_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where hist is crossed_above other.

See combine_objs().


hist_crossed_below method

MACD.hist_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where hist is crossed_below other.

See combine_objs().


hist_equal method

MACD.hist_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where hist is equal other.

See combine_objs().


hist_stats method

MACD.hist_stats(
    *args,
    **kwargs
)

Stats of hist as generic.


macd property

Output array.


macd_above method

MACD.macd_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where macd is above other.

See combine_objs().


macd_below method

MACD.macd_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where macd is below other.

See combine_objs().


macd_crossed_above method

MACD.macd_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where macd is crossed_above other.

See combine_objs().


macd_crossed_below method

MACD.macd_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where macd is crossed_below other.

See combine_objs().


macd_equal method

MACD.macd_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where macd is equal other.

See combine_objs().


macd_stats method

MACD.macd_stats(
    *args,
    **kwargs
)

Stats of macd as generic.


macd_wtype_list property

List of macd_wtype values.


param_select_func_nb method

MACD.param_select_func_nb(
    i,
    args_before,
    close,
    fast_window,
    slow_window,
    signal_window,
    wtype,
    macd_wtype,
    signal_wtype,
    *args
)

plot method

_MACD.plot(
    column=None,
    macd_trace_kwargs=None,
    signal_trace_kwargs=None,
    hist_trace_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot MACD.macd, MACD.signal and MACD.hist.

Args

column : str
Name of the column to plot.
macd_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for MACD.macd.
signal_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for MACD.signal.
hist_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Bar for MACD.hist.
add_trace_kwargs : dict
Keyword arguments passed to fig.add_trace when adding each trace.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments passed to fig.update_layout.

Usage

>>> vbt.MACD.run(ohlcv['Close']).plot().show()


run class method

MACD.run(
    close,
    fast_window=Default(value=12),
    slow_window=Default(value=26),
    signal_window=Default(value=9),
    wtype=Default(value='exp'),
    macd_wtype=Default(value=None),
    signal_wtype=Default(value=None),
    short_name='macd',
    hide_params=None,
    hide_default=True,
    **kwargs
)

Run MACD indicator.

  • Inputs: close
  • Parameters: fast_window, slow_window, signal_window, wtype, macd_wtype, signal_wtype
  • Outputs: macd, signal
  • Lazy outputs: hist

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

MACD.run_combs(
    close,
    fast_window=Default(value=12),
    slow_window=Default(value=26),
    signal_window=Default(value=9),
    wtype=Default(value='exp'),
    macd_wtype=Default(value=None),
    signal_wtype=Default(value=None),
    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 MACD indicators using function comb_func.

  • Inputs: close
  • Parameters: fast_window, slow_window, signal_window, wtype, macd_wtype, signal_wtype
  • Outputs: macd, signal
  • Lazy outputs: hist

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 MACD.run().

Note

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


signal property

Output array.


signal_above method

MACD.signal_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where signal is above other.

See combine_objs().


signal_below method

MACD.signal_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where signal is below other.

See combine_objs().


signal_crossed_above method

MACD.signal_crossed_above(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where signal is crossed_above other.

See combine_objs().


signal_crossed_below method

MACD.signal_crossed_below(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where signal is crossed_below other.

See combine_objs().


signal_equal method

MACD.signal_equal(
    other,
    level_name=None,
    allow_multiple=True,
    **kwargs
)

Return True for each element where signal is equal other.

See combine_objs().


signal_stats method

MACD.signal_stats(
    *args,
    **kwargs
)

Stats of signal as generic.


signal_window_list property

List of signal_window values.


signal_wtype_list property

List of signal_wtype values.


slow_window_list property

List of slow_window values.


wtype_list property

List of wtype values.