Overall Statistics
using System.Drawing; // for Color

namespace QuantConnect 
{ 
    public class ExampleStochasticChartingAlgorithm : QCAlgorithm
    {
       	private RelativeStrengthIndex rsi;
       	private bool _bRSIUpdated;

        String _symbol = "XIV";
        String _plotter = "RSI";
        
        int minVal = 30;
        
        public override void Initialize()
        {
            SetStartDate(2016, 3, 1);
            SetEndDate(2016, 12, 31);

        // Set data resolution
            var targetSecurity = AddSecurity(SecurityType.Equity, _symbol, Resolution.Second, false, true);
            targetSecurity.MarginModel = new PatternDayTradingMarginModel();
            targetSecurity.FeeModel = new ConstantFeeTransactionModel(1);
            
        // Cash allocation
            SetCash(100000);

		// Brokerage model and account type:
			SetBrokerageModel(BrokerageName.Default, AccountType.Margin);

        // Gather appropriate indicators
        	var symbol = Symbol(_symbol);
        	rsi = RSI(symbol, 5, MovingAverageType.Wilders, Resolution.Daily);
        	rsi.Updated += OnRSIUpdate;
        	_bRSIUpdated = false;

            //Warmup Time
            SetWarmUp(TimeSpan.FromDays(1));

            Chart plotter = new Chart(_plotter);
            plotter.AddSeries(new Series("RSI", SeriesType.Line, " ",Color.Blue));
            plotter.AddSeries(new Series("Min", SeriesType.Line, " ",Color.Red));
            AddChart(plotter);
        }
        
        //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) 
        {
        // If warming up...
            if (IsWarmingUp)
            {
			// Return until algorithm is ready to execute.
				return;
			}

        // Access current tradebar data.
        	TradeBar dataBar = data[_symbol];

		// Test RSI
			if (_bRSIUpdated)
			{
				Log("RSI: " + rsi + "[" + dataBar.Time.ToString() + "]");
				_bRSIUpdated = false;
			}

        }

        //RSI OnUpdate Function
        public void OnRSIUpdate(object sender, IndicatorDataPoint data)
        {
        // RSI Update
			Log("OnRSIUpdate()");
			_bRSIUpdated = true;

		// Plot Chart if RSI is ready
        	if (rsi.IsReady)
        	{
        		Plot(_plotter,"RSI", rsi);
        		Plot(_plotter,"Min", minVal);
        	}
        }

        public override void OnEndOfDay() 
        {
        }
    }
    
}