Overall Statistics
Total Trades
4
Average Win
0.49%
Average Loss
-7.92%
Compounding Annual Return
-99.109%
Drawdown
8.000%
Expectancy
-0.469
Net Profit
-7.467%
Sharpe Ratio
-5.935
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.06
Alpha
-3.552
Beta
7.628
Annual Standard Deviation
0.525
Annual Variance
0.276
Information Ratio
-6.31
Tracking Error
0.503
Treynor Ratio
-0.409
Total Fees
$4.00
namespace QuantConnect {

    //
    //	Make sure to change "BasicTemplateAlgorithm" to your algorithm class name, and that all
    //	files use "public partial class" if you want to split up your algorithm namespace into multiple files.
    //

    //public partial class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm
    //{
    //  Extension functions can go here...(ones that need access to QCAlgorithm functions e.g. Debug, Log etc.)
    //}

    //public class Indicator 
    //{
    //  ...or you can define whole new classes independent of the QuantConnect Context
    //}
     public class movingaveragealgorithm
     {
     	private decimal period;
     	private decimal ema;
     	private int samples;
     	
     	public decimal EMA
     	{
     		get {return ema;}
     	}
     	public movingaveragealgorithm(decimal period)
     	{
     		this.period=period;
     	}
     	public bool ready
     	{
     		get {return samples>=period;}
     	}
     	public decimal AddSample(decimal price)
     	{
     		if(samples==0)
     		{
     			ema=price;
     		}else
     		{
     			ema=(1/period)*price+((period-1)/period)*ema;
     		}
     		samples++;
     		return ema;
     	}
     }

}                        
// using System;
// using System.Linq;
// using QuantConnect.Data;
// using QuantConnect.Data.Consolidators;
// using QuantConnect.Data.Market;
// using QuantConnect.Indicators;

// namespace QuantConnect.Algorithm
// {
//     public  class TimeIndicator
//     {
//         bool isMonday;
//         bool isFriday;
        
//         public bool day(Time date)
//         {
//         	if(date.Date.DayOfWeek==DayOfWeek.Monday)
//         	return true;
//         }

//     } // End Partial Algorithm Template - Indicators.

// } // End QC Namespace                        



namespace QuantConnect 
{   

    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	
        private  string symbol = "UVXY";
    	private  int quantity=100;
    	private  int trigger=0;
    	//movingaveragealgorithm emafast=new movingaveragealgorithm(10);
    	//movingaveragealgorithm emaslow=new movingaveragealgorithm(50);
        //MovingAverageConvergenceDivergence _macd;

    	
   public override void Initialize()
        {
            SetStartDate(2016, 07, 22);
            SetEndDate(2016, 07, 27);
            SetCash(30000);
            AddSecurity(SecurityType.Equity, symbol, Resolution.Daily);
            
            SetBrokerageModel(Brokerages.BrokerageName.InteractiveBrokersBrokerage);
            //SetBrokerageModel(Brokerages.BrokerageName.TradierBrokerage);
            
            Securities["UVXY"].SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted);

         }

		public void OnData(Splits splits)
        {
            Split split = splits["UVXY"];
            Debug("## Split >>  Split factor: "+split.SplitFactor);
        }

        public void OnData(TradeBars data)
        {  
        	
        	Log(Time.ToString()+"\t"+Securities["UVXY"].Close + "Holding: "+Portfolio.Securities["UVXY"].Holdings.Quantity);
        	if(!Portfolio.HoldStock)
        	{
        		MarketOrder(symbol, -quantity);
        		Log(Time.ToString()+"\t"+"short "+quantity);
        	}
        	else if(Portfolio.HoldStock)
        	{
        		Order(symbol,quantity);
        		Log(Portfolio["UVXY"].Quantity+"");
        		Log(Time.ToString()+"\t"+"close "+quantity);

        	}
        	
        }
    }
}