Overall Statistics |
Total Trades 2170 Average Win 0.38% Average Loss -0.18% Compounding Annual Return -6.657% Drawdown 25.000% Expectancy -0.112 Net Profit -19.313% Sharpe Ratio -0.635 Loss Rate 71% Win Rate 29% Profit-Loss Ratio 2.07 Alpha -0.045 Beta -0.005 Annual Standard Deviation 0.072 Annual Variance 0.005 Information Ratio -0.771 Tracking Error 0.132 Treynor Ratio 9.686 Total Fees $4340.00 |
using System; using System.Collections.Generic; using QuantConnect.Data.Consolidators; using QuantConnect.Indicators; using QuantConnect.Data.Market; namespace QuantConnect { public class BasicTemplateAlgorithm : QCAlgorithm { TradeBar _eurusdHourly; int warmupCount = 0; string symbol = "EURUSD"; int state; private RollingWindow<TEMAState> _win; private TripleExponentialMovingAverage _tema; //Initialize the data and resolution you require for your strategy: public override void Initialize() { //0 = default, -1 = short, 1 = long int state = 0; //Start and End Date range for the backtest: SetStartDate(2014, 1, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); //add security AddSecurity(SecurityType.Forex, symbol, Resolution.Hour); _win = new RollingWindow<TEMAState>(4); _tema = TEMA(symbol, 20); //Cash allocation SetCash(25000); //set brokerage model SetBrokerageModel(BrokerageName.OandaBrokerage); } //hourly data handler public void OnData(TradeBars data) { Debug("test"); if (_tema.IsReady) _win.Add(new TEMAState(_tema)); if (!_win.IsReady) return; //warm up some more hours of good data if(warmupCount != 10){ warmupCount++; Debug("still warming up"); return; } decimal current = _win[0].Value; decimal previous = _win[3].Value; if(current > previous){ goLong(data); return; }else if(current < previous){ goShort(data); return; }else{ return; } } public void goLong(TradeBars data){ //check if it's already going long if(state == 1){ return; } state = 1; Debug("Going long!"); decimal current = _win[0].Value; decimal previous = _win[3].Value; Debug("Current: " + current + "Previous: " + previous); SetHoldings(symbol, 1.0); } public void goShort(TradeBars data){ //check if it's already going short if(state == -1){ return; } state = -1; Debug("Going short!"); decimal current = _win[0].Value; decimal previous = _win[3].Value; Debug("Current: " + current + "Previous: " + previous); SetHoldings(symbol, -1.0); } public class TEMAState { public readonly decimal Value; public TEMAState(TripleExponentialMovingAverage tema) { Value = tema.Current; } } } }