//+--------------------------------------------------------------------+ //| Copyright: (C) 2014 Forex Software Ltd. | //| 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 | //| other applications without a permission. | //| The 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 (C) 2016 Laurent Wiart." #property link "" #property version "1.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class MACDZeroLag : public Indicator { public: MACDZeroLag(SlotTypes slotType) { SlotType=slotType; IndicatorName="MACD Zero Lag"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void MACDZeroLag::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters MAMethod maMethod = (MAMethod) ListParam[1].Index; MAMethod slMethod = (MAMethod) ListParam[3].Index; BasePrice basePrice = (BasePrice) ListParam[2].Index; int nSlow = (int) NumParam[0].Value; int nFast = (int) NumParam[1].Value; int nSignal = (int) NumParam[2].Value; double dLevel = NumParam[3].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar=nSlow+nFast+2; double basePrc[]; Price(basePrice,basePrc); double adMASlow[]; MovingAverage(nSlow,0,maMethod,basePrc,adMASlow); double adMAFast[]; MovingAverage(nFast,0,maMethod,basePrc,adMAFast); double MAOfMASlow[]; MovingAverage(nSlow,0,maMethod,adMASlow,MAOfMASlow); double MAOfMAFast[]; MovingAverage(nFast,0,maMethod,adMAFast,MAOfMAFast); double adMACDZR[]; ArrayResize(adMACDZR,Data.Bars); ArrayInitialize(adMACDZR,0); double adSlowMACDZR[]; ArrayResize(adSlowMACDZR,Data.Bars); ArrayInitialize(adSlowMACDZR,0); double adFastMACDZR[]; ArrayResize(adFastMACDZR,Data.Bars); ArrayInitialize(adFastMACDZR,0); //ZeroLAG MACD(i) = (2*EMA(Close, FP, i) - EMA(EMA(Close, FP, i), FP, i)) - (2*EMA(Close, SP, i) - EMA(EMA(Close, SP, i), SP, i)); for(int iBar=nSlow-1; iBar