01 // Oscillator of BBP Indicator
02 // Last changed on 2009-05-05
03 // Part of Forex Strategy Builder v2.8.3.7+
04 // Website http://forexsb.com/
05 // This code or any part of it cannot be used in other applications without a permission.
06 // Copyright (c) 2006 - 2009 Miroslav Popov - All rights reserved.
07
08 using System;
09
10 namespace Forex_Strategy_Builder
11 {
12 /// <summary>
13 /// Oscillator of BBP Indicator
14 /// </summary>
15 public class Oscillator_of_BBP : Indicator
16 {
17 /// <summary>
18 /// Sets the default indicator parameters for the designated slot type
19 /// </summary>
20 public Oscillator_of_BBP(SlotTypes slotType)
21 {
22 // General properties
23 IndicatorName = "Oscillator of BBP";
24 PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
25 SeparatedChart = true;
26
27 // Setting up the indicator parameters
28 IndParam = new IndicatorParam();
29 IndParam.IndicatorName = IndicatorName;
30 IndParam.SlotType = slotType;
31 IndParam.IndicatorType = TypeOfIndicator.OscillatorOfIndicators;
32
33 // The ComboBox parameters
34 IndParam.ListParam[0].Caption = "Logic";
35 IndParam.ListParam[0].ItemList = new string[]
36 {
37 "The Oscillator rises",
38 "The Oscillator falls",
39 "The Oscillator is higher than the zero line",
40 "The Oscillator is lower than the zero line",
41 "The Oscillator crosses the zero line upward",
42 "The Oscillator crosses the zero line downward",
43 "The Oscillator changes its direction upward",
44 "The Oscillator changes its direction downward"
45 };
46 IndParam.ListParam[0].Index = 0;
47 IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
48 IndParam.ListParam[0].Enabled = true;
49 IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
50
51 IndParam.ListParam[1].Caption = "Smoothing method";
52 IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
53 IndParam.ListParam[1].Index = (int)MAMethod.Simple;
54 IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
55 IndParam.ListParam[1].Enabled = true;
56 IndParam.ListParam[1].ToolTip = "The Moving Average method used for smoothing the BBP value.";
57
58 // The NumericUpDown parameters
59 IndParam.NumParam[0].Caption = "First BBP period";
60 IndParam.NumParam[0].Value = 13;
61 IndParam.NumParam[0].Min = 1;
62 IndParam.NumParam[0].Max = 200;
63 IndParam.NumParam[0].Enabled = true;
64 IndParam.NumParam[0].ToolTip = "The period of first BBP.";
65
66 IndParam.NumParam[1].Caption = "Second BBP period";
67 IndParam.NumParam[1].Value = 21;
68 IndParam.NumParam[1].Min = 1;
69 IndParam.NumParam[1].Max = 200;
70 IndParam.NumParam[1].Enabled = true;
71 IndParam.NumParam[1].ToolTip = "The period of second BBP.";
72
73 // The CheckBox parameters
74 IndParam.CheckParam[0].Caption = "Use previous bar value";
75 IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
76 IndParam.CheckParam[0].Enabled = true;
77 IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
78
79 return;
80 }
81
82 /// <summary>
83 /// Calculates the indicator's components
84 /// </summary>
85 public override void Calculate(SlotTypes slotType)
86 {
87 // Reading the parameters
88 MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
89 int iPeriod1 = (int)IndParam.NumParam[0].Value;
90 int iPeriod2 = (int)IndParam.NumParam[1].Value;
91 int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
92
93 // Calculation
94 int iFirstBar = iPeriod1 + iPeriod2 + 2;
95 double[] adIndicator1 = new double[Bars];
96 double[] adIndicator2 = new double[Bars];
97 double[] adOscllator = new double[Bars];
98
99 // ---------------------------------------------------------
100 Bulls_Bears_Power BBP1 = new Bulls_Bears_Power(slotType);
101 BBP1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
102 BBP1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value;
103 BBP1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
104 BBP1.Calculate(slotType);
105
106 Bulls_Bears_Power BBP2 = new Bulls_Bears_Power(slotType);
107 BBP2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
108 BBP2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value;
109 BBP2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
110 BBP2.Calculate(slotType);
111
112 adIndicator1 = BBP1.Component[0].Value;
113 adIndicator2 = BBP2.Component[0].Value;
114 // ----------------------------------------------------------
115
116 for (int iBar = iFirstBar; iBar < Bars; iBar++)
117 {
118 adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar];
119 }
120
121 // Saving the components
122 Component = new IndicatorComp[3];
123
124 Component[0] = new IndicatorComp();
125 Component[0].CompName = "Histogram";
126 Component[0].DataType = IndComponentType.IndicatorValue;
127 Component[0].ChartType = IndChartType.Histogram;
128 Component[0].FirstBar = iFirstBar;
129 Component[0].Value = adOscllator;
130
131 Component[1] = new IndicatorComp();
132 Component[1].ChartType = IndChartType.NoChart;
133 Component[1].FirstBar = iFirstBar;
134 Component[1].Value = new double[Bars];
135
136 Component[2] = new IndicatorComp();
137 Component[2].ChartType = IndChartType.NoChart;
138 Component[2].FirstBar = iFirstBar;
139 Component[2].Value = new double[Bars];
140
141 // Sets the Component's type
142 if (slotType == SlotTypes.OpenFilter)
143 {
144 Component[1].DataType = IndComponentType.AllowOpenLong;
145 Component[1].CompName = "Is long entry allowed";
146 Component[2].DataType = IndComponentType.AllowOpenShort;
147 Component[2].CompName = "Is short entry allowed";
148 }
149 else if (slotType == SlotTypes.CloseFilter)
150 {
151 Component[1].DataType = IndComponentType.ForceCloseLong;
152 Component[1].CompName = "Close out long position";
153 Component[2].DataType = IndComponentType.ForceCloseShort;
154 Component[2].CompName = "Close out short position";
155 }
156
157 // Calculation of the logic
158 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;
159
160 switch (IndParam.ListParam[0].Text)
161 {
162 case "The Oscillator rises":
163 indLogic = IndicatorLogic.The_indicator_rises;
164 break;
165
166 case "The Oscillator falls":
167 indLogic = IndicatorLogic.The_indicator_falls;
168 break;
169
170 case "The Oscillator is higher than the zero line":
171 indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
172 break;
173
174 case "The Oscillator is lower than the zero line":
175 indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
176 break;
177
178 case "The Oscillator crosses the zero line upward":
179 indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
180 break;
181
182 case "The Oscillator crosses the zero line downward":
183 indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
184 break;
185
186 case "The Oscillator changes its direction upward":
187 indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
188 break;
189
190 case "The Oscillator changes its direction downward":
191 indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
192 break;
193
194 default:
195 break;
196 }
197
198 OscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, 0, ref Component[1], ref Component[2], indLogic);
199
200 return;
201 }
202
203 /// <summary>
204 /// Sets the indicator logic description
205 /// </summary>
206 public override void SetDescription(SlotTypes slotType)
207 {
208 EntryFilterLongDescription = "the " + ToString() + " ";
209 EntryFilterShortDescription = "the " + ToString() + " ";
210 ExitFilterLongDescription = "the " + ToString() + " ";
211 ExitFilterShortDescription = "the " + ToString() + " ";
212
213 switch (IndParam.ListParam[0].Text)
214 {
215 case "The Oscillator rises":
216 EntryFilterLongDescription += "rises";
217 EntryFilterShortDescription += "falls";
218 ExitFilterLongDescription += "rises";
219 ExitFilterShortDescription += "falls";
220 break;
221
222 case "The Oscillator falls":
223 EntryFilterLongDescription += "falls";
224 EntryFilterShortDescription += "rises";
225 ExitFilterLongDescription += "falls";
226 ExitFilterShortDescription += "rises";
227 break;
228
229 case "The Oscillator is higher than the zero line":
230 EntryFilterLongDescription += "is higher than the zero line";
231 EntryFilterShortDescription += "is lower than the zero line";
232 ExitFilterLongDescription += "is higher than the zero line";
233 ExitFilterShortDescription += "is lower than the zero line";
234 break;
235
236 case "The Oscillator is lower than the zero line":
237 EntryFilterLongDescription += "is lower than the zero line";
238 EntryFilterShortDescription += "is higher than the zero line";
239 ExitFilterLongDescription += "is lower than the zero line";
240 ExitFilterShortDescription += "is higher than the zero line";
241 break;
242
243 case "The Oscillator crosses the zero line upward":
244 EntryFilterLongDescription += "crosses the zero line upward";
245 EntryFilterShortDescription += "crosses the zero line downward";
246 ExitFilterLongDescription += "crosses the zero line upward";
247 ExitFilterShortDescription += "crosses the zero line downward";
248 break;
249
250 case "The Oscillator crosses the zero line downward":
251 EntryFilterLongDescription += "crosses the zero line downward";
252 EntryFilterShortDescription += "crosses the zero line upward";
253 ExitFilterLongDescription += "crosses the zero line downward";
254 ExitFilterShortDescription += "crosses the zero line upward";
255 break;
256
257 case "The Oscillator changes its direction upward":
258 EntryFilterLongDescription += "changes its direction upward";
259 EntryFilterShortDescription += "changes its direction downward";
260 ExitFilterLongDescription += "changes its direction upward";
261 ExitFilterShortDescription += "changes its direction downward";
262 break;
263
264 case "The Oscillator changes its direction downward":
265 EntryFilterLongDescription += "changes its direction downward";
266 EntryFilterShortDescription += "changes its direction upward";
267 ExitFilterLongDescription += "changes its direction downward";
268 ExitFilterShortDescription += "changes its direction upward";
269 break;
270
271 default:
272 break;
273 }
274
275 return;
276 }
277
278 /// <summary>
279 /// Indicator to string
280 /// </summary>
281 public override string ToString()
282 {
283 string sString = IndicatorName +
284 (IndParam.CheckParam[0].Checked ? "* (" : " (") +
285 IndParam.ListParam[1].Text + ", " + // Method
286 IndParam.NumParam[0].ValueToString + ", " + // Period
287 IndParam.NumParam[1].ValueToString + ")"; // Period
288
289 return sString;
290 }
291 }
292 }
Top