Skip to contents

The fixed_moving_average_convergence_divergence() is a generic S3 function that builds upon 'type-safe'-esque workflows limited to classes in in base R, and the package-wide dependencies. Ie. class in, class out. Each method is a soft wrapper of model.frame and therefore the OHLC-V series must be coercible to a data.frame. This rule does not transfer to indicators that uses univariate series, unless passed as a 1-column data.frame or matrix. In such cases, if univariate series is passed as a vector the function calculates the indicator 'as is', and returns a data.frame if the indicator itself is also a univariate series.

The indicator, by default, follows its mathematical definition. However, the cols argument allows for simple rearrangement of the definition by passing relevant columns in a custom order. Refer to the details-section for more on the calculation of the indicators.

Usage

fixed_moving_average_convergence_divergence(x, cols, signal = 9, ...)

Arguments

x

An OHLC-V series that is coercible to data.frame. The function assumes that all columns are named in lowercase and order invariant.

cols

An optional formula passed into model.frame. If passed into indicators based on univariate series, the function calculates indicators for each element in 'cols'. For indicators based on multivariate series, it will alter the calculation itself. See vignette("talib") for more details.

signal

Smoothing for the signal line.

...

Additional parameters passed into model.frame

Value

An object of same class and length of x:

macd

double

signal

double

histogram

double

Author

Serkan Korkmaz

Examples

## load Bitcoin (BTC)
## series
data(BTC, package = "talib")

## calculate the indicator
## for Bitcoin (BTC)
output <- talib::fixed_moving_average_convergence_divergence(BTC)

## display the results
utils::tail(output)
#>                           macd    signal  histogram
#> 2024-12-26 01:00:00  588.63641 1525.1467  -936.5103
#> 2024-12-27 01:00:00  241.35538 1268.3885 -1027.0331
#> 2024-12-28 01:00:00   37.06467 1022.1237  -985.0590
#> 2024-12-29 01:00:00 -240.73287  769.5524 -1010.2853
#> 2024-12-30 01:00:00 -526.64220  510.3135 -1036.9557
#> 2024-12-31 01:00:00 -688.31718  270.5873  -958.9045

## visualize the indicator
## with candlesticks
##
## see ?talib::chart or ?talib::indicator
## for more details
{
 ## chart OHLC-V
 ## series with candlesticks
 talib::chart(BTC)

 ## chart indicator
 ## with default values
 talib::indicator(
     talib::fixed_moving_average_convergence_divergence
 )
}
#> Warning: Ignoring 33 observations