Hi,

I'm trying to use the HeikinAshi indicator with multiple forex securities adapting a code to my strategy but I'm not able to use the registerindicator with HeikinAshi, below is the code, Is there any way to use the HeikinAshi indicator with multiple symbols?

namespace QuantConnect { /* * QuantConnect University: Full Basic Template: * * The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect. * We have explained some of these here, but the full algorithm can be found at: * https://github.com/QuantConnect/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs */ public class BasicTemplateAlgorithm : QCAlgorithm { private readonly List<string> Symbols = new List<string>{"USDJPY","AUDCHF"}; private readonly Dictionary<string, SymbolData> Data = new Dictionary<string, SymbolData>(); //Initialize the data and resolution you require for your strategy: public override void Initialize() { //Start and End Date range for the backtest: SetStartDate(2013, 1, 1); SetEndDate(2015, 1, 1); //Cash allocation SetCash(25000); SetBrokerageModel(BrokerageName.OandaBrokerage); //Add as many securities as you like. All the data will be passed into the event handler: foreach (var symbol in Symbols) { AddSecurity(SecurityType.Forex, symbol, Resolution.Daily); // create symbol data for each symbol and initialize it Data.Add(symbol, new SymbolData(symbol, this)); } } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(TradeBars data) { foreach (var symbolData in Data.Values) { // do something with our symbol data if (symbolData.Security.Close > symbolData.EMA_Long) { SetHoldings(symbolData.Symbol, .75m*symbolData.Security.Leverage/(decimal)Symbols.Count); } } } } public class SymbolData { public readonly string Symbol; public readonly Security Security; public readonly ExponentialMovingAverage EMA_Short; public readonly ExponentialMovingAverage EMA_Long; public readonly HeikinAshi HA; public SymbolData(string symbol, QCAlgorithm algorithm) { Symbol = symbol; Security = algorithm.Securities[symbol]; var consolidator = new QuoteBarConsolidator(TimeSpan.FromDays(1)); EMA_Short = new ExponentialMovingAverage(21); EMA_Long = new ExponentialMovingAverage(55); HA = new HeikinAshi(); //algorithm.RegisterIndicator(symbol, SMA, consolidator, Field.Close); algorithm.RegisterIndicator(symbol, EMA_Long, consolidator, Field.Close); algorithm.RegisterIndicator(symbol, EMA_Short, consolidator, Field.Close); algorithm.RegisterIndicator(symbol, HA, consolidator, Field.Close); } } }

Author