Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
-0.04%
Compounding Annual Return
-2.404%
Drawdown
0.000%
Expectancy
-1
Net Profit
-0.040%
Sharpe Ratio
-4.898
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.02
Beta
0.049
Annual Standard Deviation
0.003
Annual Variance
0
Information Ratio
-1.933
Tracking Error
0.038
Treynor Ratio
-0.345
Total Fees
$2.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);
            
            Securities["UVXY"].SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted);

            Schedule.On(DateRules.Every(DayOfWeek.Friday), TimeRules.AfterMarketOpen("UVXY",0), () =>
            {
                trigger=-1;
                Log(Time.ToString()+"");
            });
            
           Schedule.On(DateRules.Every(DayOfWeek.Monday), TimeRules.BeforeMarketClose("UVXY",0), () =>
            {
                trigger=1;
                Log(Time.ToString()+"");
            });
         
         
         }

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

        	}
        	
        }
    }
}