Overall Statistics
Total Trades
6
Average Win
30.24%
Average Loss
-11.87%
Compounding Annual Return
10.203%
Drawdown
25.200%
Expectancy
1.839
Net Profit
421.838%
Sharpe Ratio
0.672
Loss Rate
20%
Win Rate
80%
Profit-Loss Ratio
2.55
Alpha
0.11
Beta
0.001
Annual Standard Deviation
0.164
Annual Variance
0.027
Information Ratio
0.11
Tracking Error
0.257
Treynor Ratio
124.509
Total Fees
$21.91
namespace QuantConnect 
{
    public class PlotFillsAlgorithm : QCAlgorithm
    {
    	public ExponentialMovingAverage emaFast, emaSlow;
        public override void Initialize() 
        {
            SetStartDate(1998, 1, 1);
            SetEndDate(2015, 1, 1);
            SetCash(25000);
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
            
            // define our indicators
            var spyClose = Identity("SPY");
			emaFast = EMA("SPY", 100);
			emaSlow = EMA("SPY", 300);
			
			// define our chart
			var chart = new Chart("SPY");
			chart.AddSeries(new Series(spyClose.Name, SeriesType.Line));
			chart.AddSeries(new Series(emaFast.Name, SeriesType.Line));
			chart.AddSeries(new Series(emaSlow.Name, SeriesType.Line));
			
			// notice we use scatter plots for the buy/sell plots
			chart.AddSeries(new Series(OrderDirection.Buy.ToString(), SeriesType.Scatter));
			chart.AddSeries(new Series(OrderDirection.Sell.ToString(), SeriesType.Scatter));
			AddChart(chart);
			
			// auto plot our indicators on our symbol chart
			PlotIndicator("SPY", spyClose, emaFast, emaSlow);
        }

        //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) 
        {
        	const decimal threshold = 0.001m;
        	if (Securities["SPY"].Holdings.Quantity <= 0 && emaFast > emaSlow*(1+threshold))
        	{
        		SetHoldings("SPY", 1);
        	}
        	if (Securities["SPY"].Holdings.Quantity >= 0 && emaFast < emaSlow*(1-threshold))
        	{
        		SetHoldings("SPY", -1);
        	}
        }
        
        public override void OnOrderEvent(OrderEvent fill)
        {
        	// if this is a fill event (Filled or PartiallyFilled) then plot it
        	if (fill.Status.IsFill())
        	{
        		Plot(fill.Symbol, fill.Direction.ToString(), fill.FillPrice);
        	}
        }
    }
}