Hi,
I wish to use the IndicatorExtensions.Minus() composite indicator function in the Update function of a custom indicator (Py) but received this error:
Runtime Error: RuntimeBinderException : The best overloaded method match for 'QuantConnect.Indicators.IndicatorExtensions.Minus(Python.Runtime.PyObject, decimal)' has some invalid arguments
at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,System.Type,object,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet] (System.Runtime.CompilerServices.CallSite site, T0 arg0, T1 arg1, T2 arg2) [0x0011a] in <92922d9bda2f4e1cba9242d052be6d43>:0
at QuantConnect.Indicators.IndicatorExtensions.Minus (Python.Runtime.PyObject left, Python.Runtime.PyObject right, System.String name) [0x00096] in <31d71f9023394fa885170f3eadc85c43>: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
at Update in main.py:line 286
The indicator Update function contains the statement:
self.chngCloseInd.Update(IndicatorExtensions.Minus(self.inputRWin[0], self.inputRWin[1]))
Where self.inputRWin is defined in the init function of the custom indicator class as:
self.inputRWin = RollingWindow[TradeBar](period)
My expectation from the lean engine code:
namespace QuantConnect.Indicators
public static class IndicatorExtensions
Is that the binder would select the highlighted Minus overload, or py equivalent:
CompositeIndicator<T> Minus<T>(this IndicatorBase<T> left, IndicatorBase<T> right) where T : IBaseData
object Minus(PyObject left, decimal constant)
object Minus(PyObject left, PyObject right, string name = "")
However the implementation selected the first py overload above.
I attempted to force a different overload by:
self.chngCloseInd.Update(IndicatorExtensions.Minus(self.inputRWin[0], self.inputRWin[1], ""))
And to simplify the argument terms, as here:
# vmapChng = IndicatorExtensions.Minus(self.inputRWin[0], self.inputRWin[1])
# vmapChng = IndicatorExtensions.Minus(self.inputRWin[0], self.inputRWin[1], "")
t0 = self.inputRWin[0]
t1 = self.inputRWin[1]
vmapChng = IndicatorExtensions.Minus(t0, t1)
However the same runtime error, as above, was generated.
The inheritance hierarchies, leaf to root, are rooted at IBaseData.
IndicatorBase is:
IndicatorBase<T> : IIndicator<T> where T : IBaseData
TradeBar is:
TradeBar : BaseData, IBaseDataBar
BaseData : IBaseData
And this code passes the Runtime Binder:
self.closeInd.Update(tradebar)
I have a workaround that does not use IndicatorExtensions.Minus() but would appreciate suggestions that enable the ‘Minus’ function to be used.
Thanks for your time, Chris.
Derek Melchin
Hi Chris,
The first two objects we pass the `IndicatorsExtensions.Minus` method must be of type IndicatorBase or Decimal. In the code above, 2 TradeBar objects are passed as arguments. This is why the error message displays "... some invalid arguments". A quick review of our documentation on indicator extensions may be helpful.
Best,
Derek Melchin
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.
ChrisFg
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!