Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
namespace QuantConnect 
{   
    public class MultipleSymbolConsolidator : QCAlgorithm
    {
    	private Dictionary<Symbol, AverageTrueRange> _atr = new Dictionary<Symbol, AverageTrueRange>();
    	private Dictionary<Symbol, SimpleMovingAverage> _sma = new Dictionary<Symbol, SimpleMovingAverage>();

        public override void Initialize()
        {
            SetStartDate(2016, 12, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            SetCash(50000);
            
            foreach(var symbol in new[]{"SPY", "UVXY"})
            {
            	AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
            	var fiveMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(5));
            	var atr = new AverageTrueRange("ATR_" + symbol, 5, MovingAverageType.Simple);
            	var sma = new SimpleMovingAverage("SMA_" + symbol, 5);
            	_atr.Add(symbol, atr);
            	_sma.Add(symbol, sma);
            	RegisterIndicator(symbol, atr, fiveMinuteConsolidator);
				RegisterIndicator(symbol, sma, fiveMinuteConsolidator);
				SubscriptionManager.AddConsolidator(symbol, fiveMinuteConsolidator);
				
				if(!symbol.Equals("SPY")) return;
				fiveMinuteConsolidator.DataConsolidated += FiveMinuteHandler;
            }
        }
        
        private void FiveMinuteHandler(object sender, TradeBar bar)
        {
        	if( _atr.Values.All(x=>x.IsReady) && _sma.Values.All(x=>x.IsReady)) 
        	{
        		Console.WriteLine(
        			"Time: " + bar.EndTime + 
        		    " SPY Price: " + Securities["SPY"].Price + 
        		    " UVXY Price: " + Securities["UVXY"].Price + 
        		    " SPY SMA: " + _sma["SPY"] + 
        		    " UVXY SMA: " + _sma["UVXY"] + 
        		    " SPY ATR: " + _atr["SPY"] + 
        		    " UVXY ATR: " + _atr["UVXY"]);
        		    
        		var holdings = Portfolio["UVXY"].Quantity;
        		Plot("SMA", _sma.Values.ToArray());
        		Plot("ATR", _atr.Values.ToArray());
        	} 
        	else 
        	{
        		Console.WriteLine("Warming up");
        	}
        }

        public void OnData(TradeBars data) 
        {
        	//
        }
    }
}
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
    //}

}