my code is supposed to scan and print the stocks meeting the criteria without repeating the same stock more than once. the issues I need help with:
- Why some stocks are repeated more than once?
- why stock.price or stock.adjusted price when uncommented in this line [#stock.AdjustedPrice > self.averages[symbol].EMA20 and] it's cuasing the following error. Runtime Error: TypeError : Cannot get managed object at CoarseSelectionFunction stock.AdjustedPrice > self.averages[symbol].EMA20 and === at Python.Runtime.Dispatcher.TrueDispatch(Object[] args) at Python.Runtime.Dispatcher.Dispatch(Object[] args) at __System_Func`2\[\[System_Collections_Generic_IEnumerable`1\[\[QuantConnect_Data_UniverseSelection_CoarseFundamental\ in main.py: line 31
Fred Painchaud
HI Mostafa,
2. Don't do coarse = [c for c in coarse if c.Price > 1000]. It messes with Python.NET dispatch algorithm. If you use another variable instead of overwriting coarse, it should be fine. For instance:
Fred
Mostafa Omran
Thanks Fred. For the first point, i just realized I was placing the loop to print stocks in the wrong place and now it's fixed (no repeated stocks any more).
For the second point, I changed the (coarse) variable to (selectedStocks) and still getting the same error. What surprises me a lot the same expression (stock.AdjustedPrice) is used few lines above with the averages.update method and that didn't cause any problem, but it's not working and causing error when used in this if comparison statement (stock.AdjustedPrice > self.averages[symbol].EMA20). Any idea how I can fix that?
Mostafa Omran
I just found the solution in another thread.
Comparing current stock price to ema should be in the following format:
stock.AdjustedPrice or Price > self.averages[symbol].EMA20.Current.Value
instead of my original code which caused the error:
stock.AdjustedPrice > self.averages[symbol].EMA20
Mostafa Omran
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!