Overall Statistics
Total Trades
18
Average Win
0.94%
Average Loss
-1.81%
Compounding Annual Return
-6.024%
Drawdown
16.700%
Expectancy
-0.336
Net Profit
-11.173%
Sharpe Ratio
-0.502
Loss Rate
56%
Win Rate
44%
Profit-Loss Ratio
0.52
Alpha
-0.038
Beta
-0.037
Annual Standard Deviation
0.079
Annual Variance
0.006
Information Ratio
-0.629
Tracking Error
0.147
Treynor Ratio
1.083
Total Fees
$0.00
using System;
using System.Globalization;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Indicators.CandlestickPatterns;


namespace QuantConnect.Algorithm.CSharp
{
    /// <summary>
    /// Basic template algorithm simply initializes the date range and cash
    /// </summary>
    public class CandlestickClosingMarubozuDailyESData : QCAlgorithm
    {
        private string _symbol = "ES";
        private ClosingMarubozu _pattern3 = new ClosingMarubozu();

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

            AddData<CloseMarib>(_symbol);

            _pattern3 = CandlestickPatterns.ClosingMarubozu(_symbol);
        }

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public void OnData(CloseMarib data)
        {
            Debug(Time + " -> Value: " + data.Value + " pattern: " + _pattern3);

            if (_pattern3 == 1)
            {
                // Bullish ClosingMarubozu, go long
                Debug(Time + " -> found Bullish ClosingMarubozu");
                SetHoldings(_symbol, 1);
            }
            else if (_pattern3 == -1)
            {
                // Bearish ClosingMarubozu, go short
                Debug(Time + " -> found Bearish ClosingMarubozu");
                SetHoldings(_symbol, -1);
            }
        }
    }

    public class CloseMarib : 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 isLive)
        {
            return new SubscriptionDataSource("https://www.dropbox.com/s/bpk2i3hmzaa0c6t/ES%20daily%202015-01-01%20-%202015-12-31.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 isLive)
        {
            CloseMarib cmBar = new CloseMarib();

            try
            {
                var data = line.Split(',');
                //Required.
                cmBar.Symbol = config.Symbol;
                cmBar.Time = DateTime.ParseExact(data[0], "yyyyMMdd", CultureInfo.InvariantCulture);

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

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