Time Grid by Popov

52601 downloads / 4853 views / Created: 26.04.2016
 Average Rating: 0

Indicator Description

Allows entry at a round minute within a time interval.
For example: Enter at every 15 minutes from 08:00 to 11:30.



Forum topic Entry every x minutes

Comments

Thank You for this sir!
//============================================================== // Forex Strategy Builder // Copyright © Miroslav Popov. All rights reserved. //============================================================== // THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. //============================================================== using System; using System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class TimeGrid : Indicator { public TimeGrid() { IndicatorName = "Time Grid"; PossibleSlots = SlotTypes.OpenFilter; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "1.0"; IndicatorDescription = "Allows entry at every round hour"; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // Setting up the indicator parameters IndParam.IndicatorType = TypeOfIndicator.DateTime; IndParam.IsAllowLTF = false; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "Bar opens at round 1 min", "Bar opens at round 5 min", "Bar opens at round 15 min", "Bar opens at round 30 min", "Bar opens at round 60 min", }; IndParam.ListParam[0].Index = 0; IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Logic of application of the indicator."; IndParam.NumParam[0].Caption = "From hour (incl.)"; IndParam.NumParam[0].Value = 8; IndParam.NumParam[0].Min = 0; IndParam.NumParam[0].Max = 23; IndParam.NumParam[0].Point = 0; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The beginning of the trading period"; IndParam.NumParam[1].Caption = "Until hour (excl.)"; IndParam.NumParam[1].Value = 16; IndParam.NumParam[1].Min = 0; IndParam.NumParam[1].Max = 24; IndParam.NumParam[1].Point = 0; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The the of the trading period."; } public override void Calculate(IDataSet dataSet) { int logic = IndParam.ListParam[0].Index; int minutes = 1; if (logic == 1) minutes = 5; if (logic == 2) minutes = 15; if (logic == 3) minutes = 30; if (logic == 4) minutes = 0; DataSet = dataSet; // Reading the parameters int fromHour = (int)IndParam.NumParam[0].Value; int toHour = (int)IndParam.NumParam[1].Value; // Calculation int firstBar = 2; double[] signal = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { if (minutes == 0 && Time[bar].Minute != 0) { signal[bar] = 0; continue; } if (minutes != 0 && Time[bar].Minute % minutes != 0) { signal[bar] = 0; continue; } if (fromHour < toHour) signal[bar] = Time[bar].Hour >= fromHour && Time[bar].Hour < toHour ? 1 : 0; else if (fromHour > toHour) signal[bar] = Time[bar].Hour >= fromHour || Time[bar].Hour < toHour ? 1 : 0; else signal[bar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = firstBar; Component[0].Value = signal; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = firstBar; Component[1].Value = signal; } public override void SetDescription() { int fromHour = (int)IndParam.NumParam[0].Value; int toHour = (int)IndParam.NumParam[1].Value; int logic = IndParam.ListParam[0].Index; int minutes = 1; if (logic == 1) minutes = 5; if (logic == 2) minutes = 15; if (logic == 3) minutes = 30; if (logic == 3) minutes = 60; EntryFilterLongDescription = "the bar opens at round " + minutes + " hour from " + fromHour + " (incl.) to " + toHour + " (excl.)"; EntryFilterShortDescription = "the bar opens at round " + minutes + " hour from "+ fromHour + " (incl.) to " + toHour + " (excl.)"; } public override string ToString() { int fromHour = (int)IndParam.NumParam[0].Value; int toHour = (int)IndParam.NumParam[1].Value; return IndicatorName + " (" + fromHour + ", " + toHour + ")"; } } }
//+--------------------------------------------------------------------+ //| 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 <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> 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); }
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2024, Forex Software Ltd.;