| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 16773.923% Drawdown 10.400% Expectancy 0 Net Profit 8.796% Sharpe Ratio 6.316 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -3.556 Beta 567.548 Annual Standard Deviation 0.5 Annual Variance 0.25 Information Ratio 6.294 Tracking Error 0.5 Treynor Ratio 0.006 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 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);
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);
}
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);
}
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;
}
}