Hilbert Transform | HTPeriod

Modified on 2015/11/13 12:52 by Eugene — Categorized as: Community Indicators

Syntax


public HTPeriod(DataSeries ds, string description)
public static HTPeriod(DataSeries ds)

Parameter Description

ds The source DataSeries, usually AverageSeries

Description

The Hilbert Transform is a technique used to generate inphase and quadrature components of a de-trended real-valued "analytic-like" signal (such as a Price Series) in order to analyze variations of the instantaneous phase and amplitude. HTPeriod (or MESA Instantaneous Period) returns the period of the Dominant Cycle of the analytic signal as generated by the Hilbert Transform. The Dominant Cycle can be thought of as being the "most likely" period (in the range of 10 to 40) of a sine function of the Price Series.

Interpretation

The HTPeriod at a specific bar gives the current Hilbert Transform Period as instantaneously measured at that bar in the range of 10 to 40. It is meaningful only during a cyclic period of the analytic signal waveform (price series) being measured. The HTPeriod, or one of its sub-periods, is often used to adjust other indicators; for example, Stochastics and RSIs work best when using a half cycle period to peak their performance. Similarly other indicators can be made to be adaptive by using the HTPeriod, or one of its sub-periods, as the period of the indicator. See the examples.



Calculation

More detailed information concerning the calculation of the Hilbert Transform related functions can be found on the Mesa Software site.

The basic flow and simplified pseudo code for the computation for the Dominant Cycle Period is:

Compute the Hilbert Transform
{Detrend Price}
{Compute InPhase and Quadrature components}

Compute the Period of the Dominant Cycle
{Use ArcTangent to compute the current phase}
{Resolve the ArcTangent ambiguity}
{Compute a differential phase, resolve phase wraparound, and limit delta phase errors}
{Sum DeltaPhases to reach 360 degrees. The sum is the instantaneous period.}
{Resolve Instantaneous Period errors and smooth}

Return the Hilbert Transform Period measured at the current bar 

Example

This code creates an adaptive moving average. The period of the MA is based on the HTPeriod for the bar:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // This code creates an adaptive moving average. // The period of the MA is based on the HTPeriod for the bar

HTPeriod htp = HTPeriod.Series( AveragePrice.Series( Bars ) ); DataSeries DynSMA = Close-Close; int n = 0; ChartPane HTPeriodPane = CreatePane( 50, true, true ); PlotSeries( HTPeriodPane, htp, Color.Blue, LineStyle.Solid, 1 ); for(int bar = 40; bar < Bars.Count; bar++) { n = (int)Math.Round( htp[bar] ); if( n < 2 ) n = 2; DynSMA[bar] = SMA.Series( AveragePrice.Series( Bars ), n )[bar]; } PlotSeries( PricePane, DynSMA, Color.Navy, LineStyle.Solid, 2 ); } } }