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 NodaTime;

namespace QuantConnect 
{   
    /*
    *   Demonstration of Problem on data timing when plotting in the "cloud" Vs 
    *   desktop
    */
    public class DataTimingProblem : QCAlgorithm
    {
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
			string _co ="CO";
			
            //Start and End Date range for the backtest:
            SetStartDate(2016, 07, 26);
            SetEndDate(2016, 07, 28);
            
            //Cash allocation
            SetCash(25000);
            
            //Add as many securities as you like. All the data will be passed into the event handler:
            AddData<RCL>(_co, Resolution.Tick);
            
            var stockPlot = new Chart("Market Price Plot");
            var assetPrice = new Series("Price", SeriesType.Line, 0);
            var rcCA1 = new Series("C1");
            
            stockPlot.AddSeries(assetPrice);
            
            AddChart(stockPlot);
        }

        // Event handler
        public void OnData(RCL data)
        {
        	// Compiler suggests implements "OnData(RCL data){...}" method
        	// but it seems the method has never been invoked
        	// so an empty implementation here just for suppression 
        	// of compiler warning
        }
        
        // Event handler - plot and print the custom data
        public void OnData(Ticks data)
        {
        	List<Tick> targetData = data["CO"];
        	foreach (var t in targetData)
        	{
        		Plot("Market Price Plot", "Price", t.Value);
        		// print out data for monitoring
        		System.Console.WriteLine("time & price: " + t.Time + t.Value);
        	}
        }
        
        public class RCL : Tick
        {
        	public decimal CL = 0; // only one field
        	
        	public RCL()
        	{
        		this.Symbol = "CO";
        	}
        	
        	public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLive)
        	{
        		var url = "https://dl.dropboxusercontent.com/u/1049831/For_QC/rcoil20160727to28.csv";
            	return new SubscriptionDataSource(url, SubscriptionTransportMedium.RemoteFile);
        	}
        	
        	public override BaseData Reader(SubscriptionDataConfig config, string line, System.DateTime date, bool isLive)
        	{
        		RCL rcBar = new RCL();
        		
        		try
        		{
        			string[] data = line.Split(',');
        			rcBar.Symbol = config.Symbol;

        			/* 
        			* Parse date time using NodaTime
        			* the datetime of custom data is in UTC
        			* All my subsequent data manipulation is in Chicago timezone
        			* So time is converted to Chicago time zone after import 
        			*/
        			OffsetDateTime defaultValue = new OffsetDateTime(new LocalDateTime(2000, 1, 1, 0, 0), Offset.Zero); // default result if parse fails
                	NodaTime.Text.OffsetDateTimePattern pattern = 
                		NodaTime.Text.OffsetDateTimePattern.Create("yyyy-MM-dd HH:mm:sso<G>", CultureInfo.InvariantCulture, defaultValue);
                	var parsedResult = pattern.Parse(data[0]); // this is the result of datatime parsing 
                	
                	Instant instant = parsedResult.Value.ToInstant(); // convert the result into NodaTime instant
                	DateTimeZone targetedTimezoneId = DateTimeZoneProviders.Tzdb["America/Chicago"];  // Chicago timezone ID 
                	ZonedDateTime dtTargetedZone = instant.InZone(targetedTimezoneId); // convert from UTC to Chicago
                	
                	/*
                	* Convert from NodaTime ZonedDateTime to System.DataTime typeof
                	* as required in BaseData
                	*/
                	rcBar.Time = new System.DateTime(dtTargetedZone.Year, dtTargetedZone.Month,
                									 dtTargetedZone.Day, dtTargetedZone.Hour,
                									 dtTargetedZone.Minute, dtTargetedZone.Second,
                									 DateTimeKind.Local);
                	
                	// Parse data
                	// for simplicity, only parse one column of data as example
                	rcBar.CL = Convert.ToDecimal(data[4]);
                	
                	rcBar.Value = rcBar.CL;
        		}
        		catch
        		{}
        		return rcBar;
        	}
        }
    }
}