I have the following code which returns me an error:

Failed to initialize algorithm: Initialize(): System.NullReferenceException: Object reference not set to an instance of an object
at QuantConnect.Algorithm.CSharp.MyFirstAlgorithm.Initialize () [0x00113] in <c3378781b1e44bb3a34c27f412a5505b>:0
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler+<>c__DisplayClass19_0.<Setup>b__0 () [0x00066] in <1f6d6705efa94d3eb00c00b8efeb3d8b>:0 (Open Stacktrace)

 

What am I doing wrong? I try to add an exponential moving average as value in a dictionary with key the specific symbol.

What is the object it talks about whose reference is not set?

Maybe is a basic question but I am beginner with CSharp. Thanks for your time in advance!

 

        string _clSymbol;

  Dictionary<string,ExponentialMovingAverage> _sma,_smaLong = new Dictionary<string, ExponentialMovingAverage>();

        public override void Initialize()
        {
            _ImportedSecurities.Add("BCOUSD",new KeyValuePair<double, int>(0.1, 10));           

            foreach (string security in _ImportedSecurities.Keys)

            {
            _clSymbol = security;                
            AddCfd(_clSymbol, Resolution.Minute, Market.Oanda);
           _sma.Add(_clSymbol,EMA(_clSymbol, 7, Resolution.Daily));

         

Author