Overall Statistics
Total Trades
2
Average Win
0.22%
Average Loss
0%
Compounding Annual Return
1234.850%
Drawdown
0.200%
Expectancy
0
Net Profit
0.712%
Sharpe Ratio
11.225
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
1.796
Beta
0.508
Annual Standard Deviation
0.08
Annual Variance
0.006
Information Ratio
34.394
Tracking Error
0.077
Treynor Ratio
1.768
Total Fees
$0.00
using System;
using System.Globalization;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Indicators.CandlestickPatterns;


namespace QuantConnect.Algorithm.CSharp
{ 
    public class CandlestickClosingMarubozu5minESData : QCAlgorithm
    {
        private string _symbol = "ES";
        private ClosingMarubozu _pattern4 = new ClosingMarubozu();

        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must be initialized.
        /// </summary>
        public override void Initialize()
        {
            SetStartDate(2016, 01, 04);  //Set Start Date
            SetEndDate(2016, 01, 04);    //Set End Date
            SetCash(100000);             //Set Strategy Cash

            AddData<CloseMaribo>(_symbol);

            _pattern4 = CandlestickPatterns.ClosingMarubozu(_symbol);
        }

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>        
        public void OnData(CloseMaribo data)
        {
            if (data.Time.TimeOfDay < new TimeSpan(8, 35, 00) ||
                 data.Time.TimeOfDay > new TimeSpan(11, 00, 00))
            {
                return;
            }
            else
            {
                if (_pattern4 == 1)
                {
                    // Bullish ClosingMarubozu, go long
                    Debug(Time + " -> found Bullish ClosingMarubozu");
                    SetHoldings(_symbol, 1);
                }
                else if (_pattern4 == -1)
                {
                    // Bearish ClosingMarubozu, go short
                    Debug(Time + " -> found Bearish ClosingMarubozu");
                    SetHoldings(_symbol, -1);
                }
            }
        }
    }

    public class CloseMaribo : TradeBar
    {
        /// <summary>
        /// Return the URL external source for the data: QuantConnect will download it an read it line by line automatically:
        /// </summary>
        public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
        {
            return new SubscriptionDataSource("https://www.dropbox.com/s/jni2cm5r9d22a60/ES%202016-01-04%20-%202016-12-19.csv?dl=1", SubscriptionTransportMedium.RemoteFile);
        }

        /// <summary>
        /// Convert each line of the file above into an object.
        /// </summary>
        public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
        {
            CloseMaribo cmBar = new CloseMaribo();

            try
            {
                var data = line.Split(',');
                //Required.
                cmBar.Symbol = "ES";

                cmBar.Time = DateTime.ParseExact(data[0] + data[1], "yyyyMMddhhmmss", CultureInfo.InvariantCulture);

                //User configured / optional data on each bar:
                cmBar.Open = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
                cmBar.High = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
                cmBar.Low = Convert.ToDecimal(data[4], CultureInfo.InvariantCulture);
                cmBar.Close = Convert.ToDecimal(data[5], CultureInfo.InvariantCulture);
                cmBar.Volume = Convert.ToInt32(data[6], CultureInfo.InvariantCulture);

                //This is the value the engine uses for portfolio calculations
                cmBar.Value = cmBar.Close;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            return cmBar;
        }
    }
}