18 using System.Globalization;
51 public static T
Of<T>(
this T second,
IIndicator first,
bool waitForFirstToReady =
true)
54 first.
Updated += (sender, consolidated) =>
57 if (!waitForFirstToReady || first.
IsReady)
59 second.Update(consolidated);
79 var numerator =
new Sum(
"Sum_xy", period);
80 var denominator =
new Sum(
"Sum_y", period);
82 value.Updated += (sender, consolidated) =>
84 x.Update(consolidated);
85 if (x.Samples == y.Samples)
87 numerator.Update(consolidated.Time, consolidated.Value * y.Current.Value);
91 weight.Updated += (sender, consolidated) =>
93 y.Update(consolidated);
94 if (x.Samples == y.Samples)
96 numerator.Update(consolidated.Time, consolidated.Value * x.Current.Value);
98 denominator.Update(consolidated);
101 var resetCompositeIndicator =
new ResetCompositeIndicator(numerator, denominator, GetOverIndicatorComposer(), () => {
106 return resetCompositeIndicator;
121 return left.Plus(constantIndicator);
135 return new (left, right, (l, r) => l.Current.Value + r.Current.Value);
150 return new (name, left, right, (l, r) => l.Current.Value + r.Current.Value);
165 return left.Minus(constantIndicator);
179 return new (left, right, (l, r) => l.Current.Value - r.Current.Value);
194 return new (name, left, right, (l, r) => l.Current.Value - r.Current.Value);
209 return left.Over(constantIndicator);
223 return new (left, right, GetOverIndicatorComposer());
238 return new (name, left, right, GetOverIndicatorComposer());
253 return left.Times(constantIndicator);
267 return new (left, right, (l, r) => l.Current.Value * r.Current.Value);
282 return new (name, left, right, (l, r) => l.Current.Value * r.Current.Value);
307 return new Maximum($
"MAX{period}_Of_{left.Name}", period).Of(left, waitForFirstToReady);
319 return new Minimum($
"MIN{period}_Of_{left.Name}", period).Of(left, waitForFirstToReady);
331 return new SimpleMovingAverage($
"SMA{period}_Of_{left.Name}", period).Of(left, waitForFirstToReady);
346 public static object Of(PyObject second, PyObject first,
bool waitForFirstToReady =
true)
348 dynamic indicator1 = GetIndicatorAsManagedObject(first);
349 dynamic indicator2 = GetIndicatorAsManagedObject(second);
350 return Of(indicator2, indicator1, waitForFirstToReady);
363 dynamic indicator1 = GetIndicatorAsManagedObject(value);
364 dynamic indicator2 = GetIndicatorAsManagedObject(weight);
365 return WeightedBy(indicator1, indicator2, period);
378 dynamic indicator = GetIndicatorAsManagedObject(left);
379 return EMA(indicator, period, smoothingFactor, waitForFirstToReady);
389 public static Maximum MAX(PyObject left,
int period,
bool waitForFirstToReady =
true)
391 dynamic indicator = GetIndicatorAsManagedObject(left);
392 return MAX(indicator, period, waitForFirstToReady);
402 public static Minimum MIN(PyObject left,
int period,
bool waitForFirstToReady =
true)
404 dynamic indicator = GetIndicatorAsManagedObject(left);
405 return MIN(indicator, period, waitForFirstToReady);
417 dynamic indicator = GetIndicatorAsManagedObject(left);
418 return SMA(indicator, period, waitForFirstToReady);
430 public static object Over(PyObject left, decimal constant)
432 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
433 return Over(indicatorLeft, constant);
446 public static object Over(PyObject left, PyObject right,
string name =
"")
448 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
449 dynamic indicatorRight = GetIndicatorAsManagedObject(right);
450 if (name.IsNullOrEmpty())
452 return Over(indicatorLeft, indicatorRight);
454 return Over(indicatorLeft, indicatorRight, name);
466 public static object Minus(PyObject left, decimal constant)
468 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
469 return Minus(indicatorLeft, constant);
482 public static object Minus(PyObject left, PyObject right,
string name =
"")
484 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
485 dynamic indicatorRight = GetIndicatorAsManagedObject(right);
486 if (name.IsNullOrEmpty())
488 return Minus(indicatorLeft, indicatorRight);
490 return Minus(indicatorLeft, indicatorRight, name);
502 public static object Times(PyObject left, decimal constant)
504 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
505 return Times(indicatorLeft, constant);
518 public static object Times(PyObject left, PyObject right,
string name =
"")
520 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
521 dynamic indicatorRight = GetIndicatorAsManagedObject(right);
522 if (name.IsNullOrEmpty())
524 return Times(indicatorLeft, indicatorRight);
526 return Times(indicatorLeft, indicatorRight, name);
538 public static object Plus(PyObject left, decimal constant)
540 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
541 return Plus(indicatorLeft, constant);
554 public static object Plus(PyObject left, PyObject right,
string name =
"")
556 dynamic indicatorLeft = GetIndicatorAsManagedObject(left);
557 dynamic indicatorRight = GetIndicatorAsManagedObject(right);
558 if (name.IsNullOrEmpty())
560 return Plus(indicatorLeft, indicatorRight);
562 return Plus(indicatorLeft, indicatorRight, name);
565 private static dynamic GetIndicatorAsManagedObject(PyObject indicator)
569 pythonIndicator.SetIndicator(indicator);
570 return pythonIndicator;
573 return indicator.SafeAsManagedObject();
580 private static CompositeIndicator.IndicatorComposer GetOverIndicatorComposer()
582 return (l, r) => r.Current.Value == 0m ?
new IndicatorResult(0m,
IndicatorStatus.MathError) : new IndicatorResult(l.Current.Value / r.Current.Value);