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
namespace QuantConnect 
{   
    public class TestFutureTickData : QCAlgorithm
    {
        private int contractDOY, tickMinute;
        FuturesContract contract;

        public override void Initialize()
        {
            Log("Initialize");

            SetStartDate(2017, 1, 1);
            SetEndDate(2017, 1, 30);
            SetCash(1000000);

            var futureCL = AddFuture(Futures.Energies.CrudeOilWTI, Resolution.Tick); //AddFuture(Futures.Indices.SP500EMini);
            futureCL.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));

            var benchmark = AddEquity("SPY");
            SetBenchmark(benchmark.Symbol);
        }

        public override void OnData(Slice slice)
        {
            if (contractDOY != Time.DayOfYear)
            {
                foreach (var chain in slice.FutureChains)
                {
                    foreach (var c in chain.Value)
                    {
                        if (c != null)
                        {
                            //Log("OnData(Slice slice): contract="+c.Symbol.Value);
                            contract = c;
                            contractDOY = Time.DayOfYear;
                        }
                    }
                }
            }
        }

        public void OnData(Ticks data)
        {
            // Ticks objects are piped into this method.

            if (contract != null && tickMinute != Time.Minute && Time.Hour > 9 && Time.Hour < 14)
            {
                List<Tick> ticks;

                if (data.TryGetValue(contract.Symbol, out ticks))
                {
                    foreach (var tb in ticks)
                    {
                        Log(contract.Symbol.Value + " Bid:" + tb.BidPrice.ToString("#.####") + " Ask:" + tb.AskPrice.ToString("#.####") + "Last:" + tb.LastPrice.ToString("#.##"));
                        tickMinute = Time.Minute;
                    }
                }
            }

        }

        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            foreach (var change in changes.AddedSecurities)
            {
                Log("Securities Added: " + change.Symbol.Value);
            }
            foreach (var change in changes.RemovedSecurities)
            {
                Log("Securities Removed: " + change.Symbol.Value);
            }
        }
    }
}