Average Price

Technical Analysis Indicator: avgprice

Fork me on GitHub

Function Prototype

/* Average Price */
/* Type: overlay */
/* Input arrays: 4    Options: 0    Output arrays: 1 */
/* Inputs: open, high, low, close */
/* Options: none */
/* Outputs: avgprice */
int ti_avgprice_start(TI_REAL const *options);
int ti_avgprice(int size,
      TI_REAL const *const *inputs,
      TI_REAL const *options,
      TI_REAL *const *outputs);

Description

This documentation is still a work in progress. It has omissions, and it probably has errors too. If you see any issues, or have any general feedback, please get in touch.

The average price indicator calculates the mean of the open, high, low, and close of a bar.

$$avgprice_{t} = \frac{open_{t}+high_{t}+low_{t}+close_{t}}{4}$$

See Also

References

Example Usage

Calling From C

/* Example usage of Average Price */
/* Assuming that 'open', 'high', 'low', and 'close' are pre-loaded arrays of size 'in_size'. */
TI_REAL *inputs[] = {open, high, low, close};
TI_REAL options[] = {}; /* No options */
TI_REAL *outputs[1]; /* avgprice */

/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_avgprice_start(options);

/* Allocate memory for output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* avgprice */

/* Run the actual calculation. */
const int ret = ti_avgprice(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);

Calling From Lua (with Tulip Chart bindings)

-- Example usage of Average Price
avgprice = ti.avgprice(open, high, low, close)

Example Calculation

dateopenhighlowcloseavgprice
2005-11-0181.8582.1581.2981.5981.72
2005-11-0281.2081.8980.6481.0681.20
2005-11-0381.5583.0381.3182.8782.19
2005-11-0482.9183.3082.6583.0082.97
2005-11-0783.1083.8583.0783.6183.41
2005-11-0883.4183.9083.1183.1583.39
2005-11-0982.7183.3382.4982.8482.84
2005-11-1082.7084.3082.3083.9983.32
2005-11-1184.2084.8484.1584.5584.44
2005-11-1484.2585.0084.1184.3684.43
2005-11-1584.0385.9084.0385.5384.87
2005-11-1685.4586.5885.3986.5485.99
2005-11-1786.1886.9885.7686.8986.45
2005-11-1888.0088.0087.1787.7787.74
2005-11-2187.6087.8787.0187.2987.44

Chart

 

Other Indicators

Previous indicator: Average True Range

Next indicator: Bollinger Bands

Random indicator: Weighted Moving Average