//+--------------------------------------------------------------------+ //| Copyright: (C) 2015 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) 2015 Forex Software Ltd." #property link "http://forexsb.com" #property version "1.00" #property strict #include #include #include //## Requires CommodityChannelIndex.mqh class Sonic : public Indicator { public: Sonic(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Sonic"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; void Sonic::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); // Reading the parameters MAMethod maMethod=(MAMethod) ListParam[2].Index; int volumePeriod = (int) NumParam[0].Value; int previous = CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = volumePeriod + previous + 2; double averageVolume[]; ArrayResize(averageVolume, Data.Bars); ArrayInitialize(averageVolume, 0); for (int bar = firstBar; bar < Data.Bars; bar++) { int sum = 0; for (int n = bar - 1; n >= bar - volumePeriod; n--) sum += (int) Data.Volume[n]; averageVolume[bar] = 1.0*sum/volumePeriod; } // Rising Volume double volumeType[]; ArrayResize(volumeType, Data.Bars); ArrayInitialize(volumeType, 0); for (int bar = firstBar; bar < Data.Bars; bar++) if (Data.Volume[bar] >= 1.5*averageVolume[bar]) volumeType[bar] = 2; // Climax Volume for (int bar = firstBar; bar < Data.Bars; bar++) { double highVolRange = 0; double volumeRange = Data.Volume[bar]*(Data.High[bar] - Data.Low[bar]); for (int n = bar - 1; n >= bar - volumePeriod; n--) { double volRange = Data.Volume[n]*(Data.High[n] - Data.Low[n]); if (highVolRange < volRange) highVolRange = volRange; } if (volumeRange >= highVolRange || Data.Volume[bar] >= 2.0*averageVolume[bar]) volumeType[bar] = 1; } // Bar type double buyZone[]; ArrayResize(buyZone, Data.Bars); ArrayInitialize(buyZone, 0); double sellZone[]; ArrayResize(sellZone, Data.Bars); ArrayInitialize(sellZone, 0); for (int bar = firstBar; bar < Data.Bars; bar++) { if (SlotType == SlotTypes_OpenFilter && volumeType[bar] == 2) { // Enter on a rising volume bar buyZone[bar] = Data.Close[bar] > Data.Open[bar] ? 1 : 0; sellZone[bar] = Data.Close[bar] < Data.Open[bar] ? 1 : 0; } else if (SlotType == SlotTypes_CloseFilter && volumeType[bar] == 1) { // Exit on a climax bar buyZone[bar] = Data.Close[bar] > Data.Open[bar] ? 1 : 0; sellZone[bar] = Data.Close[bar] < Data.Open[bar] ? 1 : 0; } } // Shift signal if it is necessary if (previous > 0) { for (int bar = Data.Bars - 1; bar >= firstBar; bar--) { buyZone[bar] = buyZone[bar - 1]; sellZone[bar] = sellZone[bar - 1]; } } // Saving the components ArrayResize(Component[0].Value, Data.Bars); Component[0].FirstBar = firstBar; ArrayResize(Component[1].Value, Data.Bars); Component[1].FirstBar = firstBar; // Sets the Component's type if (SlotType == SlotTypes_OpenFilter) { Component[0].DataType = IndComponentType_AllowOpenLong; Component[0].CompName = "Is long entry allowed"; ArrayCopy(Component[0].Value, buyZone); Component[1].DataType = IndComponentType_AllowOpenShort; Component[1].CompName = "Is short entry allowed"; ArrayCopy(Component[1].Value, sellZone); } else if (SlotType == SlotTypes_CloseFilter) { Component[0].DataType = IndComponentType_ForceCloseLong; Component[0].CompName = "Close out long position"; ArrayCopy(Component[0].Value, sellZone); Component[1].DataType = IndComponentType_ForceCloseShort; Component[1].CompName = "Close out short position"; ArrayCopy(Component[1].Value, buyZone); } }