Overall Statistics
Total Trades
188
Average Win
2.53%
Average Loss
-1.55%
Compounding Annual Return
62.139%
Drawdown
22.100%
Expectancy
0.090
Net Profit
9.921%
Sharpe Ratio
1.109
Loss Rate
59%
Win Rate
41%
Profit-Loss Ratio
1.63
Alpha
0.424
Beta
0.62
Annual Standard Deviation
0.564
Annual Variance
0.318
Information Ratio
0.535
Tracking Error
0.562
Treynor Ratio
1.008
Total Fees
$209.99
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect;
using QuantConnect.Algorithm;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Securities;
using QuantConnect.Securities.Interfaces;

namespace QuantConnect2
{
    public class TickDataTradingAlgorithmProblem : QCAlgorithm
    {
        private DateTime lastTradeTime = new DateTime(2012, 1, 1);


        private string _indicatorAsset = "SPY";
        private string _tradingAsset = "TVIX";



        public override void Initialize()
        {
            SetCash(100000);
            SetStartDate(2013, 1, 1);
            SetEndDate(2013, 7, 1);
            AddSecurity(SecurityType.Equity, _indicatorAsset, Resolution.Tick);
            AddSecurity(SecurityType.Equity, _tradingAsset, Resolution.Tick);
            
            Securities[_indicatorAsset].DataFilter = new ExchangeDataFilter();
            Securities[_tradingAsset].DataFilter = new ExchangeDataFilter();


        }

        public void OnData(Ticks data)
        {
            if (!data.ContainsKey(_indicatorAsset)) return;
            List<Tick> indicatorTickList = data[_indicatorAsset];

            Tick firstTick = indicatorTickList.First();
        
            if (!Portfolio[_tradingAsset].HoldStock && indicatorTickList.Count() > 100)
            {
                SetHoldings(_tradingAsset, 1);
                lastTradeTime = firstTick.Time;
            }

            if (Portfolio[_tradingAsset].HoldStock && firstTick.Time - lastTradeTime > new TimeSpan(1, 0, 0))
            {
                Liquidate(_tradingAsset);
            }
        }

    }

    
    public class ExchangeDataFilter : ISecurityDataFilter
    {

        public bool Filter(Security asset, BaseData data)
        {
            var tick = data as Tick;

            if (tick != null)
            {
                if (tick.Exchange == "P") 
                {
                    return true;
                }
            }

            return false;
        }

    }
}