//+--------------------------------------------------------------------+ //| 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 Buddahcandleindicator : public Indicator { public: Buddahcandleindicator(SlotTypes slotType) { SlotType=slotType; IndicatorName="Buddah candle indicator"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Buddahcandleindicator::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters BasePrice fastbasePrice = (BasePrice)ListParam[1].Index; BasePrice slowbasePrice = (BasePrice)ListParam[2].Index; MAMethod fastMAMethod = (MAMethod )ListParam[3].Index; MAMethod slowMAMethod = (MAMethod )ListParam[4].Index; int iNFastMA = (int)NumParam[0].Value; int iNSlowMA = (int)NumParam[1].Value; int iSFastMA = (int)NumParam[2].Value; int iSSlowMA = (int)NumParam[3].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; int iFirstBar=(int)MathMax(iNFastMA+iSFastMA,iNSlowMA+iSSlowMA)+2; double fastPrice[]; Price(fastbasePrice,fastPrice); double slowPrice[]; Price(slowbasePrice,slowPrice); double adMAFast[]; MovingAverage(iNFastMA,iSFastMA,fastMAMethod,fastPrice,adMAFast); double adMASlow[]; MovingAverage(iNSlowMA,iSSlowMA,slowMAMethod,slowPrice,adMASlow); // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Fast Moving Average"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adMAFast); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Slow Moving Average"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = iFirstBar; ArrayCopy(Component[1].Value,adMASlow); ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; ArrayResize(Component[3].Value,Data.Bars); Component[3].FirstBar=iFirstBar; // 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"; } // Calculation of the logic IndicatorLogic indLogic=IndicatorLogic_It_does_not_act_as_a_filter; if(ListParam[0].Text=="Flying Buddah") { for(int iBar=iFirstBar+iPrvs; iBaradMAFast[iBar-iPrvs]&& Data.Low[iBar-1]>adMASlow[iBar-iPrvs] ? 1 : 0; Component[3].Value[iBar]=Data.High[iBar-1]adMAFast[iBar-iPrvs]&& Data.Low[iBar-1]>adMASlow[iBar-iPrvs] ? 1 : 0; } } } //+------------------------------------------------------------------+