Overall Statistics |
Total Trades 990 Average Win 2.65% Average Loss -2.68% Compounding Annual Return -17.626% Drawdown 91.500% Expectancy -0.129 Net Profit -87.383% Sharpe Ratio -0.522 Loss Rate 56% Win Rate 44% Profit-Loss Ratio 0.99 Alpha -0.108 Beta -0.072 Annual Standard Deviation 0.214 Annual Variance 0.046 Information Ratio -0.583 Tracking Error 0.278 Treynor Ratio 1.556 Total Fees $0.00 |
using System; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// Possibles states of two moving averages. /// </summary> public enum CrossingMovingAveragesSignals { Bullish = 1, FastCrossSlowFromAbove = -2, Bearish = -1, FastCrossSlowFromBelow = 2 } public class CrossingMovingAverages { private readonly CompositeIndicator<IndicatorDataPoint> _moving_average_difference; private int _lastSignal; public CrossingMovingAverages(IndicatorBase<IndicatorDataPoint> fast_moving_average, IndicatorBase<IndicatorDataPoint> slow_moving_average) { _moving_average_difference = fast_moving_average.Minus(slow_moving_average); _moving_average_difference.Updated += MaDiffUpdated; } /// <summary> /// Gets the actual state of both moving averages. /// </summary> public CrossingMovingAveragesSignals Signal { get; set; } /// <summary> /// Gets a value indicating whether this instance is ready. /// </summary> /// <value> /// <c>true</c> if this instance is ready; otherwise, <c>false</c>. /// </value> public bool IsReady { get { return _moving_average_difference.IsReady; } } private void MaDiffUpdated(object sender, IndicatorDataPoint updated) { if (!IsReady) { return; } var actualSignal = Math.Sign(_moving_average_difference); if (actualSignal == _lastSignal || _lastSignal == 0) { Signal = (CrossingMovingAveragesSignals)actualSignal; } else if (_lastSignal == -1 && actualSignal == 1) { Signal = CrossingMovingAveragesSignals.FastCrossSlowFromBelow; } else if (_lastSignal == 1 && actualSignal == -1) { Signal = CrossingMovingAveragesSignals.FastCrossSlowFromAbove; } _lastSignal = actualSignal; } } }
using System; using System.Collections.Generic; using NodaTime; using QuantConnect.Brokerages; using QuantConnect.Data; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Market; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp.DateTimeEffectAlgo { public class DateTimeEffectAlgoAnonymous : QCAlgorithm { /* +-------------------------------------------------+ * |Algorithm Control Panel | * +-------------------------------------------------+*/ private readonly string _pair = "GBPUSD"; private readonly decimal _leverage = 10m; private readonly decimal _exposure = 0.8m; TimeSpan _entryTimeThreshold = new TimeSpan(hours:9, minutes:15, seconds:0); private int _first_fast_sma_period = 74; private int _first_slow_sma_period = 97; private int _second_fast_sma_period = 28; private int _second_slow_sma_period = 30; private decimal _shareByPair; /* +-------------------------------------------------+*/ private Symbol _symbol; private CrossingMovingAverages _first_sma_cross; private CrossingMovingAverages _second_sma_cross; private SimpleMovingAverage _first_fast_sma; private SimpleMovingAverage _first_slow_sma; private SimpleMovingAverage _second_fast_sma; private SimpleMovingAverage _second_slow_sma; public override void Initialize() { SetStartDate(year: 2007, month: 01, day: 01); //Set Start Date SetEndDate(year: 2017, month: 09, day: 01); //Set End Date SetCash(startingCash: 25000); //Set Strategy Cash SetBrokerageModel(BrokerageName.OandaBrokerage); _shareByPair = _leverage * _exposure; // Find more symbols here: http://quantconnect.com/data _symbol = AddForex(_pair, Resolution.Minute, "OANDA", leverage: _leverage).Symbol; _first_fast_sma = new SimpleMovingAverage(_first_fast_sma_period); _first_slow_sma = new SimpleMovingAverage(_first_slow_sma_period); _first_sma_cross = new CrossingMovingAverages(_first_fast_sma, _first_slow_sma); _second_fast_sma = new SimpleMovingAverage(_second_fast_sma_period); _second_slow_sma = new SimpleMovingAverage(_second_slow_sma_period); _second_sma_cross = new CrossingMovingAverages(_second_fast_sma, _second_slow_sma); var fifteenMinuteConsolidator = new QuoteBarConsolidator(TimeSpan.FromMinutes(15)); fifteenMinuteConsolidator.DataConsolidated += FifteenMinuteConsolidatorOnDataConsolidated; SubscriptionManager.AddConsolidator(_symbol, fifteenMinuteConsolidator); Schedule.On(DateRules.EveryDay(), TimeRules.At(21, 15, DateTimeZone.Utc), () => { if (Portfolio[_symbol].IsShort) { Liquidate(_symbol); } }); } private void FifteenMinuteConsolidatorOnDataConsolidated(object sender, QuoteBar quoteBar) { var idp = new IndicatorDataPoint { Time = Time, Value = quoteBar.Close }; _first_fast_sma.Update(idp); _first_slow_sma.Update(idp); _second_fast_sma.Update(idp); _second_slow_sma.Update(idp); // Enter short before 9am gmt on 15min bar close... if (Time.ToUniversalTime().TimeOfDay <= _entryTimeThreshold) { // ... when SMA(97) Crosses Above SMA(74)... if (_first_sma_cross.Signal == CrossingMovingAveragesSignals.FastCrossSlowFromBelow) { // ... and SMA(28) > SMA(30) if (_second_sma_cross.Signal == CrossingMovingAveragesSignals.Bullish) { SetHoldings(_symbol, - _shareByPair); } } } } } }