Forecast Oscillator (FOSC)
Summary
Forecast Oscillator: the percentage by which the close deviates from the Time Series Forecast that was made one bar earlier for the current bar.
Positive means price came in above what the regression projected, negative below; the value oscillates around zero and crosses it whenever price meets its own forecast. Persistent readings far from zero say the trend is running ahead of, or lagging, its regression line.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive·negative
Formula
FOSC[t] = 100 * (P[t] - TSF[t-1]) / P[t], where TSF[t-1] is the Time Series Forecast fitted over the N bars ending at t-1 and evaluated one x-step beyond that window — the forecast for bar t made without seeing it.
Notes
- The input is assumed positive. The current value is the divisor. Where it is exactly 0 the output is 0. Near zero the divisor is small and the output very large; no error is returned. A series that reaches or crosses zero, such as an oscillator or a spread, has no meaningful result here.
- Several vendors publish a "Chande Forecast Oscillator (CFO)" that compares the close to the regression value of the window ending at the same bar, with no lag. FOSC is the lagged form Chande and Achelis describe.
- The default window is Chande's own suggestion, shorter than the one TA-Lib's TSF and LINEARREG default to.
Inputs
inReal— Source price/value series
Outputs
outReal— Percentage deviation of the close from the previous bar's forecast
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 5 | 2–100000 | Number of bars in the regression window |
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 i |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_FOSC( 0, n - 1, series, 5, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.fosc(0, series.len() - 1, &series, 5, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.fosc(0, series.length - 1, series, 5, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Fosc(0, series.Length - 1, series, 5, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));import { fosc } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = fosc(series, { timePeriod: 5 });
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0].toFixed(4) + ', ..., ' + values[values.length - 1].toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.FOSC(0, len(series)-1, series, 5, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.8.1 (ta-lib-python 0.8.1).
TA-Lib Definition: fosc.c · fosc.yaml
| Native | File |
|---|---|
| C | ta_FOSC.c |
| Rust | fosc.rs |
| Java | Core_FOSC.java |
| C# | Core_FOSC.cs |
| TypeScript | fosc.ts |
| Go | fosc.go |
Python: talib.FOSC (ta-lib-python 0.8.1 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Forecast Oscillator
See Also
References
- Tushar S. Chande and Stanley Kroll, The New Technical Trader, John Wiley & Sons (ISBN 0471597805)
- Steven B. Achelis, Technical Analysis from A to Z, page 147