forked from PopovMP/FSB_Pro_Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBarsFilter.cs
More file actions
198 lines (173 loc) · 7.26 KB
/
DataBarsFilter.cs
File metadata and controls
198 lines (173 loc) · 7.26 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//==============================================================
// 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 ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class DataBarsFilter : Indicator
{
public DataBarsFilter()
{
IndicatorName = "Data Bars Filter";
PossibleSlots = SlotTypes.OpenFilter;
IsDeafultGroupAll = true;
IsGeneratable = false;
WarningMessage =
"This indicator is designed to be used in the backtester only. It doesn't work in the trader.";
IndicatorAuthor = "Miroslav Popov";
IndicatorVersion = "2.0";
IndicatorDescription = "Bundled in FSB distribution.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
IndParam.IndicatorType = TypeOfIndicator.Additional;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new[]
{
"Do not use the newest bars",
"Do not use the oldest bars",
"Do not use the newest bars and oldest bars",
"Use the newest bars only",
"Use the oldest bars only"
};
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 = "Specify the entry bars.";
// The NumericUpDown parameters.
IndParam.NumParam[0].Caption = "Newest bars";
IndParam.NumParam[0].Value = 1000;
IndParam.NumParam[0].Min = 0;
IndParam.NumParam[0].Max = 50000;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The number of newest bars.";
IndParam.NumParam[1].Caption = "Oldest bars";
IndParam.NumParam[1].Value = 0;
IndParam.NumParam[1].Min = 0;
IndParam.NumParam[1].Max = 50000;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "The number of oldest bars.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
var newest = (int) IndParam.NumParam[0].Value;
var oldest = (int) IndParam.NumParam[1].Value;
// Calculation
int firstBar = 0;
var adBars = new double[Bars];
// Calculation of the logic
if (IsBacktester)
{
switch (IndParam.ListParam[0].Text)
{
case "Do not use the newest bars":
for (int bar = firstBar; bar < Bars - newest; bar++)
adBars[bar] = 1;
break;
case "Do not use the oldest bars":
firstBar = Math.Min(oldest, Bars - 300);
for (int bar = firstBar; bar < Bars; bar++)
adBars[bar] = 1;
break;
case "Do not use the newest bars and oldest bars":
firstBar = Math.Min(oldest, Bars - 300);
int lastBar = Math.Max(firstBar + 300, Bars - newest);
for (int bar = firstBar; bar < lastBar; bar++)
adBars[bar] = 1;
break;
case "Use the newest bars only":
firstBar = Math.Max(0, Bars - newest);
firstBar = Math.Min(firstBar, Bars - 300);
for (int bar = firstBar; bar < Bars; bar++)
adBars[bar] = 1;
break;
case "Use the oldest bars only":
oldest = Math.Max(300, oldest);
for (int bar = firstBar; bar < oldest; bar++)
adBars[bar] = 1;
break;
}
}
else
{
for (int bar = firstBar; bar < Bars; bar++)
adBars[bar] = 1;
}
// Saving the components
Component = new IndicatorComp[2];
Component[0] = new IndicatorComp
{
CompName = "(No) Used bars",
DataType = IndComponentType.AllowOpenLong,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = adBars
};
Component[1] = new IndicatorComp
{
CompName = "(No) Used bars",
DataType = IndComponentType.AllowOpenShort,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = adBars
};
}
public override void SetDescription()
{
if (!IsBacktester)
{
EntryFilterLongDescription = "A back tester limitation. It hasn't effect on the trade.";
EntryFilterShortDescription = "A back tester limitation. It hasn't effect on the trade.";
return;
}
var newest = (int) IndParam.NumParam[0].Value;
var oldest = (int) IndParam.NumParam[1].Value;
EntryFilterLongDescription = "(a back tester limitation) ";
EntryFilterShortDescription = "(a back tester limitation) ";
switch (IndParam.ListParam[0].Text)
{
case "Do not use the newest bars":
EntryFilterLongDescription += "Do not use the newest " + newest + " bars";
EntryFilterShortDescription += "Do not use the newest " + newest + " bars";
break;
case "Do not use the oldest bars":
EntryFilterLongDescription += "Do not use the oldest " + oldest + " bars";
EntryFilterShortDescription += "Do not use the oldest " + oldest + " bars";
break;
case "Do not use the newest bars and oldest bars":
EntryFilterLongDescription += "Do not use the newest " + newest + " bars and oldest " + oldest +
" bars";
EntryFilterShortDescription += "Do not use the newest " + newest + " bars and oldest " + oldest +
" bars";
break;
case "Use the newest bars only":
EntryFilterLongDescription += "Use the newest " + newest + " bars only";
EntryFilterShortDescription += "Use the newest " + newest + " bars only";
break;
case "Use the oldest bars only":
EntryFilterLongDescription += "Use the oldest " + newest + " bars only";
EntryFilterShortDescription += "Use the oldest " + newest + " bars only";
break;
}
}
public override string ToString()
{
return IndicatorName;
}
}
}