Overall Statistics |
Total Trades 103 Average Win 0.05% Average Loss -0.04% Compounding Annual Return -0.024% Drawdown 0.800% Expectancy -0.044 Net Profit -0.084% Sharpe Ratio -0.07 Loss Rate 59% Win Rate 41% Profit-Loss Ratio 1.32 Alpha 0.001 Beta -0.049 Annual Standard Deviation 0.003 Annual Variance 0 Information Ratio -5.923 Tracking Error 0.003 Treynor Ratio 0.004 Total Fees $0.00 |
namespace QuantConnect { /* * Basic Template Algorithm * * The underlying QCAlgorithm class has many methods which enable you to use QuantConnect. * We have explained some of these here, but the full base class can be found at: * https://github.com/QuantConnect/Lean/tree/master/Algorithm */ public class BasicTemplateAlgorithm : QCAlgorithm { private string _symbol = "EURUSD"; ExponentialMovingAverage _emaFast; ExponentialMovingAverage _emaSlow; ExponentialMovingAverage _emaBase; RollingWindow<decimal> _rollingFast; RollingWindow<decimal> _rollingSlow; public override void Initialize() { // backtest parameters SetStartDate(2016, 1, 1); SetEndDate(DateTime.Now); // cash allocation SetCash(25000); // request specific equities // including forex. Options and futures in beta. //AddEquity("SPY", Resolution.Minute); AddForex(_symbol, Resolution.Hour); var eightHours = new QuoteBarConsolidator(TimeSpan.FromHours(8)); eightHours.DataConsolidated += OnEightHourBar; SetWarmUp(TimeSpan.FromDays(20)); _emaFast = new ExponentialMovingAverage(10); _emaSlow = new ExponentialMovingAverage(20); _emaBase = new ExponentialMovingAverage(50); RegisterIndicator(_symbol, _emaFast, eightHours); RegisterIndicator(_symbol, _emaSlow, eightHours); RegisterIndicator(_symbol, _emaBase, eightHours); _rollingFast = new RollingWindow<decimal>(3); _rollingSlow = new RollingWindow<decimal>(3); //SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin); } public override void OnEndOfDay() { Plot("EMA", _emaFast, _emaSlow, _emaBase); } public void OnEightHourBar(object sender, QuoteBar bar) { if(!_emaSlow.IsReady) return; _rollingFast.Add(_emaFast); _rollingSlow.Add(_emaSlow); if(_rollingFast.Count < 3) return; var quantity = Portfolio[_symbol].Quantity; if(quantity != 0) { if(quantity > 0) { if(_emaFast < _emaSlow && bar.Close > _emaBase) { Debug("Exit Buy"); Liquidate(); } }else { if(_emaFast > _emaSlow && bar.Close < _emaBase) { Debug("Exit Sell"); Liquidate(); } } } if(quantity == 0) { if(_rollingFast[0] > _rollingSlow[0]){ if(_rollingFast[1] < _rollingSlow[1]) { Debug("Buy"); MarketOrder(_symbol, 1000); } }else if(_emaFast < _emaSlow && _rollingFast[1] > _rollingSlow[1]) { Debug("Sell"); MarketOrder(_symbol, -1000); } } } /* * New data arrives here. * The "Slice" data represents a slice of time, it has all the data you need for a moment. */ public override void OnData(Slice data) { } } }