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;
using System.Drawing;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;

namespace QuantConnect.Algorithm.CSharp
{
    /// <summary>
    /// Demonstration of how to initialize and use the RenkoConsolidator
    /// </summary>
    /// <meta name="tag" content="renko" />
    /// <meta name="tag" content="indicators" />
    /// <meta name="tag" content="using data" />
    /// <meta name="tag" content="consolidating data" />
    public class RenkoConsolidatorAlgorithm : QCAlgorithm
    {
    	protected DateTime iBarTime;
    	protected string iSymbol = "SPY";
    	protected string iChartName = "Deals";
    	
        /// <summary>
        /// Initializes the algorithm state.
        /// </summary>
        public override void Initialize()
        {
            SetStartDate(2012, 01, 01);
            SetEndDate(2013, 01, 01);

            AddSecurity(SecurityType.Equity, iSymbol);

            // this is the simple constructor that will perform the renko logic to the Value
            // property of the data it receives.

            // break SPY into $2.5 renko bricks and send that data to our 'OnRenkoBar' method
            var renkoClose = new RenkoConsolidator(10m);

            renkoClose.DataConsolidated += (sender, consolidated) =>
            {
                HandleRenkoClose(consolidated);
            };

            SubscriptionManager.AddConsolidator(iSymbol, renkoClose);

            var chart = new Chart(iChartName);
			var seriesStock = new Series("Stock", SeriesType.Line, 0);
			var seriesBuy = new Series("Buy", SeriesType.Scatter, 0) { Color = Color.Blue, ScatterMarkerSymbol = ScatterMarkerSymbol.Triangle };
			var seriesSell = new Series("Sell", SeriesType.Scatter, 0) { Color = Color.Red, ScatterMarkerSymbol = ScatterMarkerSymbol.TriangleDown };
			var seriesVolume = new Series("Volume", SeriesType.Line, 1);
			var seriesBalance = new Series("Balance", SeriesType.Line, 2);
			var seriesEquity = new Series("Equity", SeriesType.Line, 2);
			var seriesRenko = new Series("Renko", SeriesType.Line, 3);
			var seriesRenkoVolume = new Series("Renko Volume", SeriesType.Line, 4);

			chart.AddSeries(seriesStock);
			chart.AddSeries(seriesVolume);
			chart.AddSeries(seriesBuy);
			chart.AddSeries(seriesSell);
			chart.AddSeries(seriesBalance);
			chart.AddSeries(seriesEquity);
			chart.AddSeries(seriesRenko);
			chart.AddSeries(seriesRenkoVolume);

            AddChart(chart);
        }

        /// <summary>
        /// We're doing our analysis in the OnRenkoBar method, but the framework verifies that this method exists, so we define it.
        /// </summary>
        public void OnData(TradeBars data)
        {
        	if (Securities[iSymbol].LocalTime > iBarTime.AddHours(1))
        	{
        		iBarTime = Securities[iSymbol].LocalTime;
        		Plot(iChartName, "Stock", data[iSymbol].Close);
        		Plot(iChartName, "Volume", data[iSymbol].Volume);
        	}
        }

        /// <summary>
        /// This function is called by our renkoClose consolidator defined in Initialize()
        /// </summary>
        /// <param name="data">The new renko bar produced by the consolidator</param>
        public void HandleRenkoClose(RenkoBar data)
        {
        	Plot(iChartName, "Renko", data.Close);
        	Plot(iChartName, "Renko Volume", data.Volume);

            if (!Portfolio.Invested)
            {
                //SetHoldings(data.Symbol, 1.0);
            }
        }
	}
}