Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return -59.205% Drawdown 11.900% Expectancy 0 Net Profit -1.705% Sharpe Ratio -0.468 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -3.58 Beta 269.415 Annual Standard Deviation 0.698 Annual Variance 0.488 Information Ratio -0.485 Tracking Error 0.698 Treynor Ratio -0.001 Total Fees $2.49 |
using QuantConnect.Brokerages; using QuantConnect.Data.Consolidators; using QuantConnect.Indicators; using System; using System.Collections.Generic; using System.Linq; namespace QuantConnect.Algorithm.CSharp { public class AKoolAlgo : QCAlgorithm { //private Symbol _Symbol = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.USA); public string _Symbol = "BTCUSD"; private MovingAverageConvergenceDivergence MACD; private ExponentialMovingAverage fastEMA; private ExponentialMovingAverage slowEMA; private IndicatorBase<IndicatorDataPoint> signal; private List<SignalProp> macdHist = new List<SignalProp>(); private int globalCount = 0; private decimal _macd = 0; public override void Initialize() { SetStartDate(2018, 3, 30); //Set Start Date SetEndDate(2018, 4, 5); //Set End Date SetCash(1000); //Set Strategy Cash SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash); AddSecurity(SecurityType.Crypto, _Symbol, Resolution.Hour); //AddCrypto("BTCUSD", Resolution.Hour); fastEMA = new ExponentialMovingAverage(12); slowEMA = new ExponentialMovingAverage(26); MACD = new MovingAverageConvergenceDivergence(12,26,9); signal = new FunctionalIndicator<IndicatorDataPoint>("ChrisCustom", point => RatioIndicator_ComputeNextValue(point, fastEMA, fastEMA), ratioIndicator => RatioIndicator_IsReady() ); var Consolidator = new TradeBarConsolidator(TimeSpan.FromHours(1)); //Consolidator.DataConsolidated += OnHalfHour; SubscriptionManager.AddConsolidator(_Symbol, Consolidator); RegisterIndicator(_Symbol, signal, Consolidator, x => x.Value); RegisterIndicator(_Symbol, fastEMA, Consolidator, x => x.Value); RegisterIndicator(_Symbol, slowEMA, Consolidator, x => x.Value); RegisterIndicator(_Symbol, MACD, Consolidator, x => x.Value); } public override void OnData(Slice data) { if (!Portfolio.Invested) { SetHoldings(_Symbol, 1); } _macd = fastEMA - slowEMA; Plot("MACD", _macd); Plot("signal", signal); Plot("histO", _macd - signal); Plot("NewMACD", MACD); Plot("NewMACD Signal", MACD.Signal); Plot("NewMACD Histogram", MACD.Histogram); } private decimal RatioIndicator_ComputeNextValue(IndicatorDataPoint data, IndicatorBase<IndicatorDataPoint> fastMA, IndicatorBase<IndicatorDataPoint> slowMA) { decimal retunVal = 0; globalCount++; SignalProp tempObj = new SignalProp(); tempObj.sequence = globalCount; tempObj.value = fastMA - slowMA; macdHist.Add(tempObj); if (macdHist.Count > 9) { macdHist = TrimDecimalList(macdHist, 9); } if (macdHist.Count == 9) { decimal tempval = 0; foreach (SignalProp item in macdHist) { tempval = item.value + tempval; retunVal = tempval / 9; } } return retunVal; } private bool RatioIndicator_IsReady() { return (macdHist.Count > 8); } public List<SignalProp> TrimDecimalList(List<SignalProp> decimalList, int amounttokeep) { decimalList = decimalList.OrderByDescending(o => o.sequence).ToList(); int count = 0; List<SignalProp> temp = new List<SignalProp>(); foreach (SignalProp item in decimalList) { count++; temp.Add(item); if (count == amounttokeep) { break; } } return temp; } } public class SignalProp { public int sequence; public decimal value; } }