Hello All! 

I am trying to test 3 crypto currencies (BTCUSD,ETHUSD, and LTCUSD) using EMA of 20 using rolling windows to check old emas.

Initially I added the following:

//initialize moving averages dictionary
for symbol in self.symbols:
	self.fast_ema[symbol] = self.EMA(symbol,fast_moving_average,Resolution.Daily)
    self.ema_window[symbol] = RollingWindow[float](2)
    self.fast_ema[symbol].Updated += lambda sender,updated: self.ema_window[symbol].Add(self.fast_ema[symbol].Current.Value)

What I noticed is that only the last element of the list subcribes to the function. I tried a few combinations, but ended up doing the following which works properly:
 

       self.fast_ema["BTCUSD"] = self.EMA("BTCUSD",fast_moving_average,Resolution.Daily)
        self.ema_window["BTCUSD"] = RollingWindow[float](2)
        self.fast_ema["BTCUSD"].Updated += lambda sender,updated: self.ema_window["BTCUSD"].Add(self.fast_ema["BTCUSD"].Current.Value)  
        
        self.fast_ema["ETHUSD"] = self.EMA("ETHUSD",fast_moving_average,Resolution.Daily)
        self.ema_window["ETHUSD"] = RollingWindow[float](2)
        self.fast_ema["ETHUSD"].Updated += lambda sender,updated: self.ema_window["ETHUSD"].Add(self.fast_ema["ETHUSD"].Current.Value)    
          
        self.fast_ema["LTCUSD"] = self.EMA("LTCUSD",fast_moving_average,Resolution.Daily)
        self.ema_window["LTCUSD"] = RollingWindow[float](2)
        self.fast_ema["LTCUSD"].Updated += lambda sender,updated: self.ema_window["LTCUSD"].Add(self.fast_ema["LTCUSD"].Current.Value) 

Anyone has idea about this behavior. each lambda call should get a new function object reference. 

I tried also which named functions leading to the same behavior.

 

Author