/// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex;
            mylog.Debug(algoname);

            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _proformatransactions = new List<OrderTransaction>();
            string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv";
            if (File.Exists(filepath)) File.Delete(filepath);
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            symbol = new Symbol("AAPL");
            #region "Read Symbols from File"
            /**********************************************
             THIS SECTION IS FOR READING SYMBOLS FROM A FILE
            ************************************************/
            string symbols;
            var filename = AssemblyLocator.ExecutingDirectory() + "symbols.txt";
            using (StreamReader sr = new StreamReader(filename))
            {
                symbols = sr.ReadLine();
                sr.Close();
            }
            //symbol = new Symbol(symbols);
            #endregion

            minuteReturns.AppendFormat("{0},{1}", symbol, _startDate.ToShortDateString());
            minuteHeader.AppendFormat("Symbol,Date");

            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Indicators
            Price = new RollingWindow<IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend = new InstantaneousTrend("Main", 7, .24m);

            _orderTransactionProcessor = new OrderTransactionProcessor();
            _transactions = new List<OrderTransaction>();
            _ticketsQueue = new List<OrderTicket>();
            #region ITrend
            iTrendSignal = new ITrendSignal(7);
            LastOrderSent.Add(symbol, OrderSignal.doNothing);
            #endregion

            #region lists

            signalInfos.Add(new SignalInfo
            {
                Id = 0,
                Name = "Minutes_001",
                IsActive = true,
                SignalJson = string.Empty,
                Value = OrderSignal.doNothing,
                InternalState = string.Empty,
                SignalType = typeof(Sig9)
            });
            //signalInfos.Add(new SignalInfo
            //{
            //    Id = 1,
            //    Name = "ITrend",
            //    IsActive = true,
            //    SignalJson = string.Empty,
            //    Value = OrderSignal.doNothing,
            //    InternalState = string.Empty,
            //    SignalType = typeof(ITrendSignal)
            //});

            //foreach (SignalInfo s in signalInfos)
            //{
            //    s.IsActive = false;
            //    if (s.Id == LiveSignalIndex)
            //    {
            //        s.IsActive = true;
            //    }
            //}

            #endregion
            #region "15 Minute"
            // define our 15 minute consolidator
            //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));

            // if we want to make decisions every 15 minutes as well, we can add an event handler
            // to the DataConsolidated event
            //fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL;

            //trend15Min = new InstantaneousTrend(3);
            //RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close);

            //int fast = 15;

            //int slow = 30;

            //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)'
            //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast);
            //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow);

            //// register our indicator and consolidator together. this will wire the consolidator up to receive
            //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator
            //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);
            //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);
            #endregion

            // for use with Tradier. Default is IB.
            //var security = Securities[symbol];
            //security.TransactionModel = new ConstantFeeTransactionModel(1.0m);
        }
        //private string sig7comment;

        //private TradeBarConsolidator fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));
        //private InstantaneousTrend trend15Min;

        //private bool CanMakeTrade = true;
        //private bool MinuteDataActivated = false;

        #endregion

        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name + " UseSig=" + LiveSignalIndex;
            mylog.Debug(algoname);

            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _proformatransactions = new List <OrderTransaction>();
            string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv";
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            #endregion


            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            symbol = new Symbol("AAPL");
            #region "Read Symbols from File"

            /**********************************************
             * THIS SECTION IS FOR READING SYMBOLS FROM A FILE
             ************************************************/
            string symbols;
            var    filename = AssemblyLocator.ExecutingDirectory() + "symbols.txt";
            using (StreamReader sr = new StreamReader(filename))
            {
                symbols = sr.ReadLine();
                sr.Close();
            }
            //symbol = new Symbol(symbols);
            #endregion

            minuteReturns.AppendFormat("{0},{1}", symbol, _startDate.ToShortDateString());
            minuteHeader.AppendFormat("Symbol,Date");

            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Indicators
            Price = new RollingWindow <IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend = new InstantaneousTrend("Main", 7, .24m);

            _orderTransactionProcessor = new OrderTransactionProcessor();
            _transactions = new List <OrderTransaction>();
            _ticketsQueue = new List <OrderTicket>();
            #region ITrend
            iTrendSignal = new ITrendSignal(7);
            LastOrderSent.Add(symbol, OrderSignal.doNothing);
            #endregion

            #region lists

            signalInfos.Add(new SignalInfo
            {
                Id            = 0,
                Name          = "Minutes_001",
                IsActive      = true,
                SignalJson    = string.Empty,
                Value         = OrderSignal.doNothing,
                InternalState = string.Empty,
                SignalType    = typeof(Sig9)
            });
            //signalInfos.Add(new SignalInfo
            //{
            //    Id = 1,
            //    Name = "ITrend",
            //    IsActive = true,
            //    SignalJson = string.Empty,
            //    Value = OrderSignal.doNothing,
            //    InternalState = string.Empty,
            //    SignalType = typeof(ITrendSignal)
            //});


            //foreach (SignalInfo s in signalInfos)
            //{
            //    s.IsActive = false;
            //    if (s.Id == LiveSignalIndex)
            //    {
            //        s.IsActive = true;
            //    }
            //}

            #endregion
            #region "15 Minute"
            // define our 15 minute consolidator
            //var fifteenMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));

            // if we want to make decisions every 15 minutes as well, we can add an event handler
            // to the DataConsolidated event
            //fifteenMinuteConsolidator.DataConsolidated += OnFiftenMinuteAAPL;

            //trend15Min = new InstantaneousTrend(3);
            //RegisterIndicator(symbol, trend15Min, fifteenMinuteConsolidator, Field.Close);

            //int fast = 15;

            //int slow = 30;

            //// define our EMA, we'll manually register this, so we aren't using the helper function 'EMA(...)'
            //var fastEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA15", fast);
            //var slowEmaOnFifteenMinuteBars = new ExponentialMovingAverage("AAPL_EMA30", slow);

            //// register our indicator and consolidator together. this will wire the consolidator up to receive
            //// data for the specified symbol, and also set up the indicator to receive its data from the consolidator
            //RegisterIndicator("AAPL", fastEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);
            //RegisterIndicator("AAPL", slowEmaOnFifteenMinuteBars, fifteenMinuteConsolidator, Field.Close);
            #endregion

            // for use with Tradier. Default is IB.
            //var security = Securities[symbol];
            //security.TransactionModel = new ConstantFeeTransactionModel(1.0m);
        }