Hi, everyone, I am making some progress on my code, but I am unable to access Time values. Specifically, I am trying to find out if it is 9:31 am in OnData(TradeBars data) by getting the Time.Hours and Time.Minute values and converting them to string, but they haven'nt worked.

Also, I need help accessing variables in OnData(TradeBars data) after declaring them in initialize. For example, how would I access values from the string[] stocksToTrade array in OnData(TradeBars data)?

I am basically working off the basic template from Quantopian which I cloned. I am a decent progrogrammer in various languages, but I am new to C#.

Unfortunately, I have no successful backtests, because I havn't been able to get the code to run. I have been receiving only error messages. But I have attached my source code. 

Sorry for the long post. I would greatly appreciate any help anyone could me. Thank you.

 

 

 

 


namespace QuantConnect
{  
    // Name your algorithm class anything, as long as it inherits QCAlgorithm
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2013, 9, 13);        
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            SetCash(1000);
            AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute);
            string[] stocksToTrade = {"AES","ASIX","BAC","CHK","F","FCX","FTR","HBAN","HPQ"};
            foreach (var stock in stocksToTrade)
                                {
        AddSecurity(SecurityType.Equity, stock, Resolution.Minute);
                }
        }

        //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)
        {  
            if (!Portfolio.HoldStock)
            {
            //                Console.WriteLine("Just testing");
                Order("MSFT", (int)Math.Floor(Portfolio.Cash / data["MSFT"].Close) );
                Debug("Debug Purchased MSFT");
                var hourVal = Time.Hours.
                var minuteVal = Time.minute
                Debug(hourVal);
                Debug(minuteVal);
            }
        }
    }
}

Author