I have been trying to write a class to make a custom SMA envelope indicator and store it in a rolling window, however Im having some difficulty calling the SMA method froum outside the main class, I suspect I may be going about this the wrong way. Any help would be appreciated.
class ENV(): #this is our custom sma envelope class
def __init__(self, symbol, period, deviation): #deviation is in percentage
self.upperRollingWindow = RollingWindow[float](20)
self.lowerRollingWindow = RollingWindow[float](20)
self.deviation = deviation/100
self.envSma = QCAlgorithm.SMA(symbol, period, Resolution.Hour)
def EnvUpperRollingWindow(self): #this function returns the rolling window
return self.upperRollingWindow
def EnvLowerRollingWindow(self):
return self.lowerRollingWindow
def UpdateEnvelope(self):
self.upperRollingWindow.Add(self.Upper())
self.lowerRollingWindow.Add(self.Lower())
def Upper(self):
#gives the upper envelope
upperEnv = self.envSma.Current.Value + (self.envSma.Current.Value*self.deviation)
return upperEnv
def Lower(self):
#lower envelope
lowerEnv = self.envSma.Current.Value - (self.envSma.Current.Value*self.deviation)
return lowerEnv
Derek Melchin
Hi Edmund,
Instead of using the shortcut SMA method, we can use the full class name (SimpleMovingAverage). See the attached backtest for an example. Since we register the envelope indicator for automatic updates, we simply update the internal SMA when new data is passed to the envelope indicator.
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.
Edmund jones
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!