import numpy as np
class LongRSI_test(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 3, 31)
self.SetCash(100000)
res = Resolution.Minute
self.msft = self.AddEquity("MSFT", res).Symbol
self.SetWarmUp(10, res)
self.msft_rsi = RelativeStrengthIndex(self.msft, 6)
def OnData(self, data):
if self.IsWarmingUp: return
self.msft_rsi.Update(self.Time, self.Securities[self.msft].Close)
self.Log(f"MSFTrsi: {self.msft_rsi}")
if self.msft_rsi >= 80:
self.Log(f"rsiabove80")***Another (probably simple issue) has me scratching my head. I get the following error when checking the rsi by running the code above:Runtime Error: TypeError : Cannot get managed object
***Without the if self.msft_rsi>=80 statement, log shows numbers... Is the result a string instead of an actual number? I'm an old c++ programmer, so I'm still trying to learning Python. Thank you in advance.
at OnData
if self.msft_rsi >= 80:
===
at Python.Runtime.PyObject.Invoke (Python.Runtime.PyTuple args in main.py:line 35
TypeError : Cannot get managed object (Open Stacktrace)
Vladimir
Matthew Griffin,
Try this
2021-04-01 09:31:00 : MSFTrsi: 100.0
2021-04-01 09:31:00 : rsiabove80
2021-04-01 09:32:00 : MSFTrsi: 0.0
2021-04-01 09:33:00 : MSFTrsi: 69.23077
2021-04-01 09:34:00 : MSFTrsi: 80.24691
2021-04-01 09:34:00 : rsiabove80
2021-04-01 09:35:00 : MSFTrsi: 66.32653
2021-04-01 09:36:00 : MSFTrsi: 81.46067
2021-04-01 09:36:00 : rsiabove80
2021-04-01 09:37:00 : MSFTrsi: 86.8
2021-04-01 09:37:00 : rsiabove80
2021-04-01 09:38:00 : MSFTrsi: 89.82737
Matthew Griffin
Matthew Griffin
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!