Back

How to use IndicatorExtensions.Over with 2 indicators?

I run code in research jupyter notebook:

minutes=len(df_price)
ema = qb.Indicator(ExponentialMovingAverage(750), syl, minutes, Resolution.Minute)
close = qb.Indicator(SimpleMovingAverage(1), syl, minutes, Resolution.Minute)
close = close.drop('simplemovingaverage', axis = 1)
close_over_ema = IndicatorExtensions.Over(close, ema)

the output is :

InvalidCastException: cannot convert object to target type
  at Python.Runtime.PyObject.AsManagedObject (System.Type t) [0x00011] in <5699e871b2d343059e1ba5b428b465a0>:0 
  at QuantConnect.Indicators.IndicatorExtensions.Over (Python.Runtime.PyObject left, Python.Runtime.PyObject right, System.String name) [0x00008] in <03b550573bc44002ba53a1f597f9e9c4>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0 

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Li,

The reason is, the Indicator created by qb.Indicator() is actually a panda dataframe, not a QC Indicator class type. If you try to print type(ema) for example, you would see `pandas.core.frame.DataFrame
`. Therefore, IndicatorExtensions.Over cannot take those dataframes as arguments. It only works in backtesting algorithms.

Meanwhile, I would suggest to manually divide two value. Here is information for accessing value in panda dataframe. Hope it helps!

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed