Time Grid by Popov
55749 downloads / 6283 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
For example: Enter at every 15 minutes from 08:00 to 11:30.

Forum topic Entry every x minutes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
//==============================================================
// 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 + ")";
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108//+--------------------------------------------------------------------+ //| 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 - 2025, Forex Software Ltd.;
Copyright © 2006 - 2025, Forex Software Ltd.;