Overall Statistics
Total Trades
13
Average Win
0.39%
Average Loss
0%
Compounding Annual Return
68.129%
Drawdown
2.500%
Expectancy
0
Net Profit
1.995%
Sharpe Ratio
6.775
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.703
Beta
0.308
Annual Standard Deviation
0.067
Annual Variance
0.005
Information Ratio
11.266
Tracking Error
0.112
Treynor Ratio
1.475
Total Fees
$13.00
namespace QuantConnect 
{   

    public class ScheduledEventPractice : QCAlgorithm
    {
    	public string symbol = "SPY";
    	public decimal dailyLevel;

        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
			SetStartDate(2016, 1, 1);
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            SetCash(25000);           

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

        //Data Event Handler: New data arrives here. 
        public void OnData(TradeBars data) 
        {
        	
        	// Schedule event to fire daily and capture Close of first bar
            Schedule.On(DateRules.EveryDay(symbol), TimeRules.At(9, 31, 01), () =>
            {
                Log("Scheduled Event fired at : " + Time);
                dailyLevel = data[symbol].Close;
                Log("dailyLevel = " + dailyLevel );
            });

			// If not holding stock, order if price drops to 50 cents below captured dailyLevel
            if (!Portfolio.HoldStock && data[symbol].Close < dailyLevel - 0.50m) 
            {
                int quantity = (int)Math.Floor(Portfolio.Cash / data[symbol].Close);
                
                Order(symbol, quantity);
                
                Log("Purchased " + symbol + " : " + quantity + " at " + data[symbol].Close + " on " + Time);
            }
            // If holding stock, sell if price rises to 75 cents above purchased price
            if (Portfolio.HoldStock && data[symbol].Close >= Portfolio[symbol].AveragePrice + 0.75m) 
            {
            	int _holdings = Portfolio[symbol].Quantity;
            	decimal _sellPrice = Securities[symbol].Price;
                Liquidate();
                
                Log("Sold " + symbol + " : " + _holdings + " at " + _sellPrice + " on " + Time);
            }
        }
    }
}