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.Indicators;
using QuantConnect.Securities;
using QuantConnect.Orders;
using QuantConnect.Data.Consolidators;

namespace QuantConnect.Algorithm.CSharp
{
    public class TestAlgo : QCAlgorithm, IRegressionAlgorithmDefinition
    {
    	
    	public RollingWindow<decimal> BidPrice = new RollingWindow<decimal>(4);
        public RollingWindow<decimal> AskPrice = new RollingWindow<decimal>(4);
        public RollingWindow<decimal> Volume = new RollingWindow<decimal>(4);
		
        public override void Initialize() 
        {
            SetStartDate(2010, 01, 08);
            SetEndDate(DateTime.Now);
            SetCash(1000000);
            
            var futureSP500 = AddFuture(Futures.Indices.SP500EMini, Resolution.Hour);
            futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
			
			var benchmark = AddEquity("SPY");
            SetBenchmark(benchmark.Symbol);
        }
        public override void OnData(Slice slice)
        {
        	
        	if (!Portfolio.Invested)
            {
                foreach(var chain in slice.FutureChains)
                {
                    // find the front contract expiring no earlier than in 90 days
                    var contract = (
                        from futuresContract in chain.Value.OrderBy(x => x.Expiry)
                        where futuresContract.Expiry > Time.Date.AddDays(90)
                        select futuresContract).FirstOrDefault();

                    // if found, perform logic
                    if (contract != null)
                    {
                    	BidPrice.Add(contract.BidPrice);
				        AskPrice.Add(contract.AskPrice);
				        Volume.Add(contract.Volume);
				        
				        var CurrentBidPrice = BidPrice[0];
				        Console.WriteLine(CurrentBidPrice);
				        var OneBidPriceAgo = BidPrice[1];
				        Console.WriteLine(OneBidPriceAgo);
				        var TwoBidPriceAgo = BidPrice[2];
				        Console.WriteLine(TwoBidPriceAgo);
				        var ThreeBidPriceAgo = BidPrice[3];
				        Console.WriteLine(ThreeBidPriceAgo);
				        
				        var CurrentAskPrice = AskPrice[0];
				        Console.WriteLine(CurrentAskPrice);
				        var OneAskPriceAgo = AskPrice[1];
				        Console.WriteLine(OneAskPriceAgo);
				        var TwoAskPriceAgo = AskPrice[2];
				        Console.WriteLine(TwoAskPriceAgo);
				        var ThreeAskPriceAgo = AskPrice[3];
				        Console.WriteLine(ThreeAskPriceAgo);
				        
				        var CurrentVolume = Volume[0];
				        Console.WriteLine(CurrentVolume);
				        var OneVolumeAgo = Volume[1];
				        Console.WriteLine(OneVolumeAgo);
				        var TwoVolumeAgo = Volume[2];
				        Console.WriteLine(TwoVolumeAgo);
				        var ThreeVolumeAgo = Volume[3];
				        Console.WriteLine(ThreeVolumeAgo);
				        
				        var Long = (CurrentBidPrice > OneAskPriceAgo);

				        if (!BidPrice.IsReady || !AskPrice.IsReady || !Volume.IsReady)
				        	continue;
				        	
				        	if (Long)
				        		{
									MarketOrder(contract.Symbol, 10);
				        		}
                    }
                }
            }
        }    
        /// <summary>
        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
        /// </summary>
        public bool CanRunLocally { get; } = true;

        /// <summary>
        /// This is used by the regression test system to indicate which languages this algorithm is written in.
        /// </summary>
        public Language[] Languages { get; } = { Language.CSharp };

        /// <summary>
        /// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
        /// </summary>
        public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
        {
            {"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"}
        };
    }
}