//+--------------------------------------------------------------------+ //| 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 #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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; iBaradBPFilter[iBar-2]) adBPPeak[iBar]=adBPFilter[iBar-1]; else adBPPeak[iBar]=adBPPeak[iBar-1]; if(adBPFilter[iBar]>adBPFilter[iBar-1] && adBPFilter[iBar-1]