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.Indicators.CandlestickPatterns;

namespace QuantConnect.Algorithm.CSharp
{   
    /// <summary>
    /// Basic template algorithm simply initializes the date range and cash
    /// </summary>
    public class CandlestickClosingMarubozuAlgorithm : QCAlgorithm
    {
        private string _symbol = "INDEX_SPY";
        private ClosingMarubozu _pattern = 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(2014, 01, 01);  //Set Start Date
            SetEndDate(2014, 12, 31);    //Set End Date
            SetCash(100000);             //Set Strategy Cash
            
            AddData<CloseMar>("INDEX_SPY");

            _pattern = 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(CloseMar data)
        {
            if (_pattern == 1)
            {
                // Bullish ClosingMarubozu, go long
                SetHoldings(_symbol, 1);
            }
            else if (_pattern == -1)
            {
                // Bearish ClosingMarubozu, go short
                SetHoldings(_symbol, -1);
            }
        }
    }

    public class CloseMar : BaseData
    {
        public decimal Open = 0;
        public decimal High = 0;
        public decimal Low = 0;
        public decimal Close = 0;
        public decimal AdjustedClose = 0;
        public decimal Volume = 0;

        public CloseMar()
        {
            this.Symbol = "";
        }

        /// <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)
        {
            var startDate = new DateTime(2010, 01, 01).ToString("yyyy-MM-dd");
            var endDate = DateTime.Now.ToString("yyyy-MM-dd");

            //QUANDL WRAPPER ON YAHOO FINANCE API TO SORT DATA:
            //https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_SPY.csv?trim_start=2010-01-01&trim_end=2015-12-31&sort_order=asc
            return new SubscriptionDataSource("https://www.quandl.com/api/v1/datasets/YAHOO/" + config.Symbol + ".csv?trim_start=" + startDate + "&trim_end=" + endDate + "&sort_order=asc&exclude_headers=true", 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)
        {
            CloseMar cmBar = new CloseMar();

            try
            {
                string[] 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.ToDecimal(data[5]);
                cmBar.AdjustedClose = Convert.ToDecimal(data[6]);

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