Hilbert Transform - SineWave (HT_SINE)
Summary
Hilbert Transform SineWave: derives the dominant-cycle phase from price and emits its sine plus a 45-degree-lead sine. The two curves cross near cycle turning points. outSine and outLeadSine crossing marks cycle turning points.
Chart
Chart metadata i
Outputs
outSine:line·positive·negativeoutLeadSine:dash_line·positive·negative
Inputs
inReal— Source price series
Outputs
outSine— Sine of the dominant-cycle phaseoutLeadSine— Sine of the phase advanced 45 degrees (lead)
Properties
Numerical Stability: Initial Unstable Period
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ✅ Uses Transcendental i |
| ☐ Input Must Be Positive |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double sine[252], leadSine[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_HT_SINE( 0, n - 1, series, &outBegIdx, &outNBElement, sine, leadSine );
printf( "%d values from bar %d:\n", outNBElement, outBegIdx );
printf( "sine = [%.4f, ..., %.4f]\n", sine[0], sine[outNBElement - 1] );
printf( "leadSine = [%.4f, ..., %.4f]\n", leadSine[0], leadSine[outNBElement - 1] );Rust
use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut sine = vec![0.0; 252];
let mut lead_sine = vec![0.0; 252];
let core = Core::new();
let range = core.ht_sine(0, series.len() - 1, &series, &mut sine, &mut lead_sine)?;
println!("{} values from bar {}:", range.count, range.beg_idx);
println!("sine = [{:.4}, ..., {:.4}]", sine[0], sine[range.count - 1]);
println!("lead_sine = [{:.4}, ..., {:.4}]", lead_sine[0], lead_sine[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] sine = new double[252];
double[] leadSine = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.htSine(0, series.length - 1, series, sine, leadSine);
System.out.printf(Locale.ROOT, "%d values from bar %d:%n", r.count(), r.begIdx());
System.out.printf(Locale.ROOT, "sine = [%.4f, ..., %.4f]%n", sine[0], sine[r.count() - 1]);
System.out.printf(Locale.ROOT, "leadSine = [%.4f, ..., %.4f]%n", leadSine[0], leadSine[r.count() - 1]);C#
using System;
using TALib;
var series = new double[252]; // your data, oldest first
var sine = new double[252];
var leadSine = new double[252];
var core = Core.Default;
OutRange r = core.HtSine(0, series.Length - 1, series, sine, leadSine);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}:");
Console.WriteLine(FormattableString.Invariant($"sine = [{sine[0]:F4}, ..., {sine[r.Count - 1]:F4}]"));
Console.WriteLine(FormattableString.Invariant($"leadSine = [{leadSine[0]:F4}, ..., {leadSine[r.Count - 1]:F4}]"));TypeScript
import { htSine } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, outSine, outLeadSine } = htSine(series);
console.log(outSine.length + ' values from bar ' + begIdx + ':');
console.log('outSine = [' + outSine[0].toFixed(4) + ', ..., ' + outSine[outSine.length - 1].toFixed(4) + ']');
console.log('outLeadSine = [' + outLeadSine[0].toFixed(4) + ', ..., ' + outLeadSine[outLeadSine.length - 1].toFixed(4) + ']');Go
import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
sine := make([]float64, 252)
leadSine := make([]float64, 252)
core := talib.NewCore()
r, err := core.HT_SINE(0, len(series)-1, series, sine, leadSine)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d:\n", r.NBElement, r.BegIdx)
fmt.Printf("sine = [%.4f, ..., %.4f]\n", sine[0], sine[r.NBElement-1])
fmt.Printf("leadSine = [%.4f, ..., %.4f]\n", leadSine[0], leadSine[r.NBElement-1])Implementation
Added in 0.4.0.
TA-Lib Definition: ht_sine.c · ht_sine.yaml
| Native | File |
|---|---|
| C | ta_HT_SINE.c |
| Rust | ht_sine.rs |
| Java | Core_HT_SINE.java |
| C# | Core_HT_SINE.cs |
| TypeScript | htSine.ts |
| Go | ht_sine.go |
Python: talib.HT_SINE, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Hilbert Transform SineWave, Ehlers SineWave, SineWave Indicator
See Also
HT_DCPHASE · HT_DCPERIOD · HT_PHASOR · HT_TRENDMODE · MAMA
References
- John F. Ehlers, Rocket Science for Traders: Digital Signal Processing Applications, John Wiley & Sons (ISBN 0471405671)