public HTTrendLine(DataSeries ds, string description) public static HTTrendLine(DataSeries ds)
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} Compute the Instantaneous Trendline {Average over the period of the Dominant Cycle at each bar} Return the Hilbert Transform Trendline measured at the current 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() { /* Example - Another method of determining a trendual period using the HTTrendline is shown in the chartscript RocketScience, v1, by soulaerius. Here's a small extract of that script in which a "significant" deviation of the smoothed price, determined by an Optimization Variable, from the Trendline is used to declare trend mode. */ int trendfilter = (int)(2 / 100.0); // compute dominant cycle phase WMA SmoothPrice = WMA.Series( Close, 4 ); // compute trendline as simple average over dominant cycle period HTTrendLine Trendline = HTTrendLine.Series( AveragePrice.Series( Bars ) ); bool trend = false; for(int bar = 10; bar < Bars.Count; bar++) { //declare a trend mode if smoothprice is more than TRENDFILTER % from trendline if ( (SmoothPrice[bar] - Trendline[bar]) / Trendline[bar] >= trendfilter ) trend = true; else if ( (SmoothPrice[bar] - Trendline[bar]) / Trendline[bar] <= -trendfilter ) trend = false; if( trend ) SetBarColor( bar, Color.Navy ); else SetBarColor( bar, Color.Silver ); } } } }