Overall Statistics |
Total Trades 342 Average Win 1.58% Average Loss -0.33% Compounding Annual Return -2.085% Drawdown 11.600% Expectancy -0.018 Net Profit -2.519% Sharpe Ratio -0.091 Loss Rate 83% Win Rate 17% Profit-Loss Ratio 4.79 Alpha 0.327 Beta -24.347 Annual Standard Deviation 0.103 Annual Variance 0.011 Information Ratio -0.226 Tracking Error 0.103 Treynor Ratio 0 Total Fees $514.39 |
using System; namespace QuantConnect.Algorithm.CSharp { public class EMACrossExample : QCAlgorithm { //USER VARIABLES private string _Ticker = "BCHUSD"; int _MaxPosition = 500; int _MinPosition = 100; int _FastPeriod = 12; int _SlowPeriod = 26; // PROGRAM VARIABLES public decimal _Price; public decimal _Holding; public string _BaseSymbol; public decimal _USD; ExponentialMovingAverage _FastEMA; ExponentialMovingAverage _SlowEMA; // INITIALIASE BLOCK public override void Initialize() { SetStartDate(2017, 12, 22); SetEndDate(2019, 3, 8); SetCash(5000); var _Crypto = AddCrypto(_Ticker, Resolution.Hour); _BaseSymbol = _Crypto.BaseCurrencySymbol; SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash); _FastEMA = EMA(_Ticker, _FastPeriod, Resolution.Hour); _SlowEMA = EMA(_Ticker, _SlowPeriod, Resolution.Hour); } // ONDATA BLOCK public override void OnData(Slice data) { _Price = data[_Ticker].Price; _USD = Portfolio.CashBook["USD"].Amount; if (!Portfolio.Invested && _USD > _MinPosition) { if(_FastEMA > _SlowEMA) { decimal _Quantity = Math.Round(_MaxPosition / _Price, 6); MarketOrder(_Ticker, _Quantity); } } if(Portfolio.Invested) { _Holding = Portfolio.CashBook[_BaseSymbol].Amount; if(_FastEMA < _SlowEMA) { Sell(_Ticker, _Holding); } } } } }