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