Hilbert Channel by zuijaideai
4778 downloads / 6167 views / Created: 23.05.2013




Average Rating: 0
Indicator Description
Hi All,
Attached is the famous Hilbert Channel Indicator from John Ehlers appears in TASC magazine Nov 2000.

Please somebody post the description regarding this indicator.
Link to the forum topic: Hilbert Channel
Rgds
Denny Imanuel
imanuel.denny@gmail.com
Attached is the famous Hilbert Channel Indicator from John Ehlers appears in TASC magazine Nov 2000.

Please somebody post the description regarding this indicator.
Link to the forum topic: Hilbert Channel
Rgds
Denny Imanuel
imanuel.denny@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
//==============================================================
// Forex Strategy Builder
// Copyright © Miroslav Popov. All rights reserved.
//==============================================================
// THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE.
//==============================================================
using System;
using System.Drawing;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class HilbertChannel : Indicator
{
public HilbertChannel()
{
// General properties
IndicatorName = "Hilbert Channel";
PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;
IndicatorAuthor = "Denny Imanuel";
IndicatorVersion = "2.1";
IndicatorDescription = "Hilbert Channel Indicator from John Ehlers appears in TASC magazine Nov 2000";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
if (slotType == SlotTypes.Open)
IndParam.ListParam[0].ItemList = new string[]
{
"Enter long at the Entry Channel",
"Enter long at the Exit Channel"
};
else if (slotType == SlotTypes.OpenFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar opens below the Entry Channel",
"The bar opens above the Entry Channel",
"The bar opens below the Exit Channel",
"The bar opens above the Exit Channel",
"The position opens below the Entry Channel",
"The position opens above the Entry Channel",
"The position opens below the Exit Channel",
"The position opens above the Exit Channel",
"The bar opens below the Entry Channel after opening above it",
"The bar opens above the Entry Channel after opening below it",
"The bar opens below the Exit Channel after opening above it",
"The bar opens above the Exit Channel after opening below it"
};
else if (slotType == SlotTypes.Close)
IndParam.ListParam[0].ItemList = new string[]
{
"Exit long at the Entry Channel",
"Exit long at the Exit Channel"
};
else if (slotType == SlotTypes.CloseFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar closes below the Entry Channel",
"The bar closes above the Entry Channel",
"The bar closes below the Exit Channel",
"The bar closes above the Exit Channel"
};
else
IndParam.ListParam[0].ItemList = new string[]
{
"Not Defined"
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
IndParam.ListParam[2].Caption = "Base price";
IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
IndParam.ListParam[2].Index = (int)BasePrice.Median;
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "The price the central Moving Average is based on.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "Look Back Value";
IndParam.NumParam[0].Value = 15;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 100;
IndParam.NumParam[0].Point = 0;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The Hilbert Channel look back value.";
IndParam.NumParam[1].Caption = "K Coefficient";
IndParam.NumParam[1].Value = 0;
IndParam.NumParam[1].Min = 0;
IndParam.NumParam[1].Max = 5;
IndParam.NumParam[1].Point = 2;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "Determines the width of Hilbert Channel.";
// The CheckBox parameters
IndParam.CheckParam[0].Caption = "Use previous bar value";
IndParam.CheckParam[0].Enabled = true;
IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
BasePrice price = (BasePrice)IndParam.ListParam[2].Index;
int iVal = (int)IndParam.NumParam[0].Value;
double dMpl = IndParam.NumParam[1].Value;
int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
// Calculation
double[] adPrice = Price(price);
double[] adPeriod = HilbertPeriod(adPrice);
double[] adEntryChannel = new double[Bars];
double[] adExitChannel = new double[Bars];
int iLookBack;
int iFirstBar = iVal + iPrvs + 2;
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
if (iVal!=0) iLookBack = iVal;
else iLookBack = (int)(dMpl*adPeriod[iBar]);
if (iLookBack<1) iLookBack = 1;
adEntryChannel[iBar] = double.MinValue;
adExitChannel[iBar] = double.MaxValue;
for (int iBack=1; iBack<=iLookBack; iBack++)
{
if (adEntryChannel[iBar]Low[iBar-iBack]) adExitChannel[iBar] = Low[iBar-iBack];
}
}
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp();
Component[0].CompName = "Entry Channel";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.DarkGreen;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adEntryChannel;
Component[1] = new IndicatorComp();
Component[1].CompName = "Exit Channel";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.DarkRed;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adExitChannel;
Component[2] = new IndicatorComp();
Component[2].ChartType = IndChartType.NoChart;
Component[2].FirstBar = iFirstBar;
Component[2].Value = new double[Bars];
Component[3] = new IndicatorComp();
Component[3].ChartType = IndChartType.NoChart;
Component[3].FirstBar = iFirstBar;
Component[3].Value = new double[Bars];
// Sets the Component's type.
if (SlotType == SlotTypes.Open)
{
Component[2].DataType = IndComponentType.OpenLongPrice;
Component[2].CompName = "Long position entry price";
Component[3].DataType = IndComponentType.OpenShortPrice;
Component[3].CompName = "Short position entry price";
}
else if (SlotType == SlotTypes.OpenFilter)
{
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[2].CompName = "Is long entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
Component[3].CompName = "Is short entry allowed";
}
else if (SlotType == SlotTypes.Close)
{
Component[2].DataType = IndComponentType.CloseLongPrice;
Component[2].CompName = "Long position closing price";
Component[3].DataType = IndComponentType.CloseShortPrice;
Component[3].CompName = "Short position closing price";
}
else if (SlotType == SlotTypes.CloseFilter)
{
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[2].CompName = "Close out long position";
Component[3].DataType = IndComponentType.ForceCloseShort;
Component[3].CompName = "Close out short position";
}
if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close)
{
if (iFirstBar > 1)
{
for (int iBar = 2; iBar < Bars; iBar++)
{
// Covers the cases when the price can pass through the band without a signal
double dValueUp = adEntryChannel[iBar - iPrvs]; // Current value
double dValueUp1 = adEntryChannel[iBar - iPrvs - 1]; // Previous value
double dTempValUp = dValueUp;
if ((dValueUp1 > High[iBar - 1] && dValueUp < Low[iBar]) || // It jumps below the current bar
(dValueUp1 < Low[iBar - 1] && dValueUp > High[iBar]) || // It jumps above the current bar
(Close[iBar - 1] < dValueUp && dValueUp < Open[iBar]) || // Positive gap
(Close[iBar - 1] > dValueUp && dValueUp > Open[iBar])) // Negative gap
dTempValUp = Open[iBar];
double dValueDown = adExitChannel[iBar - iPrvs]; // Current value
double dValueDown1 = adExitChannel[iBar - iPrvs - 1]; // Previous value
double dTempValDown = dValueDown;
if ((dValueDown1 > High[iBar - 1] && dValueDown < Low[iBar]) || // It jumps below the current bar
(dValueDown1 < Low[iBar - 1] && dValueDown > High[iBar]) || // It jumps above the current bar
(Close[iBar - 1] < dValueDown && dValueDown < Open[iBar]) || // Positive gap
(Close[iBar - 1] > dValueDown && dValueDown > Open[iBar])) // Negative gap
dTempValDown = Open[iBar];
if (IndParam.ListParam[0].Text == "Enter long at the Entry Channel" ||
IndParam.ListParam[0].Text == "Exit long at the Entry Channel")
{
Component[2].Value[iBar] = dTempValUp;
Component[3].Value[iBar] = dTempValDown;
}
else
{
Component[2].Value[iBar] = dTempValDown;
Component[3].Value[iBar] = dTempValUp;
}
}
}
else
{
for (int iBar = 2; iBar < Bars; iBar++)
{
if (IndParam.ListParam[0].Text == "Enter long at the Entry Channel" ||
IndParam.ListParam[0].Text == "Exit long at the Entry Channel")
{
Component[2].Value[iBar] = adEntryChannel[iBar - iPrvs];
Component[3].Value[iBar] = adExitChannel[iBar - iPrvs];
}
else
{
Component[2].Value[iBar] = adExitChannel[iBar - iPrvs];
Component[3].Value[iBar] = adEntryChannel[iBar - iPrvs];
}
}
}
}
else
{
switch (IndParam.ListParam[0].Text)
{
case "The bar opens below the Entry Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band);
break;
case "The bar opens above the Entry Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band);
break;
case "The bar opens below the Exit Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band);
break;
case "The bar opens above the Exit Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band);
break;
case "The bar opens below the Entry Channel after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
break;
case "The bar opens above the Entry Channel after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
break;
case "The bar opens below the Exit Channel after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
break;
case "The bar opens above the Exit Channel after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
break;
case "The position opens above the Entry Channel":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[2].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens below the Entry Channel":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[2].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens above the Exit Channel":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens below the Exit Channel":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The bar closes below the Entry Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band);
break;
case "The bar closes above the Entry Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band);
break;
case "The bar closes below the Exit Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band);
break;
case "The bar closes above the Exit Channel":
BandIndicatorLogic(iFirstBar, iPrvs, adEntryChannel, adExitChannel, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band);
break;
}
}
}
public override void SetDescription()
{
switch (IndParam.ListParam[0].Text)
{
case "Enter long at the Entry Channel":
EntryPointLongDescription = "at the Entry Channel of " + ToString();
EntryPointShortDescription = "at the Exit Channel of " + ToString();
break;
case "Enter long at the Exit Channel":
EntryPointLongDescription = "at the Exit Channel of " + ToString();
EntryPointShortDescription = "at the Entry Channel of " + ToString();
break;
case "Exit long at the Entry Channel":
ExitPointLongDescription = "at the Entry Channel of " + ToString();
ExitPointShortDescription = "at the Exit Channel of " + ToString();
break;
case "Exit long at the Exit Channel":
ExitPointLongDescription = "at the Exit Channel of " + ToString();
ExitPointShortDescription = "at the Entry Channel of " + ToString();
break;
case "The bar opens below the Entry Channel":
EntryFilterLongDescription = "the bar opens below the Entry Channel of " + ToString();
EntryFilterShortDescription = "the bar opens above the Exit Channel of " + ToString();
break;
case "The bar opens above the Entry Channel":
EntryFilterLongDescription = "the bar opens above the Entry Channel of " + ToString();
EntryFilterShortDescription = "the bar opens below the Exit Channel of " + ToString();
break;
case "The bar opens below the Exit Channel":
EntryFilterLongDescription = "the bar opens below the Exit Channel of " + ToString();
EntryFilterShortDescription = "the bar opens above the Entry Channel of " + ToString();
break;
case "The bar opens above the Exit Channel":
EntryFilterLongDescription = "the bar opens above the Exit Channel of " + ToString();
EntryFilterShortDescription = "the bar opens below the Entry Channel of " + ToString();
break;
case "The bar opens below the Entry Channel after opening above it":
EntryFilterLongDescription = "the bar opens below the Entry Channel of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Exit Channel of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Entry Channel after opening below it":
EntryFilterLongDescription = "the bar opens above the Entry Channel of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Exit Channel of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar opens below the Exit Channel after opening above it":
EntryFilterLongDescription = "the bar opens below the Exit Channel of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Entry Channel of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Exit Channel after opening below it":
EntryFilterLongDescription = "the bar opens above the Exit Channel of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Entry Channel of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar closes below the Entry Channel":
ExitFilterLongDescription = "the bar closes below the Entry Channel of " + ToString();
ExitFilterShortDescription = "the bar closes above the Exit Channel of " + ToString();
break;
case "The bar closes above the Entry Channel":
ExitFilterLongDescription = "the bar closes above the Entry Channel of " + ToString();
ExitFilterShortDescription = "the bar closes below the Exit Channel of " + ToString();
break;
case "The bar closes below the Exit Channel":
ExitFilterLongDescription = "the bar closes below the Exit Channel of " + ToString();
ExitFilterShortDescription = "the bar closes above the Entry Channel of " + ToString();
break;
case "The bar closes above the Exit Channel":
ExitFilterLongDescription = "the bar closes above the Exit Channel of " + ToString();
ExitFilterShortDescription = "the bar closes below the Entry Channel of " + ToString();
break;
}
}
public override string ToString()
{
return IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.ListParam[2].Text + ", " + // Price
IndParam.NumParam[0].ValueToString + ", " + // Look Back
IndParam.NumParam[1].ValueToString + ")"; // K Coeff
}
protected double[] HilbertPeriod(double[] adPrice)
{
double[] adPeriod = new double[Bars];
double[] adSmoother = new double[Bars];
double[] adDetrender = new double[Bars];
double[] Q1 = new double[Bars];
double[] I1 = new double[Bars];
double[] jI = new double[Bars];
double[] jQ = new double[Bars];
double[] I2 = new double[Bars];
double[] Q2 = new double[Bars];
double[] Re = new double[Bars];
double[] Im = new double[Bars];
double X1; double X2; double Y1; double Y2;
for(int iBar=6; iBar1.5*adPeriod[iBar-1]) adPeriod[iBar] = 1.5*adPeriod[iBar-1];
if (adPeriod[iBar]<.67*adPeriod[iBar-1]) adPeriod[iBar] = .67*adPeriod[iBar-1];
if (adPeriod[iBar]<6) adPeriod[iBar] = 6;
if (adPeriod[iBar]>50) adPeriod[iBar] = 50;
adPeriod[iBar] = .2*adPeriod[iBar] + .8*adPeriod[iBar-1];
}
return adPeriod;
}
}
}
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2025, Forex Software Ltd.;
Copyright © 2006 - 2025, Forex Software Ltd.;