Overall Statistics
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace QuantConnect 
{
    using QuantConnect.Securities;
    using QuantConnect.Models; 

    /**
     * Simple Moving Average Cross
    **/
    public partial class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm 
    { 

        string symbol = "SPY";
        decimal volumeTrigger = 500000; //(decimal)Math.Pow(10, 5); //15000 * 8; //35 * 35;
        decimal liquidityTrigger = 500000; //(decimal)Math.Pow(10, 5); //15000 * 8;
        
        //4 -4 Parallel

        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
            //Initialize the start, end dates for simulation; cash and data required.
            SetStartDate(2013, 06, 01); //(2014, 01, 20);
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(30000); //Starting Cash in USD.
            AddSecurity(SecurityType.Equity, symbol, Resolution.Second); //Minute, Second or Tick
            SetRunMode(RunMode.Parallel); //Series or Parallel for intraday strategies.
        }

        //Handle TradeBar Events: a TradeBar occurs on a time-interval (second or minute bars)
        public override void OnTradeBar(Dictionary<string, TradeBar> data)
        {
            if (data.ContainsKey(symbol)) {
                TradeBar tradeBar = data[symbol];

                decimal modelVolume = tradeBar.Volume;
                decimal modelLiquidity = tradeBar.Volume * Math.Sign(tradeBar.Close - tradeBar.Open);
                //Debug("modelVolume=" + modelVolume + ", modelLiquidity=" + modelLiquidity);

                //CHECK ENTER
                if (Portfolio[symbol].Quantity == 0)
                {
                    if((Math.Abs(modelLiquidity) > liquidityTrigger) && (modelVolume > volumeTrigger))
                    {
                        //Debug("modelVolume=" + modelVolume + ", modelLiquidity=" + modelLiquidity);
                        int entry_side = Math.Sign(modelLiquidity);
                        Order(symbol, entry_side * 50, OrderType.Market);
                    }
                }
                //CHECK EXIT LONG
                else if (Portfolio[symbol].Quantity > 0)
                {
                    if((Math.Abs(modelLiquidity) > liquidityTrigger) && (modelVolume > volumeTrigger))
                    {
                        //Debug("modelVolume=" + modelVolume + ", modelLiquidity=" + modelLiquidity);
                        int entry_side = Math.Sign(modelLiquidity);
                        if (entry_side < 0)
                        {
                            Order(symbol, entry_side * 50, OrderType.Market);
                        }
                    }
                }
                //CHECK EXIT SHORT
                else if (Portfolio[symbol].Quantity < 0)
                {
                    if((Math.Abs(modelLiquidity) > liquidityTrigger) && (modelVolume > volumeTrigger))
                    {
                        //Debug("modelVolume=" + modelVolume + ", modelLiquidity=" + modelLiquidity);
                        int entry_side = Math.Sign(modelLiquidity);
                        if (entry_side > 0)
                        {
                            Order(symbol, entry_side * 50, OrderType.Market);
                        }
                    }
                }

            }
        }

    }
}