Overall Statistics
Total Trades
435
Average Win
3.58%
Average Loss
-1.61%
Compounding Annual Return
660.750%
Drawdown
21.200%
Expectancy
0.530
Net Profit
424.058%
Sharpe Ratio
2.881
Loss Rate
53%
Win Rate
47%
Profit-Loss Ratio
2.22
Alpha
1.502
Beta
0.311
Annual Standard Deviation
0.533
Annual Variance
0.284
Information Ratio
2.663
Tracking Error
0.535
Treynor Ratio
4.942
Total Fees
$0.00
using System;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.CSharp
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        private SimpleMovingAverage _fast;
        private SimpleMovingAverage _slow;
        private string _sym = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);

        public override void Initialize()
        {
            SetStartDate(2017, 1, 1);  //Set Start Date
            SetEndDate(DateTime.Now);
            AddCrypto("BTCUSD", Resolution.Minute, Market.GDAX);
            SetCash(40000);
            
             var consolidator = new TradeBarConsolidator(3);
			consolidator.DataConsolidated += HourHandler;
			SubscriptionManager.AddConsolidator("BTCUSD", consolidator);

            _fast = SMA("BTCUSD", 5, Resolution.Hour);
            _slow = SMA("BTCUSD", 18, Resolution.Hour);
        }

        private void HourHandler(object sender, BaseData consolidated)
        {
        	Debug(Time.ToString() + " > New Bar!");
        	Plot(_sym, "Price", consolidated.Price);
        	
            // define a small tolerance on our checks to avoid bouncing
            const decimal tolerance = 0.00015m;
            var holdings = Portfolio[_sym].Quantity;
            Log("HOLDINGS " + holdings);

            // we only want to go long if we're currently short or flat
            if (holdings <= 0)
            {
            	Log("FASTSMA " + _fast);
            	Log("SLOWSMA " + _slow);
            	
                // if the fast is greater than the slow, we'll go long
                if (_fast > _slow * (1 + tolerance))
                {
                    Log("BUY  >> " + Securities[_sym].Price);
                    SetHoldings(_sym, 1.0);
                }
            }

            // we only want to liquidate if we're currently long
            // if the fast is less than the slow we'll liquidate our long
            if (holdings > 0 && _fast < _slow)
            {
                Log("SELL >> " + Securities[_sym].Price);
                Liquidate(_sym);
            }
            
            Plot(_sym, _fast, _slow);
        }
        
        public override void OnData(Slice data)
        {
        
        }
    }
}