01 // Entry Time indicator
02 // Forex Strategy Builder v2.8.1.1
03 // Copyright (c) 2006 - 2009 Miroslav Popov - All rights reserved!
04 // Last changed on: 2009-04-15
05 // http://forexsb.com
06
07 using System;
08
09 namespace Forex_Strategy_Builder
10 {
11 /// <summary>
12 /// Entry Time indicator
13 /// </summary>
14 public class Entry_Time : Indicator
15 {
16 /// <summary>
17 /// Sets the default indicator parameters for the designated slot type
18 /// </summary>
19 public Entry_Time(SlotTypes slotType)
20 {
21 // General properties
22 IndicatorName = "Entry Time";
23 PossibleSlots = SlotTypes.OpenFilter;
24
25 // Setting up the indicator parameters
26 IndParam = new IndicatorParam();
27 IndParam.IndicatorName = IndicatorName;
28 IndParam.SlotType = slotType;
29 IndParam.IndicatorType = TypeOfIndicator.DateTime;
30
31 // The ComboBox parameters
32 IndParam.ListParam[0].Caption = "Logic";
33 IndParam.ListParam[0].ItemList = new string[]
34 {
35 "Enter the market between the specified hours"
36 };
37 IndParam.ListParam[0].Index = 0;
38 IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
39 IndParam.ListParam[0].Enabled = true;
40 IndParam.ListParam[0].ToolTip = "Indicator's logic.";
41
42 // The NumericUpDown parameters
43 IndParam.NumParam[0].Caption = "From hour (incl.)";
44 IndParam.NumParam[0].Value = 0;
45 IndParam.NumParam[0].Min = 0;
46 IndParam.NumParam[0].Max = 23;
47 IndParam.NumParam[0].Enabled = true;
48 IndParam.NumParam[0].ToolTip = "Beginning of the entry period.";
49
50 IndParam.NumParam[1].Caption = "From min (incl.)";
51 IndParam.NumParam[1].Value = 0;
52 IndParam.NumParam[1].Min = 0;
53 IndParam.NumParam[1].Max = 59;
54 IndParam.NumParam[1].Enabled = true;
55 IndParam.NumParam[1].ToolTip = "Beginning of the entry period.";
56
57 IndParam.NumParam[2].Caption = "Until hour (excl.)";
58 IndParam.NumParam[2].Value = 24;
59 IndParam.NumParam[2].Min = 0;
60 IndParam.NumParam[2].Max = 24;
61 IndParam.NumParam[2].Enabled = true;
62 IndParam.NumParam[2].ToolTip = "End of the entry period.";
63
64 IndParam.NumParam[3].Caption = "Until min( excl.)";
65 IndParam.NumParam[3].Value = 0;
66 IndParam.NumParam[3].Min = 0;
67 IndParam.NumParam[3].Max = 59;
68 IndParam.NumParam[3].Enabled = true;
69 IndParam.NumParam[3].ToolTip = "End of the entry period.";
70
71 return;
72 }
73
74 /// <summary>
75 /// Calculates the indicator's components
76 /// </summary>
77 public override void Calculate(SlotTypes slotType)
78 {
79 // Reading the parameters
80 int iFromHour = (int)IndParam.NumParam[0].Value;
81 int iFromMin = (int)IndParam.NumParam[1].Value;
82 int iUntilHour = (int)IndParam.NumParam[2].Value;
83 int iUntilMin = (int)IndParam.NumParam[3].Value;
84 TimeSpan tsFromTime = new TimeSpan(iFromHour, iFromMin, 0);
85 TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0);
86
87 // Calculation
88 int iFirstBar = 1;
89 double[] adBars = new double[Bars];
90
91 // Calculation of the logic
92 for (int iBar = iFirstBar; iBar < Bars; iBar++)
93 {
94 if(tsFromTime < tsUntilTime)
95 adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime &&
96 Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0;
97 else if(tsFromTime > tsUntilTime)
98 adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime ||
99 Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0;
100 else
101 adBars[iBar] = 1;
102 }
103
104 // Saving the components
105 Component = new IndicatorComp[2];
106
107 Component[0] = new IndicatorComp();
108 Component[0].CompName = "Is long entry allowed";
109 Component[0].DataType = IndComponentType.AllowOpenLong;
110 Component[0].ChartType = IndChartType.NoChart;
111 Component[0].ShowInDynInfo = false;
112 Component[0].FirstBar = iFirstBar;
113 Component[0].Value = adBars;
114
115 Component[1] = new IndicatorComp();
116 Component[1].CompName = "Is short entry allowed";
117 Component[1].DataType = IndComponentType.AllowOpenShort;
118 Component[1].ChartType = IndChartType.NoChart;
119 Component[1].ShowInDynInfo = false;
120 Component[1].FirstBar = iFirstBar;
121 Component[1].Value = adBars;
122
123 return;
124 }
125
126 /// <summary>
127 /// Sets the indicator logic description
128 /// </summary>
129 public override void SetDescription(SlotTypes slotType)
130 {
131 int iFromHour = (int)IndParam.NumParam[0].Value;
132 int iFromMin = (int)IndParam.NumParam[1].Value;
133 int iUntilHour = (int)IndParam.NumParam[2].Value;
134 int iUntilMin = (int)IndParam.NumParam[3].Value;
135
136 string sFromTime = iFromHour.ToString("00") + ":" + iFromMin.ToString("00");
137 string sUntilTime = iUntilHour.ToString("00") + ":" + iUntilMin.ToString("00");
138
139 EntryFilterLongDescription = "the entry time is between " + sFromTime + " (incl.) and " + sUntilTime + " (
140 excl.)";
141 EntryFilterShortDescription = "the entry time is between " + sFromTime + " (incl.) and " + sUntilTime + " (
142 excl.)";
143
144 return;
145 }
146
147 /// <summary>
148 /// Indicator to string
149 /// </summary>
150 public override string ToString()
151 {
152 int iFromHour = (int)IndParam.NumParam[0].Value;
153 int iFromMin = (int)IndParam.NumParam[1].Value;
154 int iUntilHour = (int)IndParam.NumParam[2].Value;
155 int iUntilMin = (int)IndParam.NumParam[3].Value;
156
157 string sFromTime = iFromHour.ToString("00") + ":" + iFromMin.ToString("00");
158 string sUntilTime = iUntilHour.ToString("00") + ":" + iUntilMin.ToString("00");
159
160 string sString = IndicatorName + " (" +
161 sFromTime + " - " + // From
162 sUntilTime + ")"; // Until
163
164 return sString;
165 }
166 }
167 }
Top