Index of highest value over a specified period (MAXINDEX)
Summary
Returns the index of the highest input value within a rolling window of optInTimePeriod bars. Same as MAX but outputs the location instead of the value.
Chart
Chart metadata i
Outputs
outInteger:line·bar_index
Formula
outInteger[i] = index of max(inReal[i-optInTimePeriod+1 .. i])
Notes
- When several bars in a window share the highest value, the index of the most recent of them is returned.
Inputs
inReal— Input series to scan
Outputs
outInteger— Absolute index (into inReal) of the highest value in each window
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 30 | 2–100000 | Window length over which the max is located |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ☐ Input Must Be Positive |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
int out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_MAXINDEX( 0, n - 1, series, 30, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %d\n", outNBElement, outBegIdx, out[outNBElement - 1] );Rust
use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0i32; 252];
let core = Core::new();
let range = core.maxindex(0, series.len() - 1, &series, 30, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
double[] series = new double[252]; // your data, oldest first
int[] out = new int[252];
Core core = Core.DEFAULT;
OutRange r = core.maxindex(0, series.length - 1, series, 30, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);C#
using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outInteger = new int[252];
var core = Core.Default;
OutRange r = core.Maxindex(0, series.Length - 1, series, 30, outInteger);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outInteger = {outInteger[r.Count - 1]}");TypeScript
import { maxindex } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = maxindex(series, { timePeriod: 30 });
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.4.0.
TA-Lib Definition: maxindex.c · maxindex.yaml
| Native | File |
|---|---|
| C | ta_MAXINDEX.c |
| Rust | maxindex.rs |
| Java | Core_MAXINDEX.java |
| C# | Core_MAXINDEX.cs |
| TypeScript | maxindex.ts |
Python: talib.MAXINDEX, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Index of Highest Value, Highest Value Index, argmax
See Also
MAX · MININDEX · MIN · MINMAXINDEX