Hi, all. When comparing two variables, eg is x > y, I only get one answer "False" which I believe has to do with mixed (and incompatible) data types for x and y. Despite attempts at converting to float() and other dtypes, I have not found a solution. The logs highlight the issue. Any help would be greatly appreciated.
Dan Whitnable
Is there a backtest attached? All I see is "502 Bad Gateway". Maybe paste your code and I could take a stab at it.
Dan Whitnable
Do something like this
if price >= self.sma10[s].Current.Value: self.SetHoldings(s, 1.0) if price < self.sma10[s].Current.Value: self.SetHoldings(s, 0.0)
You defined 'self.sma10' as a dict indexed by a security (ie "SPY" and "IWM" in this case). The values in the dictionary are SMA indicator objects. So, in order to retrieve and compare to the indicator values one needs to first index into the dict (that's what the [s] does). However, that simply returns the value stored in the dict which is a SMA indicator object. In order to get the current value of an indicator object one needs to use the 'Curent.Value' method.
Hope that makes sense. Attached is a working backtest.
Good luck!
Brett C.
Dan, your input was extremely helpful, and as always, clear and concise. Many thanks!
Brett C.
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!