Overall Statistics
TotalTrades
646
AverageWin
0.05
AverageLoss
-0.03
AverageAnnualReturn
2.581
Drawdown
0.5
Expectancy
1.148
NetProfit
9.648
SharpeRatio
0.6
LossRate
20
WinRate
80
ProfitLossRatio
1.7
TradeFrequency
4
-no value-                        
-no value-                        
-no value-                        
-no value-                        
using System;
using System.Collections;
using System.Collections.Generic; 

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

    public partial class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm { 
        string symbol = "YHOO";
        System.Text.StringBuilder sb;
        
        public override void Initialize() {
            sb = new System.Text.StringBuilder();
            //Initialize the start, end dates for simulation; cash and data required.
            SetStartDate(2014, 6, ); SetEndDate(2013, 4, 30);
            //SetStartDate(2013, 10, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            
            SetCash(30000); //Starting Cash in USD.
            // AddSecurity(SecurityType.Equity, symbol, Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AAPL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BAC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JCP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NOK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YHOO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSLA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "C", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "INTC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JPM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "F", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NFLX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FCX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GOOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ORCL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "X", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WFC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CSCO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMZN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VALE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "P", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "T", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ZNGA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BIDU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "POT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VZ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "XOM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GRPN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HLF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NEM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ABX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AIG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MCP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QCOM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PBR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LVS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GMCR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DRYS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PCLN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LNKD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CLF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PFE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DOW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FSLR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OPK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WLT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DDD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LULU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VOD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IBM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MGM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JNJ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CAT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EBAY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMAT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HPQ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SLB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BRCM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LNG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MRK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HIMX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NKE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CHK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WAG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RAD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MOS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YELP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ESRX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NQ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ALU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AGNC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BMY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACHN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FIO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SLW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CRM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MCD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DIS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SINA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CMCSA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OXY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FDX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LCC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GILD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SHLD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NLY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "STP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LINE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CVX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "M", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IOC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QIHU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CELG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WMT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MRVL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UPS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SBUX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "STX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "V", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMRN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MNKD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SNDK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BBY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BTU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VLO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "APC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ANR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QCOR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WMB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DNDN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LOW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GLW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RPRX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "INVN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CIEN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CRUS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SIRI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EMC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ARNA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YOKU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADSK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CREE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NVDA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SFD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CZR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IAG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PHM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RSH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RMTI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "APA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LEN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CMG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SPF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TIBX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HUN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CIE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MAKO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KBH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GERN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EBIX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YGE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MBI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MET", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "COP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "USB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DHI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KMI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "Z", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACAD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NTAP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADBE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VVUS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SOHU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LLY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ABT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GPS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMGN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ASTX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HTZ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BIIB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SAN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AKS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SRPT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WFT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NUAN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IRM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RIO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SPWR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TEVA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NOV", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UNH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CONN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BAX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AKAM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KNDI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GDP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CLSN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OCN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RIG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EXPE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WYNN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DVN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DRI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SSYS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HES", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UNXL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KGC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JASO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SODA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RHT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UTX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NBG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RDN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VMW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NFX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AUY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SWHC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ETFC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KORS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MPEL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TASR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DISH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JDSU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WLP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WPRT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ARO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MHR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTAS", Resolution.Minute, false);
            
            SetRunMode(RunMode.Series); //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) {
            // Log(data[symbol].Time + "," + data[symbol].Symbol + "," + data[symbol].Open + "," + data[symbol].Close);
            // foreach(KeyValuePair<string, TradeBar> d in data)
            //      Log(d.Value.Time + "," + d.Value.Symbol + "," + d.Value.Open + "," + d.Value.Close);
            foreach(TradeBar v in data.Values)
                //Log(v.Time + "," + v.Symbol + "," + v.Open + "," + v.Close + ",");
                sb.Append(v.Time + "," + v.Symbol + "," + Math.Round(v.Open, 5) + "," + Math.Round(v.Close, 5) + ",");
        }
        
        //Handle Tick Events - Only when you're requesting tick data
        public override void OnTick(Dictionary<string, List<Tick>> ticks) {   
            if (Portfolio[symbol].HoldStock == false) {
                Order(symbol, 50);
                Debug("Sent order for " + symbol);
            }
        }
        
        /// <summary>
        /// Call this method at the end of the algorithm day
        /// </summary>
        public override void OnEndOfDay() {
            Log(sb.ToString());
            sb = new System.Text.StringBuilder();
        }
    }
}                        
using System;
using System.Collections;
using System.Collections.Generic; 
using QuantConnect.Securities;  
using QuantConnect.Models;   


namespace QuantConnect 
{   
    // Name your algorithm class anything, as long as it inherits QCAlgorithm
    public class BackTest : QCAlgorithm
    {
        string ticker = "BAC";
        TimeSpan startTime = new TimeSpan(09,29,00);
        TimeSpan endTime = new TimeSpan(17,00,00);
        
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2014, 12, 26);
            SetEndDate(2014, 12, 27);
            SetCash(5000);
        	AddSecurity(SecurityType.Equity, ticker, Resolution.Tick, true, 1, true);
        }
        public void OnData(Ticks ticks)
        {
        	if (!ticks.Keys.Contains(ticker)) return;
        	foreach (Tick tick in ticks[ticker]) {
        	     if ((tick.Time.TimeOfDay > startTime) && (tick.Time.TimeOfDay < endTime)){
    	            if (tick.Exchange == "N"){
    	                Log("|" + tick.Symbol + "|" + tick.Quantity + "|" + string.Format("{0:0.0000}", tick.Price));   
    	            }
    	        }
    	    }
        }
    }
}                        
using System;
using System.Collections;
using System.Collections.Generic; 

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

    public partial class BasicTemplateAlgorithm : QCAlgorithm, IAlgorithm { 
        string symbol = "YHOO";
        System.Text.StringBuilder sb;
        
        public override void Initialize() {
            sb = new System.Text.StringBuilder();
            //Initialize the start, end dates for simulation; cash and data required.
            SetStartDate(2014, 6, 9); SetEndDate(2014, 6, 30);
            //SetStartDate(2013, 10, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            
            SetCash(30000); //Starting Cash in USD.
            // AddSecurity(SecurityType.Equity, symbol, Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AAPL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BAC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JCP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NOK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YHOO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSLA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "C", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "INTC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JPM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "F", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NFLX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FCX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GOOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ORCL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "X", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WFC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CSCO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMZN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VALE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "P", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "T", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ZNGA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BIDU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "POT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VZ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "XOM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GRPN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HLF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NEM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ABX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AIG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MCP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QCOM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PBR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LVS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GMCR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DRYS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PCLN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LNKD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CLF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PFE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DOW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FSLR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OPK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WLT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DDD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LULU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VOD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IBM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MGM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JNJ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CAT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EBAY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMAT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HPQ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SLB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BRCM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LNG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MRK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HIMX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NKE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CHK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WAG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RAD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MOS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YELP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ESRX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NQ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ALU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AGNC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BMY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACHN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UAL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FIO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SLW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CRM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MCD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DIS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SINA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CMCSA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OXY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "FDX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LCC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GILD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SHLD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NLY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "STP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LINE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CVX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "M", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IOC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QIHU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CELG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WMT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MRVL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UPS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SBUX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "STX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "V", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMRN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MNKD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SNDK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BBY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BTU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VLO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "APC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ANR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "QCOR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WMB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DNDN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LOW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GLW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RPRX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "INVN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CIEN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CRUS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SIRI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EMC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ARNA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YOKU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADSK", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CREE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NVDA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SFD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CZR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IAG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PHM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RSH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RMTI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "APA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LEN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CMG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "PM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SPF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TIBX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HUN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CIE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MAKO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KBH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GERN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EBIX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "YGE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MBI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MET", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "COP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "USB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DHI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KMI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "Z", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ACAD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NTAP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADBE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VVUS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SOHU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "LLY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ABT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GPS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AMGN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ASTX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HTZ", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BIIB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SAN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AKS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SRPT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WFT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NUAN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DD", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "IRM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RIO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SPWR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TEVA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NOV", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UNH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CONN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "BAX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AKAM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KNDI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EOG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "GDP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CLSN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "OCN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RIG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "EXPE", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CF", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WYNN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DVN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TSO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DRI", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SSYS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HES", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UNXL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KGC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JASO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SODA", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RHT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "UTX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "HL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NBG", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "RDN", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ADM", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "VMW", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "NFX", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTB", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "AUY", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "SWHC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ETFC", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "KORS", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MPEL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "TASR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "DISH", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "JDSU", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WLP", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "WPRT", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "ARO", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "MHR", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTL", Resolution.Minute, false);
            AddSecurity(SecurityType.Equity, "CTAS", Resolution.Minute, false);
            
            SetRunMode(RunMode.Series); //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) {
            // Log(data[symbol].Time + "," + data[symbol].Symbol + "," + data[symbol].Open + "," + data[symbol].Close);
            // foreach(KeyValuePair<string, TradeBar> d in data)
            //      Log(d.Value.Time + "," + d.Value.Symbol + "," + d.Value.Open + "," + d.Value.Close);
            foreach(TradeBar v in data.Values)
                //Log(v.Time + "," + v.Symbol + "," + v.Open + "," + v.Close + ",");
                sb.Append(v.Time + "," + v.Symbol + "," + Math.Round(v.Open, 5) + "," + Math.Round(v.Close, 5) + ",");
        }
        
        //Handle Tick Events - Only when you're requesting tick data
        public override void OnTick(Dictionary<string, List<Tick>> ticks) {   
            if (Portfolio[symbol].HoldStock == false) {
                Order(symbol, 50);
                Debug("Sent order for " + symbol);
            }
        }
        
        /// <summary>
        /// Call this method at the end of the algorithm day
        /// </summary>
        public override void OnEndOfDay() {
            Log(sb.ToString());
            sb = new System.Text.StringBuilder();
        }
    }
}