Lean  $LEAN_TAG$
IndicatorBase.Operators.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
17 {
18  public abstract partial class IndicatorBase
19  {
20  /// <summary>
21  /// Returns the current value of this instance
22  /// </summary>
23  /// <param name="instance">The indicator instance</param>
24  /// <returns>The current value of the indicator</returns>
25  public static implicit operator decimal(IndicatorBase instance)
26  {
27  return instance.Current.Value;
28  }
29 
30  /// <summary>
31  /// Determines if the indicator's current value is greater than the specified value
32  /// </summary>
33  public static bool operator >(IndicatorBase left, double right)
34  {
35  if (ReferenceEquals(left, null)) return false;
36  return left.Current.Value > (decimal)right;
37  }
38 
39  /// <summary>
40  /// Determines if the indicator's current value is less than the specified value
41  /// </summary>
42  public static bool operator <(IndicatorBase left, double right)
43  {
44  if (ReferenceEquals(left, null)) return false;
45  return left.Current.Value < (decimal)right;
46  }
47 
48  /// <summary>
49  /// Determines if the specified value is greater than the indicator's current value
50  /// </summary>
51  public static bool operator >(double left, IndicatorBase right)
52  {
53  if (ReferenceEquals(right, null)) return false;
54  return (decimal)left > right.Current.Value;
55  }
56 
57  /// <summary>
58  /// Determines if the specified value is less than the indicator's current value
59  /// </summary>
60  public static bool operator <(double left, IndicatorBase right)
61  {
62  if (ReferenceEquals(right, null)) return false;
63  return (decimal)left < right.Current.Value;
64  }
65 
66  /// <summary>
67  /// Determines if the indicator's current value is greater than or equal to the specified value
68  /// </summary>
69  public static bool operator >=(IndicatorBase left, double right)
70  {
71  if (ReferenceEquals(left, null)) return false;
72  return left.Current.Value >= (decimal)right;
73  }
74 
75  /// <summary>
76  /// Determines if the indicator's current value is less than or equal to the specified value
77  /// </summary>
78  public static bool operator <=(IndicatorBase left, double right)
79  {
80  if (ReferenceEquals(left, null)) return false;
81  return left.Current.Value <= (decimal)right;
82  }
83 
84  /// <summary>
85  /// Determines if the specified value is greater than or equal to the indicator's current value
86  /// </summary>
87  public static bool operator >=(double left, IndicatorBase right)
88  {
89  if (ReferenceEquals(right, null)) return false;
90  return (decimal)left >= right.Current.Value;
91  }
92 
93  /// <summary>
94  /// Determines if the specified value is less than or equal to the indicator's current value
95  /// </summary>
96  public static bool operator <=(double left, IndicatorBase right)
97  {
98  if (ReferenceEquals(right, null)) return false;
99  return (decimal)left <= right.Current.Value;
100  }
101 
102  /// <summary>
103  /// Determines if the indicator's current value is equal to the specified value
104  /// </summary>
105  public static bool operator ==(IndicatorBase left, double right)
106  {
107  if (ReferenceEquals(left, null)) return false;
108  return left.Current.Value == (decimal)right;
109  }
110 
111  /// <summary>
112  /// Determines if the indicator's current value is not equal to the specified value
113  /// </summary>
114  public static bool operator !=(IndicatorBase left, double right)
115  {
116  if (ReferenceEquals(left, null)) return true;
117  return left.Current.Value != (decimal)right;
118  }
119 
120  /// <summary>
121  /// Determines if the specified value is equal to the indicator's current value
122  /// </summary>
123  public static bool operator ==(double left, IndicatorBase right)
124  {
125  if (ReferenceEquals(right, null)) return false;
126  return (decimal)left == right.Current.Value;
127  }
128 
129  /// <summary>
130  /// Determines if the specified value is not equal to the indicator's current value
131  /// </summary>
132  public static bool operator !=(double left, IndicatorBase right)
133  {
134  if (ReferenceEquals(right, null)) return true;
135  return (decimal)left != right.Current.Value;
136  }
137 
138  /// <summary>
139  /// Determines if the indicator's current value is greater than the specified value
140  /// </summary>
141  public static bool operator >(IndicatorBase left, float right)
142  {
143  if (ReferenceEquals(left, null)) return false;
144  return left.Current.Value > (decimal)right;
145  }
146 
147  /// <summary>
148  /// Determines if the indicator's current value is less than the specified value
149  /// </summary>
150  public static bool operator <(IndicatorBase left, float right)
151  {
152  if (ReferenceEquals(left, null)) return false;
153  return left.Current.Value < (decimal)right;
154  }
155 
156  /// <summary>
157  /// Determines if the specified value is greater than the indicator's current value
158  /// </summary>
159  public static bool operator >(float left, IndicatorBase right)
160  {
161  if (ReferenceEquals(right, null)) return false;
162  return (decimal)left > right.Current.Value;
163  }
164 
165  /// <summary>
166  /// Determines if the specified value is less than the indicator's current value
167  /// </summary>
168  public static bool operator <(float left, IndicatorBase right)
169  {
170  if (ReferenceEquals(right, null)) return false;
171  return (decimal)left < right.Current.Value;
172  }
173 
174  /// <summary>
175  /// Determines if the indicator's current value is greater than or equal to the specified value
176  /// </summary>
177  public static bool operator >=(IndicatorBase left, float right)
178  {
179  if (ReferenceEquals(left, null)) return false;
180  return left.Current.Value >= (decimal)right;
181  }
182 
183  /// <summary>
184  /// Determines if the indicator's current value is less than or equal to the specified value
185  /// </summary>
186  public static bool operator <=(IndicatorBase left, float right)
187  {
188  if (ReferenceEquals(left, null)) return false;
189  return left.Current.Value <= (decimal)right;
190  }
191 
192  /// <summary>
193  /// Determines if the specified value is greater than or equal to the indicator's current value
194  /// </summary>
195  public static bool operator >=(float left, IndicatorBase right)
196  {
197  if (ReferenceEquals(right, null)) return false;
198  return (decimal)left >= right.Current.Value;
199  }
200 
201  /// <summary>
202  /// Determines if the specified value is less than or equal to the indicator's current value
203  /// </summary>
204  public static bool operator <=(float left, IndicatorBase right)
205  {
206  if (ReferenceEquals(right, null)) return false;
207  return (decimal)left <= right.Current.Value;
208  }
209 
210  /// <summary>
211  /// Determines if the indicator's current value is equal to the specified value
212  /// </summary>
213  public static bool operator ==(IndicatorBase left, float right)
214  {
215  if (ReferenceEquals(left, null)) return false;
216  return left.Current.Value == (decimal)right;
217  }
218 
219  /// <summary>
220  /// Determines if the indicator's current value is not equal to the specified value
221  /// </summary>
222  public static bool operator !=(IndicatorBase left, float right)
223  {
224  if (ReferenceEquals(left, null)) return true;
225  return left.Current.Value != (decimal)right;
226  }
227 
228  /// <summary>
229  /// Determines if the specified value is equal to the indicator's current value
230  /// </summary>
231  public static bool operator ==(float left, IndicatorBase right)
232  {
233  if (ReferenceEquals(right, null)) return false;
234  return (decimal)left == right.Current.Value;
235  }
236 
237  /// <summary>
238  /// Determines if the specified value is not equal to the indicator's current value
239  /// </summary>
240  public static bool operator !=(float left, IndicatorBase right)
241  {
242  if (ReferenceEquals(right, null)) return true;
243  return (decimal)left != right.Current.Value;
244  }
245  /// <summary>
246  /// Determines if the indicator's current value is greater than the specified value
247  /// </summary>
248  public static bool operator >(IndicatorBase left, int right)
249  {
250  if (ReferenceEquals(left, null)) return false;
251  return left.Current.Value > right;
252  }
253 
254  /// <summary>
255  /// Determines if the indicator's current value is less than the specified value
256  /// </summary>
257  public static bool operator <(IndicatorBase left, int right)
258  {
259  if (ReferenceEquals(left, null)) return false;
260  return left.Current.Value < right;
261  }
262 
263  /// <summary>
264  /// Determines if the specified value is greater than the indicator's current value
265  /// </summary>
266  public static bool operator >(int left, IndicatorBase right)
267  {
268  if (ReferenceEquals(right, null)) return false;
269  return left > right.Current.Value;
270  }
271 
272  /// <summary>
273  /// Determines if the specified value is less than the indicator's current value
274  /// </summary>
275  public static bool operator <(int left, IndicatorBase right)
276  {
277  if (ReferenceEquals(right, null)) return false;
278  return left < right.Current.Value;
279  }
280 
281  /// <summary>
282  /// Determines if the indicator's current value is greater than or equal to the specified value
283  /// </summary>
284  public static bool operator >=(IndicatorBase left, int right)
285  {
286  if (ReferenceEquals(left, null)) return false;
287  return left.Current.Value >= right;
288  }
289 
290  /// <summary>
291  /// Determines if the indicator's current value is less than or equal to the specified value
292  /// </summary>
293  public static bool operator <=(IndicatorBase left, int right)
294  {
295  if (ReferenceEquals(left, null)) return false;
296  return left.Current.Value <= right;
297  }
298 
299  /// <summary>
300  /// Determines if the specified value is greater than or equal to the indicator's current value
301  /// </summary>
302  public static bool operator >=(int left, IndicatorBase right)
303  {
304  if (ReferenceEquals(right, null)) return false;
305  return left >= right.Current.Value;
306  }
307 
308  /// <summary>
309  /// Determines if the specified value is less than or equal to the indicator's current value
310  /// </summary>
311  public static bool operator <=(int left, IndicatorBase right)
312  {
313  if (ReferenceEquals(right, null)) return false;
314  return left <= right.Current.Value;
315  }
316 
317  /// <summary>
318  /// Determines if the indicator's current value is equal to the specified value
319  /// </summary>
320  public static bool operator ==(IndicatorBase left, int right)
321  {
322  if (ReferenceEquals(left, null)) return false;
323  return left.Current.Value == right;
324  }
325 
326  /// <summary>
327  /// Determines if the indicator's current value is not equal to the specified value
328  /// </summary>
329  public static bool operator !=(IndicatorBase left, int right)
330  {
331  if (ReferenceEquals(left, null)) return true;
332  return left.Current.Value != right;
333  }
334 
335  /// <summary>
336  /// Determines if the specified value is equal to the indicator's current value
337  /// </summary>
338  public static bool operator ==(int left, IndicatorBase right)
339  {
340  if (ReferenceEquals(right, null)) return false;
341  return left == right.Current.Value;
342  }
343 
344  /// <summary>
345  /// Determines if the specified value is not equal to the indicator's current value
346  /// </summary>
347  public static bool operator !=(int left, IndicatorBase right)
348  {
349  if (ReferenceEquals(right, null)) return true;
350  return left != right.Current.Value;
351  }
352  /// <summary>
353  /// Determines if the indicator's current value is greater than the specified value
354  /// </summary>
355  public static bool operator >(IndicatorBase left, long right)
356  {
357  if (ReferenceEquals(left, null)) return false;
358  return left.Current.Value > right;
359  }
360 
361  /// <summary>
362  /// Determines if the indicator's current value is less than the specified value
363  /// </summary>
364  public static bool operator <(IndicatorBase left, long right)
365  {
366  if (ReferenceEquals(left, null)) return false;
367  return left.Current.Value < right;
368  }
369 
370  /// <summary>
371  /// Determines if the specified value is greater than the indicator's current value
372  /// </summary>
373  public static bool operator >(long left, IndicatorBase right)
374  {
375  if (ReferenceEquals(right, null)) return false;
376  return left > right.Current.Value;
377  }
378 
379  /// <summary>
380  /// Determines if the specified value is less than the indicator's current value
381  /// </summary>
382  public static bool operator <(long left, IndicatorBase right)
383  {
384  if (ReferenceEquals(right, null)) return false;
385  return left < right.Current.Value;
386  }
387 
388  /// <summary>
389  /// Determines if the indicator's current value is greater than or equal to the specified value
390  /// </summary>
391  public static bool operator >=(IndicatorBase left, long right)
392  {
393  if (ReferenceEquals(left, null)) return false;
394  return left.Current.Value >= right;
395  }
396 
397  /// <summary>
398  /// Determines if the indicator's current value is less than or equal to the specified value
399  /// </summary>
400  public static bool operator <=(IndicatorBase left, long right)
401  {
402  if (ReferenceEquals(left, null)) return false;
403  return left.Current.Value <= right;
404  }
405 
406  /// <summary>
407  /// Determines if the specified value is greater than or equal to the indicator's current value
408  /// </summary>
409  public static bool operator >=(long left, IndicatorBase right)
410  {
411  if (ReferenceEquals(right, null)) return false;
412  return left >= right.Current.Value;
413  }
414 
415  /// <summary>
416  /// Determines if the specified value is less than or equal to the indicator's current value
417  /// </summary>
418  public static bool operator <=(long left, IndicatorBase right)
419  {
420  if (ReferenceEquals(right, null)) return false;
421  return left <= right.Current.Value;
422  }
423 
424  /// <summary>
425  /// Determines if the indicator's current value is equal to the specified value
426  /// </summary>
427  public static bool operator ==(IndicatorBase left, long right)
428  {
429  if (ReferenceEquals(left, null)) return false;
430  return left.Current.Value == right;
431  }
432 
433  /// <summary>
434  /// Determines if the indicator's current value is not equal to the specified value
435  /// </summary>
436  public static bool operator !=(IndicatorBase left, long right)
437  {
438  if (ReferenceEquals(left, null)) return true;
439  return left.Current.Value != right;
440  }
441 
442  /// <summary>
443  /// Determines if the specified value is equal to the indicator's current value
444  /// </summary>
445  public static bool operator ==(long left, IndicatorBase right)
446  {
447  if (ReferenceEquals(right, null)) return false;
448  return left == right.Current.Value;
449  }
450 
451  /// <summary>
452  /// Determines if the specified value is not equal to the indicator's current value
453  /// </summary>
454  public static bool operator !=(long left, IndicatorBase right)
455  {
456  if (ReferenceEquals(right, null)) return true;
457  return left != right.Current.Value;
458  }
459  }
460 }