1919using QuantConnect . Data ;
2020using Python . Runtime ;
2121using QuantConnect . Util ;
22+ using QuantConnect . Data . Market ;
2223
2324namespace QuantConnect . Indicators
2425{
@@ -98,7 +99,8 @@ public static CompositeIndicator WeightedBy<T, TWeight>(this IndicatorBase<T> va
9899 denominator . Update ( consolidated ) ;
99100 } ;
100101
101- var resetCompositeIndicator = new ResetCompositeIndicator ( numerator , denominator , GetOverIndicatorComposer ( ) , ( ) => {
102+ var resetCompositeIndicator = new ResetCompositeIndicator ( numerator , denominator , GetOverIndicatorComposer ( ) , ( ) =>
103+ {
102104 x . Reset ( ) ;
103105 y . Reset ( ) ;
104106 } ) ;
@@ -132,7 +134,7 @@ public static CompositeIndicator Plus(this IndicatorBase left, decimal constant)
132134 /// <returns>The sum of the left and right indicators</returns>
133135 public static CompositeIndicator Plus ( this IndicatorBase left , IndicatorBase right )
134136 {
135- return new ( left , right , ( l , r ) => l . Current . Value + r . Current . Value ) ;
137+ return new ( left , right , ( l , r ) => l . Current . Value + r . Current . Value ) ;
136138 }
137139
138140 /// <summary>
@@ -147,7 +149,7 @@ public static CompositeIndicator Plus(this IndicatorBase left, IndicatorBase rig
147149 /// <returns>The sum of the left and right indicators</returns>
148150 public static CompositeIndicator Plus ( this IndicatorBase left , IndicatorBase right , string name )
149151 {
150- return new ( name , left , right , ( l , r ) => l . Current . Value + r . Current . Value ) ;
152+ return new ( name , left , right , ( l , r ) => l . Current . Value + r . Current . Value ) ;
151153 }
152154
153155 /// <summary>
@@ -176,7 +178,7 @@ public static CompositeIndicator Minus(this IndicatorBase left, decimal constant
176178 /// <returns>The difference of the left and right indicators</returns>
177179 public static CompositeIndicator Minus ( this IndicatorBase left , IndicatorBase right )
178180 {
179- return new ( left , right , ( l , r ) => l . Current . Value - r . Current . Value ) ;
181+ return new ( left , right , ( l , r ) => l . Current . Value - r . Current . Value ) ;
180182 }
181183
182184 /// <summary>
@@ -191,7 +193,7 @@ public static CompositeIndicator Minus(this IndicatorBase left, IndicatorBase ri
191193 /// <returns>The difference of the left and right indicators</returns>
192194 public static CompositeIndicator Minus ( this IndicatorBase left , IndicatorBase right , string name )
193195 {
194- return new ( name , left , right , ( l , r ) => l . Current . Value - r . Current . Value ) ;
196+ return new ( name , left , right , ( l , r ) => l . Current . Value - r . Current . Value ) ;
195197 }
196198
197199 /// <summary>
@@ -220,7 +222,7 @@ public static CompositeIndicator Over(this IndicatorBase left, decimal constant)
220222 /// <returns>The ratio of the left to the right indicator</returns>
221223 public static CompositeIndicator Over ( this IndicatorBase left , IndicatorBase right )
222224 {
223- return new ( left , right , GetOverIndicatorComposer ( ) ) ;
225+ return new ( left , right , GetOverIndicatorComposer ( ) ) ;
224226 }
225227
226228 /// <summary>
@@ -235,7 +237,7 @@ public static CompositeIndicator Over(this IndicatorBase left, IndicatorBase rig
235237 /// <returns>The ratio of the left to the right indicator</returns>
236238 public static CompositeIndicator Over ( this IndicatorBase left , IndicatorBase right , string name )
237239 {
238- return new ( name , left , right , GetOverIndicatorComposer ( ) ) ;
240+ return new ( name , left , right , GetOverIndicatorComposer ( ) ) ;
239241 }
240242
241243 /// <summary>
@@ -264,7 +266,7 @@ public static CompositeIndicator Times(this IndicatorBase left, decimal constant
264266 /// <returns>The product of the left to the right indicators</returns>
265267 public static CompositeIndicator Times ( this IndicatorBase left , IndicatorBase right )
266268 {
267- return new ( left , right , ( l , r ) => l . Current . Value * r . Current . Value ) ;
269+ return new ( left , right , ( l , r ) => l . Current . Value * r . Current . Value ) ;
268270 }
269271
270272 /// <summary>
@@ -279,7 +281,23 @@ public static CompositeIndicator Times(this IndicatorBase left, IndicatorBase ri
279281 /// <returns>The product of the left to the right indicators</returns>
280282 public static CompositeIndicator Times ( this IndicatorBase left , IndicatorBase right , string name )
281283 {
282- return new ( name , left , right , ( l , r ) => l . Current . Value * r . Current . Value ) ;
284+ return new ( name , left , right , ( l , r ) => l . Current . Value * r . Current . Value ) ;
285+ }
286+
287+ /// <summary>
288+ /// Attempts to convert a <see cref="PyObject"/> into an <see cref="IndicatorBase"/>.
289+ /// </summary>
290+ /// <param name="pyObject">The Python object to convert.</param>
291+ /// <param name="indicator">The resulting indicator if successful; otherwise, null.</param>
292+ /// <returns><c>true</c> if the conversion succeeds; otherwise, <c>false</c>.</returns>
293+ public static bool TryConvertIndicator ( this PyObject pyObject , out IndicatorBase indicator )
294+ {
295+ indicator = null ;
296+
297+ return pyObject . TryConvert ( out IndicatorBase < IBaseData > ibd ) && ( indicator = ibd ) != null ||
298+ pyObject . TryConvert ( out IndicatorBase < IndicatorDataPoint > idp ) && ( indicator = idp ) != null ||
299+ pyObject . TryConvert ( out IndicatorBase < IBaseDataBar > idb ) && ( indicator = idb ) != null ||
300+ pyObject . TryConvert ( out IndicatorBase < TradeBar > itb ) && ( indicator = itb ) != null ;
283301 }
284302
285303 /// <summary>Creates a new ExponentialMovingAverage indicator with the specified period and smoothingFactor from the left indicator
@@ -418,7 +436,7 @@ public static SimpleMovingAverage SMA(PyObject left, int period, bool waitForFir
418436 return SMA ( indicator , period , waitForFirstToReady ) ;
419437 }
420438
421- /// <summary>
439+ /// <summary>
422440 /// Creates a new CompositeIndicator such that the result will be the ratio of the left to the constant
423441 /// </summary>
424442 /// <remarks>
0 commit comments