//+--------------------------------------------------------------------+ //| 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 LowPassFilter : public Indicator { public: LowPassFilter(SlotTypes slotType) { SlotType=slotType; IndicatorName="LowPass Filter"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void LowPassFilter::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters BasePrice basePrice = (BasePrice)ListParam[1].Index; int iPeriod = (int)NumParam[0].Value; int iShift = (int)NumParam[1].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // TimeExecution if(basePrice == BasePrice_Open && iPeriod == 1 && iShift == 0) ExecTime = ExecutionTime_AtBarOpening; // Calculation double adPrice[]; Price(basePrice,adPrice); double adLowPass[]; ArrayResize(adLowPass,Data.Bars);ArrayInitialize(adLowPass, 0); double lp[]; ArrayResize(lp,Data.Bars);ArrayInitialize(lp, 0); double MathPI=3.14159265359; double a = MathExp(-MathPI/iPeriod); double b = 2*a*MathCos(MathSqrt(3)*MathPI/iPeriod); double c=MathExp(-2*MathPI/iPeriod); //a * a; int iFirstBar = 24 + iShift + 2 + iPrvs; for (int iBar = 4; iBar < Data.Bars - iShift; iBar++) { lp[iBar] = (b + c) * lp[iBar - 1] - (c + b * c) * lp[iBar - 2] + c * c * lp[iBar - 3] + (1 - b + c) * (1 - c) * adPrice[iBar]; adLowPass[iBar+iShift] = lp[iBar]; } // Saving the components if(SlotType==SlotTypes_Open || SlotType==SlotTypes_Close) { ArrayResize(Component[1].Value,Data.Bars); for(int iBar=iFirstBar; iBarData.High[iBar-1] && dValue Data.Open[iBar]) || // The Data.Open price jumps below the indicator (Data.Close[iBar - 1] < dValue && dValue < Data.Open[iBar]) || // The Data.Open price is in a positive gap (Data.Close[iBar - 1] > dValue && dValue > Data.Open[iBar])) // The Data.Open price is in a negative gap dTempVal=Data.Open[iBar]; Component[1].Value[iBar]=dTempVal; // Entry or exit value } } else { ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=iFirstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; } ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "MA Value"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adLowPass); if(SlotType==SlotTypes_Open) { Component[1].CompName = "Position opening price"; Component[1].DataType = IndComponentType_OpenPrice; } else if(SlotType==SlotTypes_OpenFilter) { Component[1].DataType = IndComponentType_AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType_AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if(SlotType==SlotTypes_Close) { Component[1].CompName = "Position closing price"; Component[1].DataType = IndComponentType_ClosePrice; } else if(SlotType==SlotTypes_CloseFilter) { Component[1].DataType = IndComponentType_ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType_ForceCloseShort; Component[2].CompName = "Close out short position"; } if(SlotType==SlotTypes_OpenFilter || SlotType==SlotTypes_CloseFilter) { if(ListParam[0].Text=="LowPass rises") { IndicatorRisesLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } else if(ListParam[0].Text=="LowPass falls") { IndicatorFallsLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above LowPass") { BarOpensAboveIndicatorLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens below LowPass") { BarOpensBelowIndicatorLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above LowPass after opening below it") { BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar,iPrvs,adLowPass,Component[1], Component[2]); } else if(ListParam[0].Text=="The bar opens below LowPass after opening above it") { BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar,iPrvs,adLowPass,Component[1], Component[2]); } else if(ListParam[0].Text=="The position opens above LowPass") { Component[0].PosPriceDependence=PositionPriceDependence_BuyHigherSellLower; Component[0].UsePreviousBar=iPrvs; Component[1].DataType=IndComponentType_Other; Component[1].ShowInDynInfo=false; Component[2].DataType=IndComponentType_Other; Component[2].ShowInDynInfo=false; } else if(ListParam[0].Text=="The position opens below LowPass") { Component[0].PosPriceDependence=PositionPriceDependence_BuyLowerSelHigher; Component[0].UsePreviousBar=iPrvs; Component[1].DataType=IndComponentType_Other; Component[1].ShowInDynInfo=false; Component[2].DataType=IndComponentType_Other; Component[2].ShowInDynInfo=false; } else if(ListParam[0].Text=="The bar closes below LowPass") { BarClosesBelowIndicatorLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar closes above LowPass") { BarClosesAboveIndicatorLogic(iFirstBar,iPrvs,adLowPass,Component[1],Component[2]); } } } //+------------------------------------------------------------------+