Function Prototype
/* On Balance Volume */
/* Type: indicator */
/* Input arrays: 2 Options: 0 Output arrays: 1 */
/* Inputs: close, volume */
/* Options: none */
/* Outputs: obv */
int ti_obv_start(TI_REAL const *options);
int ti_obv(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 On Balance Volume indicator calculates a running total of volume. Volume is added on up-days and subtracted on down days. The calculation is as follows:
$$obv_{t} =\begin{cases} obv_{t-1} + volume_{t} & \mathrm{if} \; close_{t} > close_{t-1} \\obv_{t-1} - volume_{t} & \mathrm{if} \; close_{t} \lt close_{t-1} \\0 & \text{else} \end{cases} $$
See Also
References
Example Usage
Calling From C
/* Example usage of On Balance Volume */
/* Assuming that 'close' and 'volume' are pre-loaded arrays of size 'in_size'. */
TI_REAL *inputs[] = {close, volume};
TI_REAL options[] = {}; /* No options */
TI_REAL *outputs[1]; /* obv */
/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_obv_start(options);
/* Allocate memory for output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* obv */
/* Run the actual calculation. */
const int ret = ti_obv(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);
Calling From Lua (with Tulip Chart bindings)
-- Example usage of On Balance Volume
obv = ti.obv(close, volume)
Example Calculation
date | close | volume | obv |
---|---|---|---|
2005-11-01 | 81.59 | 5,653,100.00 | 0.00 |
2005-11-02 | 81.06 | 6,447,400.00 | -6,447,400.00 |
2005-11-03 | 82.87 | 7,690,900.00 | 1,243,500.00 |
2005-11-04 | 83.00 | 3,831,400.00 | 5,074,900.00 |
2005-11-07 | 83.61 | 4,455,100.00 | 9,530,000.00 |
2005-11-08 | 83.15 | 3,798,000.00 | 5,732,000.00 |
2005-11-09 | 82.84 | 3,936,200.00 | 1,795,800.00 |
2005-11-10 | 83.99 | 4,732,000.00 | 6,527,800.00 |
2005-11-11 | 84.55 | 4,841,300.00 | 11,369,100.00 |
2005-11-14 | 84.36 | 3,915,300.00 | 7,453,800.00 |
2005-11-15 | 85.53 | 6,830,800.00 | 14,284,600.00 |
2005-11-16 | 86.54 | 6,694,100.00 | 20,978,700.00 |
2005-11-17 | 86.89 | 5,293,600.00 | 26,272,300.00 |
2005-11-18 | 87.77 | 7,985,800.00 | 34,258,100.00 |
2005-11-21 | 87.29 | 4,807,900.00 | 29,450,200.00 |
Chart
Other Indicators
Previous indicator: Negative Volume Index
Next indicator: Percentage Price Oscillator
Random indicator: Vector Floor
Copyright © 2016-2024 Tulip Charts LLC. All Rights Reserved.