Bandpass Filter by zuijaideai

43966 downloads / 3240 views / Created: 23.05.2013
 Average Rating: 0

Indicator Description

Hi All,
This is the latest indicator at the moment, appears in TASC magazine Mar 2010 by John Ehlers. Read the following topics on Empirical Mode Decomposition regarding this indicator.

Traders Tips

- the pink line is the Bandpass Filter or Smoothed Bandpass Filter.
- the green line is the Peak Average of the Bandpass Filter
- the red line is the Valley Average of the Bandpass Filter

Bandpass Filter

Link to the forum topic: Bandpass Filter

Best Rgds
Denny Imanuel
imanuel.denny@gmail.com

Comments

//============================================================== // 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 BandpassFilter : Indicator { public BandpassFilter() { // General properties IndicatorName = "Bandpass Filter"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; SeparatedChart = true; IndicatorAuthor = "Denny Imanuel"; IndicatorVersion = "2.0"; IndicatorDescription = "A custom indicator for FSB and FST."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "The Bandpass Filter line rises", "The Bandpass Filter line falls", "The Bandpass Filter line is higher than zero", "The Bandpass Filter line is lower than zero", "The Bandpass Filter line crosses the zero line upward", "The Bandpass Filter line crosses the zero line downward", "The Bandpass Filter line changes its direction upward", "The Bandpass Filter line changes its direction downward", "The Bandpass Filter line crosses the Average Peak upward", "The Bandpass Filter line crosses the Average Valley downward", "The Bandpass Filter line is higher than the Average Peak", "The Bandpass Filter line is lower than the Average Valley" }; 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[1].Caption = "Smoothing method"; IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod)); IndParam.ListParam[1].Index = (int)MAMethod.Simple; IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index]; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "The smoothing method of Moving Average."; 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 Moving Average is based on."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Bandpass Period"; IndParam.NumParam[0].Value = 10; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 200; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The period of bandpass filter calculation."; IndParam.NumParam[1].Caption = "Smoothing Period"; IndParam.NumParam[1].Value = 20; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 200; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The period of bandpass filter calculation."; IndParam.NumParam[2].Caption = "Bandpass Delta"; IndParam.NumParam[2].Value = 0.5; IndParam.NumParam[2].Min = 0; IndParam.NumParam[2].Max = 10; IndParam.NumParam[2].Point = 2; IndParam.NumParam[2].Enabled = true; IndParam.NumParam[2].ToolTip = "The delta value for bandpass filter."; IndParam.NumParam[3].Caption = "Bandwidth Multiplier"; IndParam.NumParam[3].Value = 0.1; IndParam.NumParam[3].Min = 0; IndParam.NumParam[3].Max = 10; IndParam.NumParam[3].Point = 2; IndParam.NumParam[3].Enabled = true; IndParam.NumParam[3].ToolTip = "The divisor to determine the upper and lower bandwidth."; // 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."; IndParam.CheckParam[1].Caption = "Use smoothed bandpass filter"; IndParam.CheckParam[1].Checked = true; IndParam.CheckParam[1].Enabled = true; IndParam.CheckParam[1].ToolTip = "Use the smoothed value of bandpass filter."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int iSmooth = (int)IndParam.NumParam[1].Value; double Delta = IndParam.NumParam[2].Value; double dMpl = IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; double[] adPrice = Price(basePrice); double[] adBPFilter = new double[Bars]; double[] adBPSignal = new double[Bars]; double[] adBPPeak = new double[Bars]; double[] adBPValley = new double[Bars]; double[] adAvgPeak = new double[Bars]; double[] adAvgValley = new double[Bars]; // Calculation int iFirstBar = iPeriod + 2; double Beta = Math.Cos(2*Math.PI/iPeriod); double Gamma = 1/Math.Cos(4*Math.PI*Delta/iPeriod); double Alpha = Gamma - Math.Sqrt(Math.Pow(Gamma,2)-1); double Theta = 0.5*(1-Alpha); double Omega = Beta*(1+Alpha); for (int iBar = 2; iBar < Bars; iBar++) { adBPFilter[iBar] = Theta*(adPrice[iBar] - adPrice[iBar-2]) + Omega*adBPFilter[iBar-1] - Alpha*adBPFilter[iBar-2]; if (adBPFilter[iBar]adBPFilter[iBar-2]) adBPPeak[iBar] = adBPFilter[iBar-1]; else adBPPeak[iBar] = adBPPeak[iBar-1]; if (adBPFilter[iBar]>adBPFilter[iBar-1] && adBPFilter[iBar-1]
//+--------------------------------------------------------------------+ //| Copyright: (C) 2014, Miroslav Popov - All rights reserved! | //| Website: http://forexsb.com/ | //| Support: http://forexsb.com/forum/ | //| License: Proprietary under the following circumstances: | //| | //| This code is a part of Forex Strategy Builder. It is free for | //| use as an integral part of Forex Strategy Builder. | //| One can modify it in order to improve the code or to fit it for | //| personal use. This code or any part of it cannot be used in | //| another applications without a permission. Contact information | //| cannot be changed. | //| | //| NO LIABILITY FOR CONSEQUENTIAL DAMAGES | //| | //| In no event shall the author be liable for any damages whatsoever | //| (including, without limitation, incidental, direct, indirect and | //| consequential damages, damages for loss of business profits, | //| business interruption, loss of business information, or other | //| pecuniary loss) arising out of the use or inability to use this | //| product, even if advised of the possibility of such damages. | //+--------------------------------------------------------------------+ #property copyright "Copyright 2014, Miroslav Popov" #property link "http://forexsb.com" #property version "1.00" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class BandpassFilter : public Indicator { public: BandpassFilter(SlotTypes slotType) { SlotType=slotType; IndicatorName="Bandpass Filter"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void BandpassFilter::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters MAMethod maMethod=(MAMethod)ListParam[1].Index; BasePrice basePrice=(BasePrice)ListParam[2].Index; int iPeriod = (int)NumParam[0].Value; int iSmooth = (int)NumParam[1].Value; double Delta=NumParam[2].Value; double dMpl = NumParam[3].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; double adPrice[]; Price(basePrice,adPrice); double adBPFilter[]; ArrayResize(adBPFilter, Data.Bars);ArrayInitialize(adBPFilter,0); double adBPSignal[]; ArrayResize(adBPSignal, Data.Bars);ArrayInitialize(adBPSignal,0); double adBPPeak[]; ArrayResize(adBPPeak,Data.Bars); ArrayInitialize(adBPPeak,0); double adBPValley[]; ArrayResize(adBPValley,Data.Bars); ArrayInitialize(adBPValley,0); double adAvgPeak[]; ArrayResize(adAvgPeak,Data.Bars); ArrayInitialize(adAvgPeak,0); double adAvgValley[]; ArrayResize(adAvgValley,Data.Bars);ArrayInitialize(adAvgValley,0); // Calculation int iFirstBar=iPeriod+2; double MathPI=3.14159265359; double Beta=MathCos(2*MathPI/iPeriod); double Gamma = 1/MathCos(4*MathPI*Delta/iPeriod); double Alpha = Gamma - MathSqrt(MathPow(Gamma,2)-1); double Theta = 0.5*(1-Alpha); double Omega = Beta*(1+Alpha); for(int iBar=2; iBar<Data.Bars; iBar++) { adBPFilter[iBar]=Theta*(adPrice[iBar]-adPrice[iBar-2])+Omega*adBPFilter[iBar-1]-Alpha*adBPFilter[iBar-2]; if(adBPFilter[iBar]<adBPFilter[iBar-1] && adBPFilter[iBar-1]>adBPFilter[iBar-2]) adBPPeak[iBar]=adBPFilter[iBar-1]; else adBPPeak[iBar]=adBPPeak[iBar-1]; if(adBPFilter[iBar]>adBPFilter[iBar-1] && adBPFilter[iBar-1]<adBPFilter[iBar-2]) adBPValley[iBar]=adBPFilter[iBar-1]; else adBPValley[iBar]=adBPValley[iBar-1]; } if(CheckParam[1].Checked) MovingAverage(iSmooth,0,maMethod,adBPFilter,adBPSignal); else ArrayCopy(adBPSignal,adBPFilter); MovingAverage(iSmooth,0,maMethod,adBPPeak,adAvgPeak); MovingAverage(iSmooth,0,maMethod,adBPValley,adAvgValley); for(int iBar=2; iBar<Data.Bars; iBar++) { adAvgPeak[iBar]=dMpl*adAvgPeak[iBar]; adAvgValley[iBar]=dMpl*adAvgValley[iBar]; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Bandpass Filter"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adBPSignal); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "BandPass Signal"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = iFirstBar; ArrayCopy(Component[1].Value,adBPSignal); ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; ArrayResize(Component[3].Value,Data.Bars); Component[3].FirstBar=iFirstBar; ArrayResize(Component[4].Value,Data.Bars); Component[4].CompName = "Average Peak"; Component[4].DataType = IndComponentType_IndicatorValue; Component[4].FirstBar = iFirstBar; ArrayCopy(Component[4].Value,adAvgPeak); ArrayResize(Component[5].Value,Data.Bars); Component[5].CompName = "Average Valley"; Component[5].DataType = IndComponentType_IndicatorValue; Component[5].FirstBar = iFirstBar; ArrayCopy(Component[5].Value,adAvgValley); // Sets the Component's type 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_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(ListParam[0].Text=="The Bandpass Filter line rises") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_rises); } else if(ListParam[0].Text=="The Bandpass Filter line falls") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_falls); } else if(ListParam[0].Text=="The Bandpass Filter line is higher than zero") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_is_higher_than_the_level_line); } else if(ListParam[0].Text=="The Bandpass Filter line is lower than zero") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_is_lower_than_the_level_line); } else if(ListParam[0].Text=="The Bandpass Filter line crosses the zero line upward") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_crosses_the_level_line_upward); } else if(ListParam[0].Text=="The Bandpass Filter line crosses the zero line downward") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_crosses_the_level_line_downward); } else if(ListParam[0].Text=="The Bandpass Filter line changes its direction upward") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_changes_its_direction_upward); } else if(ListParam[0].Text=="The Bandpass Filter line changes its direction downward") { OscillatorLogic(iFirstBar,iPrvs,adBPSignal,0,0,Component[2],Component[3], IndicatorLogic_The_indicator_changes_its_direction_downward); } else if(ListParam[0].Text=="The Bandpass Filter line crosses the Average Peak upward") { IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar,iPrvs,adBPSignal,adAvgPeak,Component[2], Component[3]); } else if(ListParam[0].Text=="The Bandpass Filter line crosses the Average Valley downward") { IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar,iPrvs,adBPSignal,adAvgValley, Component[2],Component[3]); } else if(ListParam[0].Text=="The Bandpass Filter line is higher than the Average Peak") { IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar,iPrvs,adBPSignal,adAvgPeak,Component[2], Component[3]); } else if(ListParam[0].Text=="The Bandpass Filter line is lower than the Average Valley") { IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar,iPrvs,adBPSignal,adAvgValley,Component[2], Component[3]); } } //+------------------------------------------------------------------+
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 - 2024, Forex Software Ltd.;