diff --git a/Resources/securities/duck-typing.html b/Resources/securities/duck-typing.html index 7dd62d265c..8fc6bce3dd 100644 --- a/Resources/securities/duck-typing.html +++ b/Resources/securities/duck-typing.html @@ -13,7 +13,17 @@
// Get the SPY Equity object from Securities to get the EMA indicator.
-var ema = (Securities["SPY"] as dynamic).ema.Current.Value;
+var ema = (decimal)(Securities["SPY"] as dynamic).ema.Current.Value;
# Get the SPY Equity object from Securities to get the EMA indicator.
 ema = self.securities["SPY"].ema.current.value
+ +

To avoid casting to and from the dynamic type, you can use the Get<T> method to access the dynamic member and return the object with its type.

+ +
+
// Get the SPY Equity object from Securities to get the EMA indicator and its current value
+var ema = Securities["SPY"].Get<ExponentialMovingAverage>("ema");   // The type of ema is ExponentialMovingAverage
+var emaValue = ema.Current.Value;    // The type of emaValue is decimal
+
+ +

If the type or the member name is incorrect, the Get<T> method causes a runtime error.

\ No newline at end of file