//+--------------------------------------------------------------------+ //| Copyright: (C) 2016 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 Forex Software Ltd." #property link "http://forexsb.com" #property version "2.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class WaddahAttarExplosion : public Indicator { public: WaddahAttarExplosion(SlotTypes slotType) { SlotType=slotType; IndicatorName="Waddah Attar Explosion"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void WaddahAttarExplosion::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); MAMethod maMethod = (MAMethod )ListParam[1].Index; MAMethod slMethod = (MAMethod )ListParam[3].Index; BasePrice basePrice = (BasePrice)ListParam[2].Index; int nSlow = 40; int Sensetive = (int)NumParam[0].Value; int nFast = 20; int DeadZonePip = (int)NumParam[1].Value; int ExplosionPower = (int)NumParam[2].Value; int TrendPower = (int)NumParam[3].Value; int previous=CheckParam[0].Checked ? 1 : 0; int firstBar = MathMax(nSlow, MathMax(nFast, 20)) + 3; double point = (Data.Digits == 5 || Data.Digits == 3) ? 10 * Data.Point : Data.Point; double adMACD[]; ArrayResize(adMACD,Data.Bars); ArrayInitialize(adMACD,0); double upperBand[]; ArrayResize(upperBand,Data.Bars); ArrayInitialize(upperBand,0); double lowerBand[]; ArrayResize(lowerBand,Data.Bars); ArrayInitialize(lowerBand,0); double buy[]; ArrayResize(buy,Data.Bars); ArrayInitialize(buy,0); double sell[]; ArrayResize(sell,Data.Bars); ArrayInitialize(sell,0); double ind_buffer1[]; ArrayResize(ind_buffer1,Data.Bars); ArrayInitialize(ind_buffer1,0); double ind_buffer2[]; ArrayResize(ind_buffer2,Data.Bars); ArrayInitialize(ind_buffer2,0); double ind_buffer3[]; ArrayResize(ind_buffer3,Data.Bars); ArrayInitialize(ind_buffer3,0); double ind_buffer4[]; ArrayResize(ind_buffer4,Data.Bars); ArrayInitialize(ind_buffer4,0); double Trend1 = 0; double Trend2 = 0; double Explo1 = 0; double Explo2 = 0; double Dead = point * DeadZonePip; double pwrt = 0; double pwre = 0; double price[]; Price(basePrice,price); double adMASlow[]; MovingAverage(nSlow, 0, maMethod, price, adMASlow); double adMAFast[]; MovingAverage(nFast, 0, maMethod, price, adMAFast); double ma[]; MovingAverage(20, 0, slMethod, price, ma); for (int bar = firstBar; bar < Data.Bars; bar++) { double sum = 0; for (int i = 0; i < 20; i++) { double delta = (price[bar - i] - ma[bar]); sum += delta * delta; } double stdDev = MathSqrt(sum / 20); upperBand[bar] = ma[bar] + 2.0 * stdDev; lowerBand[bar] = ma[bar] - 2.0 * stdDev; adMACD[bar] = adMAFast[bar] - adMASlow[bar]; Trend1 = (adMACD[bar-1] - adMACD[bar-2]) * Sensetive; Trend2 = (adMACD[bar-3] - adMACD[bar-4]) * Sensetive; Explo1 = upperBand[bar-1] - lowerBand[bar-1]; Explo2 = upperBand[bar-2] - lowerBand[bar-2]; if(Trend1 >= 0) ind_buffer1[bar] = Trend1; if(Trend1 < 0) ind_buffer2[bar] = (-1*Trend1); ind_buffer3[bar] = Explo1; ind_buffer4[bar] = Dead; if(Trend1 > 0 && Trend1 > Explo1 && Trend1 > Dead && Explo1 > Dead && Explo1 > Explo2 && Trend1 > Trend2) { pwrt = 100*(Trend1 - Trend2) / Trend1; pwre = 100*(Explo1 - Explo2) / Explo1; if(pwre >= ExplosionPower && pwrt >= TrendPower) { if (ListParam[0].Index == 1) sell[bar] = 1; else buy[bar] = 1; } } if(Trend1 < 0 && MathAbs(Trend1) > Explo1 && MathAbs(Trend1) > Dead && Explo1 > Dead && Explo1 > Explo2 && MathAbs(Trend1) > MathAbs(Trend2)) { pwrt = 100*(MathAbs(Trend1) - MathAbs(Trend2)) / MathAbs(Trend1); pwre = 100*(Explo1 - Explo2) / Explo1; if(pwre >= ExplosionPower && pwrt >= TrendPower) { if (ListParam[0].Index == 1) buy[bar] = 1; else sell[bar] = 1; } } } ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Histogram"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value,ind_buffer1); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Line"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = firstBar; ArrayCopy(Component[1].Value,ind_buffer3); ArrayResize(Component[2].Value,Data.Bars); Component[2].CompName = "Line"; Component[2].DataType = IndComponentType_IndicatorValue; Component[2].FirstBar = firstBar; ArrayCopy(Component[2].Value,ind_buffer4); ArrayResize(Component[3].Value,Data.Bars); ArrayInitialize(Component[3].Value,0); Component[3].DataType = IndComponentType_AllowOpenLong; Component[3].CompName = "Allow entry"; Component[3].FirstBar=firstBar; ArrayCopy(Component[3].Value,buy); ArrayResize(Component[4].Value,Data.Bars); ArrayInitialize(Component[4].Value,0); Component[4].DataType = IndComponentType_AllowOpenShort; Component[4].CompName = "Allow entry"; Component[4].FirstBar=firstBar; ArrayCopy(Component[4].Value,sell); ArrayResize(Component[5].Value,Data.Bars); Component[5].CompName = "Histogram"; Component[5].DataType = IndComponentType_IndicatorValue; Component[5].FirstBar = firstBar; ArrayCopy(Component[5].Value,ind_buffer2); } //+------------------------------------------------------------------+