Hello,
I'm brand new to QuantConnect and this is my first post. I'm going through the tutorial on coding up an EMA cross strategy (youtube link) and have found a weird issue, not sure if it could be a bug. When I run a C# algo for the following parameters:
security: SPY
time period: between 3/20/14 and 3/21/14
resolutions: Second, Minute, Hour
I get an error:
"Runtime Error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform member binding on `null' value"
This happens with C# and does not happen with Python.
Here is my C# code:
namespace QuantConnect
{
public class BasicTemplateAlgorithm : QCAlgorithm
{
string symbol = "SPY";
public override void Initialize()
{
SetStartDate(2014, 3, 20);
SetEndDate(2014, 3, 21);
SetCash(30000);
AddEquity(symbol, Resolution.Minute);
}
public override void OnData(Slice data)
{
decimal price = data[symbol].Close;
}
}
}
Here is my Python code:
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self._symbol = "SPY"
self.SetStartDate(2014,3,20)
self.SetEndDate(2014,3,21)
self.SetCash(30000)
self.AddEquity(self._symbol, Resolution.Minute)
def OnData(self, slice):
if slice[self._symbol] is None: return
self.lastPrice = slice[self._symbol].Close
price = str(self.lastPrice)
# self.Debug(price)
Here is the stack trace:
Runtime Error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform member binding on `null' value
at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet] (System.Runtime.CompilerServices.CallSite site, T0 arg0) [0x00127] in <63992662b765477a898ef49cdcc99ee2>:0
at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at QuantConnect.BasicTemplateAlgorithm.OnData (QuantConnect.Data.Slice data) [0x00095] in <88556ecddcf344799948cd3cd676333b>:0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.IDataFeed feed, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions, QuantConnect.Lean.Engine.Results.IResultHandler results, QuantConnect.Lean.Engine.RealTime.IRealTimeHandler realtime, QuantConnect.Lean.Engine.Server.ILeanManager leanManager, QuantConnect.Lean.Engine.Alpha.IAlphaHandler alphas, System.Threading.CancellationToken token) [0x01258] in <11f348cb016f463b86b03dce3a52e390>:0 (Open Stacktrace)