Traders' Tips from TASC Magazine
Refining the Hilbert Indicator
The function, system, and indicator introduced in the articles "Refining the Hilbert Indicator", by John Ehlers, and "Optimizing with Hilbert Indicators", by Roger Darley, which appear in the November 2000 TASC issue, can be created in MetaStock 7.0 or higher with the use of the new MetaStock External Function (MSX) DLL Interface. The C++ code and MetaStock formula code is shown below:
MSX DLL C++ Code
// Main Calculation loop (begins after the fifth valid bar) for( l_iCurrentBar = a_iFirstValid + 5;
l_iCurrentBar <= a_iLastValid;l_iCurrentBar++ ) { // Set Previous Bar counter l_iPreviousBar = l_iCurrentBar - 1; // Calculate Smoother and Detrender values l_pdSmoother[l_iCurrentBar] = (4 * a_pfPrice[l_iCurrentBar] + 3 * a_pfPrice[l_iPreviousBar] + 2 * a_pfPrice[l_iCurrentBar - 2] + a_pfPrice[l_iCurrentBar - 3])/10; l_pdDetrender[l_iCurrentBar] = (.25 * l_pdSmoother[l_iCurrentBar] + .75 * l_pdSmoother[l_iCurrentBar - 2] - .75 * l_pdSmoother[l_iCurrentBar - 4] - .25 * l_pdSmoother[l_iCurrentBar - 6])* double(.046f * a_pfPeriod[l_iPreviousBar] + .332f); // Calculate InPhase and Quadrature components l_pd_Q1[l_iCurrentBar] = (.25 * l_pdDetrender[l_iCurrentBar] + .75 * l_pdDetrender[l_iCurrentBar - 2] - .75 * l_pdDetrender[l_iCurrentBar - 4] - .25 * l_pdDetrender[l_iCurrentBar - 6]) * double(.046f * a_pfPeriod[l_iPreviousBar] + .332f); l_pd_I1[l_iCurrentBar] = l_pdDetrender[l_iCurrentBar - 3]; // Advance the phase of l_pd_I1 and l_pd_Q1 by 90 degrees l_pd_jI[l_iCurrentBar] = .25 * l_pd_I1[l_iCurrentBar] + .75 * l_pd_I1[l_iCurrentBar - 2] - .75 * l_pd_I1[l_iCurrentBar - 4] - .25 * l_pd_I1[l_iCurrentBar - 6]; l_pd_jQ[l_iCurrentBar] = .25 * l_pd_Q1[l_iCurrentBar] + .75 * l_pd_Q1[l_iCurrentBar - 2] - .75 * l_pd_Q1[l_iCurrentBar - 4] -.25 * l_pd_Q1[l_iCurrentBar - 6]; // Phasor addition to equalize amplitude due to quadrature // calculations (and 3 bar averaging) l_pd_I2[l_iCurrentBar] = l_pd_I1[l_iCurrentBar] - l_pd_jQ[l_iCurrentBar]; l_pd_Q2[l_iCurrentBar] = l_pd_Q1[l_iCurrentBar] + l_pd_jI[l_iCurrentBar]; // Smooth I and Q components before applying the discriminator l_pd_I2[l_iCurrentBar] = ForceFloatRange (.15 * l_pd_I2[l_iCurrentBar] + .85 * l_pd_I2[l_iPreviousBar]); l_pd_Q2[l_iCurrentBar] = ForceFloatRange (.15 * l_pd_Q2[l_iCurrentBar] + .85 * l_pd_Q2[l_iPreviousBar]); // Homodyne Discriminator;
Complex Conjugate Multiply l_pd_X1[l_iCurrentBar] = l_pd_I2[l_iCurrentBar] * l_pd_I2[l_iPreviousBar]; l_pd_X2[l_iCurrentBar] = l_pd_I2[l_iCurrentBar] * l_pd_Q2[l_iPreviousBar]; l_pd_Y1[l_iCurrentBar] = l_pd_Q2[l_iCurrentBar] * l_pd_Q2[l_iPreviousBar]; l_pd_Y2[l_iCurrentBar] = l_pd_Q2[l_iCurrentBar] * l_pd_I2[l_iPreviousBar]; l_pd_Re[l_iCurrentBar] = l_pd_X1[l_iCurrentBar] + l_pd_Y1[l_iCurrentBar]; l_pd_Im[l_iCurrentBar] = l_pd_X2[l_iCurrentBar] - l_pd_Y2[l_iCurrentBar]; // Smooth to remove any undesired cross products l_pd_Re[l_iCurrentBar] = ForceFloatRange (.2 * l_pd_Re[l_iCurrentBar] + .8 * l_pd_Re[l_iPreviousBar]); l_pd_Im[l_iCurrentBar] = ForceFloatRange (.2 * l_pd_Im[l_iCurrentBar] + .8 * l_pd_Im[l_iPreviousBar]); // Compute Cycle Period if (l_pd_Im[l_iCurrentBar] != 0 && l_pd_Re[l_iCurrentBar] != 0) a_pfPeriod[l_iCurrentBar] = float (ForceFloatRange (360 / (atan(l_pd_Im[l_iCurrentBar] / l_pd_Re[l_iCurrentBar] ) * (180.0 / PI)))); if (a_pfPeriod[l_iCurrentBar] >
1.5f *a_pfPeriod[l_iPreviousBar]) a_pfPeriod[l_iCurrentBar] = 1.5f * a_pfPeriod[l_iPreviousBar]; if (a_pfPeriod[l_iCurrentBar] <
.67f *a_pfPeriod[l_iPreviousBar]) a_pfPeriod[l_iCurrentBar] = .67f * a_pfPeriod[l_iPreviousBar]; if (a_pfPeriod[l_iCurrentBar] <
6 ) a_pfPeriod[l_iCurrentBar] = 6; if ( a_pfPeriod[l_iCurrentBar] >
50 ) a_pfPeriod[l_iCurrentBar] = 50; a_pfPeriod[l_iCurrentBar] = .2f * a_pfPeriod[l_iCurrentBar] + .8f * a_pfPeriod[l_iPreviousBar]; }
MetaStock Code
Hilbert Channel Breakout Indicator
entryk:=Input("Entry K", 0, 1, 0);
entryval:=Input("Entry val", 0, 100, 0);
exitk:= Input("Exit K", 0, 4.5, 0);
exitval:=Input("Entry val", 0, 100, 0);
ExtFml( "EnhancedHilbert.ChannelHigh", (HIGH+LOW)/2, entryk, entryval);
ExtFml( "EnhancedHilbert.ChannelLow", (HIGH+LOW)/2, exitk, exitval)
Hilbert Channel Breakout Signal
Enter Long:
H >
ExtFml( "EnhancedHilbert.ChannelHigh",(HIGH+LOW)/2, 0, 15)
Enter Short:
L <
ExtFml( "EnhancedHilbert.ChannelLow",(HIGH+LOW)/2, 0, 15)
Click the links below to download the sample source code.
Dec2000EHilbertSetup.exe
Dec2000EnHilbertMSXSrc.ZIP
Contents
- Affine transformation
- Anticipating Moving Average Crossovers
- At Last! A Trend-Friendly Oscillator
- Average True Range or Standard Deviation
- Balance of Market Power
- Between Price and Volume
- Bollinger Band Targets
- BONUS ISSUE: Mutual Fund Screen
- Boosting Profitability - the AIM Indicator
- Breakout_Range2
- Bridging the Gap, Linking Point & Figure and Bar Charts
- Buff Up Your Moving Averages
- Bull and Bear Balance Indicator
- Candlestick Filtering
- Coding Candlesticks (II)
- Confirming the Price Trend
- Creating Multi-Colored Indicators in MetaStock
- Darvas-Style Trading and Something Darvas
- Deviation Oscillator
- Directional Breakout
- Ehlers Filters
- Elastic Volume Weighted Moving Average
- Finding Key Reversals
- Fisher Transform
- FVE - %b
- FVE - lin reg slope
- FVE - Storz's divergence
- FVE w/ linear regression slope
- High Low Strategy
- High Tech Mesa Adaptive Moving Averages
- Hilbert Indicators Tell You When to Trade
- Holding Overnight Positions
- Hot Zones
- How Smooth is Your Data Smoother
- Ichimoku Charts
- Index of Chart Sentiment
- Laguerre Filter
- Laguerre RSI
- MACD of Relative Strength
- Moving Average Crossovers
- Moving Average: Long on Talk, Sort on Action
- Normalization
- Now's The Time To Trade Crude
- Pivot point Strategy
- Profit with ETFs
- Quicken Your Averages
- Red-Green Strategy
- Refining the Hilbert Indicator
- Regularization
- Relative Performance Charting
- RSI Bands
- Squelch Those Whipsaws
- sRSI - Original
- sRSI - Using Wilders
- Stochastics
- Tandem Studies on Market Movement
- Targeting Your Pattern
- TC 2000 Scans
- The Average Peak Excursion
- The Cocked Gun Revisited
- The Inverse Fisher Transform
- The Self-Adjusting RSI
- The Truth about Volatility
- The Wilson Relative Price Channel
- Thrust Oscillator
- Trade Against the Gap
- Trade Into the Gap
- Trade the Swing Price
- Trend Continuation Factor
- Trend Quality Indicator
- Trend Trigger Factor
- TrendIV & Volume - Buy Signal
- TrendIV & Volume - Sell Signal
- Triggering Your Trading System
- Using Money Flow to Stay with the Trend
- Using Volume to Detect Shifts In Power
- Volatility System
- VWAP for Support and Resistance
- When and When not to Trade