Overall Statistics
using QuantConnect.Data;

namespace QuantConnect.Algorithm.CSharp
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        private bool _canTrade;
        private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
        
        public override void Initialize()
        {
            SetStartDate(2013, 10, 07);  //Set Start Date
            SetEndDate(2013, 10, 11);    //Set End Date
            SetCash(100000);             //Set Strategy Cash
            // Find more symbols here: http://quantconnect.com/data
            AddEquity(_spy, Resolution.Minute);
            
            // schedule an event to fire every trading day for a security
            // the time rule here tells it to fire 0 minutes after SPY's market open
            Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 0), () => 
            {
            	_canTrade = true;
           	});
            
            // schedule an event to fire every trading day for a security
            // the time rule here tells it to fire 10 minutes before SPY's market close
            Schedule.On(DateRules.EveryDay(_spy), TimeRules.BeforeMarketClose(_spy, 10), () =>
            {
            	_canTrade = false;
            	Liquidate();
            	Debug(Time + " -> Liquidate");
            });
        }

        public override void OnData(Slice data)
        {
            if (_canTrade && !Portfolio.Invested)
            {
            	Buy(_spy,1);
            	Debug(Time + " -> BUY");
            }
        }
    }
}