Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
using System; using System.Collections.Generic; using QuantConnect.Data; using QuantConnect.Data.Market; using System.Linq; using QuantConnect.Interfaces; using QuantConnect.Securities; using QuantConnect.Orders; using QuantConnect.Data.Consolidators; namespace QuantConnect.Algorithm.CSharp { public class TestAlgo : QCAlgorithm { // S&P 500 EMini futures private const string RootSP500 = Futures.Indices.SP500EMini; public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.USA); public RollingWindow<decimal> Open; public RollingWindow<decimal> Close; public RollingWindow<decimal> High; public RollingWindow<decimal> Low; public RollingWindow<decimal> Volume; public override void Initialize() { SetStartDate(2010, 01, 08); SetEndDate(2019, 10, 10); SetCash(1000000); var futureSP500 = AddFuture(RootSP500, Resolution.Minute); // set our expiry filter for this futures chain futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182)); Open = new RollingWindow<decimal>(4); Low = new RollingWindow<decimal>(4); High = new RollingWindow<decimal>(4); Close = new RollingWindow<decimal>(4); Volume = new RollingWindow<decimal>(4); } public override void OnData( Slice data ) { if(data.ContainsKey("futureSP500")) { Close.Add(data["futureSP500"].Close); Open.Add(data["futureSP500"].Open); High.Add(data["futureSP500"].High); Low.Add(data["futureSP500"].Low); Volume.Add(data["futureSP500"].Volume); var CurrentClose = Close[0]; var OneBarAgoClose = Close[1]; var TwoBarAgoClose = Close[2]; var ThreeBarAgoClose = Close[3]; var CurrentOpen = Open[0]; var OneBarAgoOpen = Open[1]; var TwoBarAgoOpen = Open[2]; var ThreeBarAgoOpen = Open[3]; var CurrentHigh = High[0]; var OneBarAgoHigh = High[1]; var TwoBarAgoHigh = High[2]; var ThreeBarAgoHigh = High[3]; var CurrentLow = Low[0]; var OneBarAgoLow = Low[1]; var TwoBarAgoLow = Low[2]; var ThreeBarAgoLow = Low[3]; var CurrentVolume = Volume[0]; var OneBarAgoVolume = Volume[1]; var TwoBarAgoVolume = Volume[2]; var ThreeBarAgoVolume = Volume[3]; if (CurrentClose > OneBarAgoClose) { MarketOrder("futureSP500", 10); } else { Liquidate(); } } } } }
namespace QuantConnect.Algorithm.Framework.Selection { public class FuturesUniverseSelectionModel : FutureUniverseSelectionModel{ public FuturesUniverseSelectionModel(Func<DateTime, IEnumerable<Symbol>> futureChainSymbolSelector) :base(TimeSpan.FromDays(1), futureChainSymbolSelector){ } public FutureFilterUniverse filter(FutureFilterUniverse filter){ return filter.Expiration(TimeSpan.FromDays(0), TimeSpan.FromDays(90)) .OnlyApplyFilterAtMarketOpen(); } } }