Overall Statistics
using System;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.CSharp
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        private Symbol _symbol = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);
        private RollingWindow<decimal> Close;
        private BollingerBands _bb;
        public override void Initialize()
        {
            SetStartDate(DateTime.Now.Date.AddDays(-30));  //Set Start Date
            SetEndDate(DateTime.Now.Date.AddDays(0));    //Set End Date
            SetCash(10000);             //Set Strategy Cash
            AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute);
            Close  = new RollingWindow<decimal>(2);
            _bb = BB(_symbol, 20, 2, MovingAverageType.Simple, Resolution.Minute);
        }

        public void OnData(Slice data)
        {
            Close.Add(data[_symbol].Close);
            if (!Close.IsReady) return;
            var Close_cur = Close[0];
            var Close_priv = Close[1];
            var holding = Portfolio[_symbol];
			var SellCondition = (Close_priv > Close_cur);
			var BuyCondition = (Close_priv < Close_cur);
			if (holding.Quantity == 0) //no position
			{
				if (BuyCondition)
				{
					SetHoldings(_symbol, 1.0);
				}
				else if (SellCondition)
				{
					SetHoldings(_symbol, -1.0);
				}
			}
			else if (holding.Quantity > 0) //in long position
			{
				if (SellCondition)
				{
					Liquidate(_symbol);
					SetHoldings(_symbol, -1.0);
				}
			}
			else if (holding.Quantity < 0) //in short position
			{
				if (BuyCondition)
				{
					Liquidate(_symbol);
					SetHoldings(_symbol, 1.0);
				}
			}
			Plot("Trade Plot", "Price", data.Bars[_symbol].Close);
			Plot("Trade Plot", "BB Upper", _bb.UpperBand);
			Plot("Trade Plot", "BB Lower", _bb.LowerBand);
        }
    }
}