#Directly below is what's in the initialize which I have set up for the 30 and 50 day sma
self.sma30 = self.SMA(self.spy, 30, Resolution.Daily)
self.sma50 = self.SMA(self.spy, 50, Resolution.Daily)
#Below is what's in the OnData which are the lines the error is for
if price * 1.05 >= high and self.sma30.Current.Value < price * 1.05>= high and self.sma50.Current.Value < price:
if not self.Portfolio[self.spy].IsLong:
self.SetHoldings(self.spy, 1)
elif price * 0.95 <= low and self.sma30.Current.Value > price:
if not self.Portfolio[self.spy].IsShort:
self.SetHoldings(self.spy, -1)
Stack Trace:
Cannot get managed object
at OnData
if price * 1.05 >= high and self.sma30.Current.Value < price * 1.05>= high and self.sma50.Current.Value < price:
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 72
Error Message:
[ERROR] FATAL UNHANDLED EXCEPTION:Extensions.SetRuntimeError(): Extensions.SetRuntimeError(): RuntimeError at 08/04/2021 13:31:00 UTC. Context: OnData Python.Runtime.PythonException: Cannot get managed object, File "/QuantConnect/backtesting/./cache/algorithm/project/main.py", line 73, in OnData, if price * 1.05 >= high and self.sma30.Current.Value < price * 1.05>= high and self.sma50.Current.Value < price:, at Python.Runtime.PythonException.ThrowLastAsClrException(), at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw), at Python.Runtime.PyObject.TryInvoke(InvokeBinder binder, Object[] args, Object& result), at CallSite.Target(Closure , CallSite , Object , PythonSlice ), at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1), at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.OnData(Slice slice) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 643, at QuantConnect.Lean.Engine.AlgorithmManager.Run(AlgorithmNodePacket job, IAlgorithm algorithm, ISynchronizer synchronizer, ITransactionHandler transactions, IResultHandler results, IRealTimeHandler realtime, ILeanManager leanManager, CancellationToken token) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/AlgorithmManager.cs:line 531,ApiConnection.TryRequest(backtest/status/update): Error: The operation has timed out.