I am trying to get the Basic Template Forex Algorithm code to run:

from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Indicators") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Data import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * from datetime import timedelta import numpy as np ### <summary> ### Algorithm demonstrating FOREX asset types and requesting history on them in bulk. As FOREX uses ### QuoteBars you should request slices ### </summary> ### <meta name="tag" content="using data" /> ### <meta name="tag" content="history and warm up" /> ### <meta name="tag" content="history" /> ### <meta name="tag" content="forex" /> class BasicTemplateForexAlgorithm(QCAlgorithm): def Initialize(self): # Set the cash we'd like to use for our backtest self.SetCash(100000) # Start and end dates for the backtest. self.SetStartDate(2013, 10, 7) self.SetEndDate(2013, 10, 11) # Add FOREX contract you want to trade # find available contracts here https://www.quantconnect.com/data#forex/oanda/cfd self.AddForex("EURUSD", Resolution.Minute) self.AddForex("GBPUSD", Resolution.Minute) self.AddForex("EURGBP", Resolution.Minute) self.History(5, Resolution.Daily) self.History(5, Resolution.Hour) self.History(5, Resolution.Minute) history = self.History(TimeSpan.FromSeconds(5), Resolution.Second) for data in sorted(history, key=lambda x: x.Time): for key in data.Keys: self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value)) def OnData(self, data): # Print to console to verify that data is coming in for key in data.Keys: self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value)) algo = BasicTemplateForexAlgorithm() algo.Initialize()

However I keep running into this error:

Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ./cache/algorithm/main.py. AlgorithmPythonWrapper(): NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Algorithm.QCAlgorithm.AddSecurity[T] (QuantConnect.SecurityType securityType, System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage, System.Boolean extendedMarketHours) [0x0008e] in <e5aa4033954c479fab6d1b73330b4508>:0
at QuantConnect.Algorithm.QCAlgorithm.AddForex (System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage) [0x00001] in <e5aa4033954c479fab6d1b73330b4508>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at <module> in main.py:line 56
:: algo.Initialize()
at Initialize in main.py:line 35
NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Algorithm.QCAlgorithm.AddSecurity[T] (QuantConnect.SecurityType securityType, System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage, System.Boolean extendedMarketHours) [0x0008e] in <e5aa4033954c479fab6d1b73330b4508>:0
at QuantConnect.Algorithm.QCAlgorithm.AddForex (System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage) [0x00001] in <e5aa4033954c479fab6d1b73330b4508>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0 Stack Trace: QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ./cache/algorithm/main.py. AlgorithmPythonWrapper(): NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Algorithm.QCAlgorithm.AddSecurity[T] (QuantConnect.SecurityType securityType, System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage, System.Boolean extendedMarketHours) [0x0008e] in <e5aa4033954c479fab6d1b73330b4508>:0
at QuantConnect.Algorithm.QCAlgorithm.AddForex (System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage) [0x00001] in <e5aa4033954c479fab6d1b73330b4508>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at <module> in main.py:line 56
:: algo.Initialize()
at Initialize in main.py:line 35
NullReferenceException : Object reference not set to an instance of an object
at QuantConnect.Algorithm.QCAlgorithm.AddSecurity[T] (QuantConnect.SecurityType securityType, System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage, System.Boolean extendedMarketHours) [0x0008e] in <e5aa4033954c479fab6d1b73330b4508>:0
at QuantConnect.Algorithm.QCAlgorithm.AddForex (System.String ticker, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage) [0x00001] in <e5aa4033954c479fab6d1b73330b4508>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance (QuantConnect.Packets.AlgorithmNodePacket algorithmNodePacket, System.String assemblyPath) [0x0009c] in <4aaa8484de144245b7fdcf42493c0ea9>:0
at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Lean.Engine.AlgorithmManager manager, System.String assemblyPath) [0x00140] in <4aaa8484de144245b7fdcf42493c0ea9>:0 (Open Stacktrace)

 

Author