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.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("Close: " + data.Close + " - AdjustedClose: " + data.AdjustedClose + " - Value: " + data.Value);

            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
    {
        public override DateTime EndTime
        {
            get { return Time + Period; }
            set { Time = value - Period; }
        }

        public new TimeSpan Period
        {
            get { return QuantConnect.Time.OneDay; }
        }

        /// <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], "yyyy-MM-dd", 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;
        }
    }
}