I get below errors while running backtesting, please can you confirm if source code is correct
class RollingMax(IndicatorBase[IndicatorDataPoint]):
def __init__(self, name: str, period: int):
super().__init__(name)
self._period = period
self._window = RollingWindow[float](period)
@property
def IsReady(self) -> bool:
return self._window.IsReady
def ComputeNextValue(self, input: IndicatorDataPoint) -> float:
if self._window.Count == self._period:
self._window.RemoveAt(self._period - 1)
self._window.Add(input.Value)
return float(max(self._window)) if self._window.Count > 0 else float('nan')Errors
Runtime Error: cannot instantiate abstract class
at __init__
self.max_close = RollingMax(f"{symbol.Value}_MAXC{cfg.n_breakout}", cfg.n_breakout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in state.py: line 12
at OnSecuritiesChanged
st = SymbolState(self, sym, self.cfg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 62
Mia Alissi
Here is the corrected RollingMax indicator for QuantConnect Python. This version implements all abstract methods required by IndicatorBase, uses snake_case naming, and updates the RollingWindow with the correct logic for maximum calculation:
You can now instantiate and use this RollingMax in your algorithm without getting the abstract class error!
Sources: Maximum - QuantConnect.com, Rolling Window - QuantConnect.com, Rolling Window - QuantConnect.com, Rolling Window Algorithm, Custom Indicator Algorithm
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.
Dharmesh Khalasi
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!