Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
16.653%
Drawdown
9.600%
Expectancy
0
Net Profit
0%
Sharpe Ratio
1.34
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.016
Beta
0.984
Annual Standard Deviation
0.12
Annual Variance
0.014
Information Ratio
0.89
Tracking Error
0.016
Treynor Ratio
0.163
Total Fees
$2.55
namespace QuantConnect 
{   
    public class MultiTimeFrameMovingAverageAlgorithm : QCAlgorithm
    {
    	private Dictionary<int, SimpleMovingAverage> _sma = new Dictionary<int, SimpleMovingAverage>();
    	private Dictionary<int, RelativeStrengthIndex> _rsi = new Dictionary<int, RelativeStrengthIndex>();
    	
        public override void Initialize() 
        {
            SetStartDate(2016, 1, 1);
            
            AddEquity("SPY", Resolution.Minute);
            
            foreach(var minute in new int[]{ 5, 10, 15, 20, 30 })
            {
            	// Create Consolidator
            	var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(minute));
            	
            	// Create indicators
            	var sma = new SimpleMovingAverage(22);
            	var rsi = new RelativeStrengthIndex(14);
            	
            	// Register indicators to the consolidator to be updated at its frequency
            	RegisterIndicator("SPY", sma, consolidator);
				RegisterIndicator("SPY", rsi, consolidator);
				
				// Add the consolidator to the subscription manager to get updated with data from security 
				SubscriptionManager.AddConsolidator("SPY", consolidator);
				
				// Add SMA and RSI to Dictionaries
				_sma.Add(minute, sma);
            	_rsi.Add(minute, rsi);
            }
        }

        public override void OnData(Slice data) 
        {
            if (!Portfolio.HoldStock) SetHoldings("SPY", 1);
        }
        
        // At end of day, plot the indicators for visual sanity check
        public override void OnEndOfDay()
        {
        	foreach(var kvp in _sma)
        	{
        		Plot("SMA", "M" + kvp.Key, kvp.Value);
        	}
        	
        	foreach(var kvp in _rsi)
        	{
        		Plot("RSI", "M" + kvp.Key, kvp.Value);
        	}
        }
    }
}