Overall Statistics |
Total Trades 1055 Average Win 0.84% Average Loss -0.48% Compounding Annual Return -87.310% Drawdown 100.000% Expectancy 0.816 Net Profit -99.842% Sharpe Ratio -0.847 Loss Rate 34% Win Rate 66% Profit-Loss Ratio 1.76 Alpha -0.845 Beta -0.342 Annual Standard Deviation 1.02 Annual Variance 1.041 Information Ratio -0.895 Tracking Error 1.03 Treynor Ratio 2.529 Total Fees $36939.09 |
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; decimal current = 0; decimal previous = 0; Chart plotter; bool hasData = false; 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>(3); _tema = TEMA(symbol, 20); //Cash allocation SetCash(25000); //set brokerage model SetBrokerageModel(BrokerageName.OandaBrokerage); plotter = new Chart("Plotter"); plotter.AddSeries(new Series("current", SeriesType.Line, index:0)); plotter.AddSeries(new Series("previous", SeriesType.Line, index:0)); plotter.AddSeries(new Series("Long", SeriesType.Scatter, index:1)); plotter.AddSeries(new Series("Short", SeriesType.Scatter, index:1)); AddChart(plotter); } //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 != 4){ warmupCount++; Debug("still warming up"); return; } current = _win[0].Value; previous = _win[2].Value; hasData = true; 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[2].Value; //Debug("Current: " + current + " Previous: " + previous); Plot("Plotter", "Long", current); SetHoldings(symbol, -25.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[2].Value; //Debug("Current: " + current + " Previous: " + previous); Plot("Plotter", "Short", current); SetHoldings(symbol, 25.0); } public override void OnEndOfDay() { if (hasData) { Plot("Plotter", "current", current); Plot("Plotter", "previous", previous); } } public class TEMAState { public readonly decimal Value; public TEMAState(TripleExponentialMovingAverage tema) { Value = tema.Current; } } } }