Overall Statistics
Total Trades
11
Average Win
0.33%
Average Loss
0%
Compounding Annual Return
-16.087%
Drawdown
22.900%
Expectancy
0
Net Profit
-9.781%
Sharpe Ratio
-0.506
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.122
Beta
-0.24
Annual Standard Deviation
0.229
Annual Variance
0.052
Information Ratio
-0.304
Tracking Error
0.3
Treynor Ratio
0.483
Total Fees
$11.00
namespace QuantConnect
{
/*
	Designed as a "first use" algorithm by a trader new to robotic trading, with a cash
	trading account of minimal size. Does not use leverage or margin and waits 4 days from
	sell date to next purchase date to allow for funds settlement by the broker. Does not
	make a lot of money, but does not lose. It may however leave you holding stock for a long
	time if you choose a stock that is falling, never to come back (oops!).
	
	Happy trading!
*/
    public class BeginnerAlgo : QCAlgorithm
    {
        private string symbol = "AAPL";

        private SimpleMovingAverage slow;
        private ExponentialMovingAverage fast;
        private decimal sellPrice = 0m;
        private DateTime currentDate;
        private DateTime nextTradeDate;

        public override void Initialize()
        {
            // set up our analysis span
            SetStartDate(2015, 6, 1);
            SetEndDate(2015, 12, 31);
            SetCash(1000);

            // request "symbol's" data with minute resolution
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // create a 20 minute simple moving average
            slow = SMA(symbol, 20, Resolution.Minute);

            // create a 5 minute exponential moving average
			fast = EMA(symbol, 5, Resolution.Minute);
        }

        public void OnData(TradeBars data)
        {
            // wait for our slow SMA to fully initialize
            if (!slow.IsReady) return;

            var holdings = Portfolio[symbol].Quantity;
			decimal currentPrice = data[symbol].Close;
			currentDate = Time.Date;
			
            // make sure we have no short positions (shouldn't be necessary, but doesn't hurt)
            if (holdings < 0)
            	{
            		Liquidate(symbol);
            	}

            // if we hold no stock, and 4 days have passed since our last sale, and
            // the EMA is greater than the SMA, we'll go long
            if (!Portfolio.HoldStock && currentDate >= nextTradeDate && fast > slow)
            	{
                    SetHoldings(symbol, 1.0);
                    Log("BUY  >> " + Securities[symbol].Price);
                    
                    // set sell price for 50 cents per share profit
                    sellPrice = Portfolio[symbol].AveragePrice + 0.50m;
            	}            

       		// if we hold stock, and we have reached our target sell price, we'll liquidate our position
           	if (Portfolio.HoldStock && currentPrice > sellPrice)
            	{
                	Liquidate(symbol);
               		Log("SELL >> " + Securities[symbol].Price);
               		
                	// set next possible trade date for 4 days out to allow for settlement
                    nextTradeDate = currentDate.AddDays(4);
            	}
        }
    }
}