//+--------------------------------------------------------------------+ //| 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 TimeGrid : public Indicator { public: TimeGrid(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Time Grid"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = true; } virtual void Calculate(DataSet &dataSet); }; void TimeGrid::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); // Reading the parameters int logic = ListParam[0].Index; int fromHour = (int) NumParam[0].Value; int toHour = (int) NumParam[1].Value; int minutes = 1; if (logic == 1) minutes = 5; if (logic == 2) minutes = 15; if (logic == 3) minutes = 30; if (logic == 4) minutes = 0; // Calculation const int firstBar = 2; double signal[]; ArrayResize(signal, Data.Bars); ArrayInitialize(signal, 0); // Calculation of the logic for (int bar = firstBar; bar < Data.Bars; bar++) { MqlDateTime mqlTime; TimeToStruct(Data.Time[bar], mqlTime); if (minutes == 0 && mqlTime.min != 0) { signal[bar] = 0; continue; } if (minutes != 0 && mqlTime.min % minutes != 0) { signal[bar] = 0; continue; } if (fromHour < toHour) signal[bar] = mqlTime.hour >= fromHour && mqlTime.hour < toHour ? 1 : 0; else if (fromHour > toHour) signal[bar] = mqlTime.hour >= fromHour || mqlTime.hour < toHour ? 1 : 0; else signal[bar] = 1; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Is long entry allowed"; Component[0].DataType = IndComponentType_AllowOpenLong; Component[0].ShowInDynInfo = false; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value, signal); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Is short entry allowed"; Component[1].DataType = IndComponentType_AllowOpenShort; Component[1].ShowInDynInfo = false; Component[1].FirstBar = firstBar; ArrayCopy(Component[1].Value,signal); }