I attempted to write my first custom Indicator. It calculates the average Momentum for a given time-frame. Or, it would if the darn thing worked. Instead, it crashes Lean before it ever initializes.
In the attached Backtest, uncomment the line following, "UNCOMMENT THIS LINE AND IT WILL BREAK." in Main.cs. I would have submitted it as such, but I couldn't even get the Backtest to get past Queuing with the line in there.
Jared Broad
Nice clean code Denny --
The bug is this:
SPY.Consolidator outputs type TradeBar but indicator expects input type IndicatorDataPoint 2016-12-13T22:20:37.3746230Z ERROR:: at QuantConnect.Algorithm.QCAlgorithm.RegisterIndicator[T] (QuantConnect.Symbol symbol, QuantConnect.Indicators.IndicatorBase`1[T] indicator, QuantConnect.Data.Consolidators.IDataConsolidator consolidator, System.Func`2[T,TResult] selector) [0x0007b] in <c292482be6584a0c8d8386916b92dc22>:0 2016-12-13T22:20:37.3750900Z ERROR:: at QuantConnect.Algorithm.QCAlgorithm.RegisterIndicator[T] (QuantConnect.Symbol symbol, QuantConnect.Indicators.IndicatorBase`1[T] indicator, System.Nullable`1[T] resolution) [0x0000c] in <c292482be6584a0c8d8386916b92dc22>:0 2016-12-13T22:20:37.3757140Z ERROR:: at QuantConnect.BasicTemplateAlgorithm.AVGMOM (System.String symbol, System.Int32 momentumPeriod, System.Int32 averagePeriod, System.Nullable`1[T] resolution) [0x00036] in <169087126c7d4f6cb5ee1c5f97299808>:0 2016-12-13T22:20:37.3761210Z ERROR:: at QuantConnect.BasicTemplateAlgorithm.Initialize () [0x00074] in <169087126c7d4f6cb5ee1c5f97299808>:0
The problem is the cloud isn't reporting it properly. For now you can move the creation of the indicator into the OnData with an "If Not Created Yet -> Create" check then the error will be reported nicely. We'll submit a patch for the failure to report the bug today-tomorrow.
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.
Denny Caldwell (Grinn)
Thanks Jared. For those interested the fix was to add the selector when calling RegisterIndicator:
public AverageMomentum AVGMOM(string symbol, int momentumPeriod, int averagePeriod, Resolution? resolution = null, Func<IBaseData, decimal> selector = null) { var name = CreateIndicatorName(symbol, string.Format("AVGMOM{0}_{1}", momentumPeriod, averagePeriod), resolution); var avgMom = new AverageMomentum(name, momentumPeriod, averagePeriod); RegisterIndicator(symbol, avgMom, resolution, selector); return avgMom; }
Denny Caldwell (Grinn)
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!