Overall Statistics
Total Trades
355
Average Win
8.86%
Average Loss
-4.10%
Compounding Annual Return
-58.848%
Drawdown
94.000%
Expectancy
0.012
Net Profit
-55.733%
Sharpe Ratio
0.194
Loss Rate
68%
Win Rate
32%
Profit-Loss Ratio
2.16
Alpha
0.255
Beta
0.217
Annual Standard Deviation
1.4
Annual Variance
1.961
Information Ratio
0.139
Tracking Error
1.403
Treynor Ratio
1.256
Total Fees
$701.67
namespace QuantConnect 
{   
    /*
    *   The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect.
    *   We have explained some of these here, but the full algorithm can be found at:
    *   https://github.com/QuantConnect/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs
    */
    public class RollingWindowAlgorithm : QCAlgorithm
    {
    	public const string Symbol = "JDST";
    	
    	public ExponentialMovingAverage Fast;
    	public ExponentialMovingAverage Slow;
    	public MovingAverageConvergenceDivergence DailyMacd;
    	public Momentum DailyMomentum;
    	public RelativeStrengthIndex DailyRSI;
        //Initialize the data and resolution you require for your strategy:

        
        public override void Initialize() 
        {
			// Code Automatically Generated  
			//AddSecurity(SecurityType.Equity, "NVDA", Resolution.Second);
			
			// Code Automatically Generated  
			//AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Second);
			
			
			
			
            //Start and End Date range for the backtest:
            SetStartDate(2016, 1, 1);         
            SetEndDate(2016, 11, 30);
            // In Initialize // Warm up of data. 
            //SetWarmup(TimeSpan.FromMinutes(900));
            //Cash allocation
            SetCash(10000);
            
            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, Symbol, Resolution.Minute);
            
            // define our 15 minute consolidator, this makes 15min bars from 1min bars
            var fifteenMinute = new TradeBarConsolidator(TimeSpan.FromMinutes(15));
            // register the consolidator to receive data for our 'Symbol'
            SubscriptionManager.AddConsolidator(Symbol, fifteenMinute);
            
            // attach our 15 minute event handler, the 'OnFifteenMinuteData' will be called
            // at 9:45, 10:00, 10:15, ect... until 4:00pm
            fifteenMinute.DataConsolidated += OnFifteenMinuteData;
            
            // define our 15 minute fast EMA
            Fast = new ExponentialMovingAverage(5);
            
            // define our 15 minute slow EMA
            Slow = new ExponentialMovingAverage(10);
            
            // we can also define some daily indicators
            //DailyMomentum = MOM(Symbol, 10);
            //DailyMacd = MACD(Symbol, 12, 26, 9, MovingAverageType.Wilders, Resolution.Daily);
            DailyRSI = RSI(Symbol, 14,  MovingAverageType.Simple, Resolution.Minute);
            
        }
        
        const decimal tolerance = 0.001m;
        
        public void OnFifteenMinuteData(object sender, TradeBar bar)
        {
        	// update our indicators
        	Fast.Update(Time, bar.Close);
        	Slow.Update(Time, bar.Close);
        	
        	var quantity = Portfolio[Symbol].Quantity;
        	
        	// short or flat and longer term up
        //if (quantity <= 0 && DailyRSI > 25 && DailyMomentum > 0)
        if (quantity <= 0 && DailyRSI > 25)
        
        	{
        		// check for short term up
        		if (Fast > Slow*(1+tolerance))
        		{
        			// move everything into a long position
        			SetHoldings(Symbol, 1.0);
        		}
        	}
        	// long or flat and longer term down
        	//else if (quantity >= 0 && DailyRSI < 75 && DailyMomentum <  0)
        	else if (quantity >= 0 && DailyRSI < 75)
        	{
        		// check for short term down
        		if (Fast < Slow*(1-tolerance))
        		{
        			// move everything into a short position
        			SetHoldings(Symbol, -1.0);
        		}
        	}
        	// check for exit conditions
        	else if (quantity != 0)
        	{
        		// check for long exit
        		if (quantity > 0 && Fast < Slow*(1-tolerance))
        		{
        			Liquidate(Symbol);
        		}
        		// check for short exit
        		else if (quantity < 0 && Fast > Slow*(1+tolerance))
        		{
        			Liquidate(Symbol);
        		}
        	}
        }

        //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) 
        {
        }
    }
}