Overall Statistics
namespace QuantConnect.Algorithm.CSharp
{ 
    public class STO_RSI_DiffBars : QCAlgorithm
    {
    	private Symbol _spy;
        private Stochastic _sto;
        private RelativeStrengthIndex _rsi; 
        private RollingWindow<TradeBar> _win;
        
        public override void Initialize()
        {
            SetStartDate(2017, 01, 01);  //Set Start Date
            
            AddEquity("SPY", Resolution.Minute);
            _spy = Securities["SPY"].Symbol;
            
            _rsi = new RelativeStrengthIndex(14);
            _sto = new Stochastic(12, 3, 5);
            _win = new RollingWindow<TradeBar>(2);
            
            var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(15));
            SubscriptionManager.AddConsolidator(_spy, consolidator);
				
			consolidator.DataConsolidated += OnConsolidatorData;
            
        }

		public void OnConsolidatorData(object s, TradeBar bar)
		{
			// Populate rolling window
			_win.Add(bar);
			if (!_win.IsReady) return;
			
			// Updates Stochastic with the previous bar
			_sto.Update(_win[1]);
			
			// Updates RSI with the current bar
			_rsi.Update(bar.EndTime, bar.Close);
			
			if(!_sto.IsReady || !_rsi.IsReady) return;
			
			Plot("Indicators",  _sto);
			Plot("Indicators",  _rsi);
			
			if(!Portfolio.Invested)
			{
				SetHoldings(_spy, 1);
			}
		}

        public void OnData(TradeBars data)
        {
        	//
        }
    }
}