% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ta_TRIMA.R
\name{triangular_moving_average}
\alias{triangular_moving_average}
\alias{TRIMA}
\title{Triangular Moving Average}
\usage{
triangular_moving_average(x, cols, n = 30, na.bridge = FALSE, ...)
}
\arguments{
\item{x}{An OHLC-V series coercible to \link{data.frame}.
Alternatively, \code{x} may also be supplied as a \link{double} vector.}

\item{cols}{(\link{formula}). An optional \code{1}-variable \link{formula} selecting columns from \code{x} via \link{model.frame}.
Defaults to \code{~close}.}

\item{n}{(\link{integer}). Lookback period (window size). A positive \link{integer}
of \link{length} 1.}

\item{na.bridge}{(\link{logical}). A \link{logical} of \link{length} 1. \link{FALSE} by
default. When \link{FALSE}, input \code{NA}s propagate through the TA-Lib C
routine (most indicators will fill the remaining output with
\code{NA}). When \link{TRUE}, input \code{NA} rows are stripped before
computation and re-inserted at the original positions in the
output, causing the indicator to treat non-consecutive non-\code{NA}
observations as if they were adjacent — see the \strong{Handling of
\code{NA} values} section above for the consequences.}

\item{...}{Additional parameters passed into \link{model.frame}.}
}
\value{
An object of same \link{class} and \link{length} of \code{x}:

\describe{
\item{TRIMA}{\link{double}}
}
}
\description{
\code{triangular_moving_average()} is a generic S3 function that preserves
the input \link{class}: \link{data.frame} in, \link{data.frame} out; \link{matrix} in,
\link{matrix} out.

\code{triangular_moving_average()} also accepts a \link{double} vector, in which case the indicator is calculated directly without column selection. When the result has a single column it is simplified to a \link{double} vector; otherwise the full \code{n} by \code{k} \link{matrix} is returned.
\subsection{Handling of \code{NA} values}{

Every indicator always emits \strong{leading \code{NA}s} for the initial
lookback period - positions where there is not yet enough data to
produce a result. This is separate from how \code{NA}s already present
in the input are handled, which is controlled by the \code{na.bridge}
argument:

\describe{
\item{\code{na.bridge = FALSE} (default)}{The input is passed to the
underlying TA-Lib C routine as-is. Because most indicators smooth
across time (EMA, RSI, MACD, Bollinger Bands, ...), a single
\code{NA} in the input typically propagates forward and \strong{poisons
every subsequent value} - it is common for one missing
observation to produce an output that is entirely \code{NA} from that
position onward. This mode is the right choice when you want to
\emph{see} the missing data in the output rather than silently
compute around it.}
\item{\code{na.bridge = TRUE}}{\code{NA} rows are stripped from the input
before the C routine runs; the indicator is computed on the
resulting dense series; results are then re-expanded to the
original length with \code{NA} inserted at every position the input
had \code{NA}. Output length always matches input length, so the
result can be joined back to the source \code{data.frame} by row.

\strong{Consequence to understand before enabling:} bridging causes
the indicator to treat non-consecutive observations as
consecutive. A 14-period RSI with \code{na.bridge = TRUE} over a
series containing a month-long gap will compute using 14
observations that span several real-world months as if they were
14 adjacent trading days. For sparse missing values (e.g. a
single missing tick) this is harmless; for clustered gaps (e.g.
a delisted period, a weekend encoded as \code{NA}) the output is
correctly aligned \emph{by position} but economically meaningless
across the gap. Inspect gap structure with \code{which(is.na(x))}
before enabling on low-quality time series.}
}
}
}
\details{
When passed without 'x', \link{triangular_moving_average} functions as an 'Moving Average'-specification which is used in, for example, \link{stochastic} when constructing the smoothing lines.

When called without 'x' it will return a named list which is used for the
indicators that supports various Moving Average specifications.
}
\examples{
## load Bitcoin (BTC)
## series
data(BTC, package = "talib")

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

## display the results
utils::tail(output)

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

 ## chart indicator
 ## with default values
 talib::indicator(
     talib::triangular_moving_average
 )
}
}
\seealso{
Other Overlap Study:
\code{\link[=acceleration_bands]{acceleration_bands()}},
\code{\link[=bollinger_bands]{bollinger_bands()}},
\code{\link[=double_exponential_moving_average]{double_exponential_moving_average()}},
\code{\link[=exponential_moving_average]{exponential_moving_average()}},
\code{\link[=extended_parabolic_stop_and_reverse]{extended_parabolic_stop_and_reverse()}},
\code{\link[=kaufman_adaptive_moving_average]{kaufman_adaptive_moving_average()}},
\code{\link[=mesa_adaptive_moving_average]{mesa_adaptive_moving_average()}},
\code{\link[=parabolic_stop_and_reverse]{parabolic_stop_and_reverse()}},
\code{\link[=simple_moving_average]{simple_moving_average()}},
\code{\link[=t3_exponential_moving_average]{t3_exponential_moving_average()}},
\code{\link[=trendline]{trendline()}},
\code{\link[=triple_exponential_moving_average]{triple_exponential_moving_average()}},
\code{\link[=weighted_moving_average]{weighted_moving_average()}}
}
\author{
Serkan Korkmaz
}
\concept{Overlap Study}
\concept{algorithmic trading}
\concept{finance}
\concept{technical analysis}
\concept{trading}
