private bool oneTime = false;
private string symbol = "SPY";

public override void Initialize()
{
SetStartDate(2020, 3, 25);
SetEndDate(2020, 3, 25);
SetCash(1000);

AddEquity(symbol, Resolution.Tick);
AddEquity(symbol, Resolution.Second);
AddEquity(symbol, Resolution.Minute);
AddEquity(symbol, Resolution.Hour);
AddEquity(symbol, Resolution.Daily);
SetWarmup(0);

}

public override void OnData(Slice data)
{
if (IsWarmingUp) return;

if(!data.ContainsKey(symbol) || data[symbol] == null) { }
else {
if(!oneTime)
{
ShowUsingInt(symbol);
ShowUsingTimeSpan(symbol);
//ShowTickUsingTimeSpan(symbol);
oneTime = true;
}
}
}

private void ShowTickUsingTimeSpan(string symbol)
{
var bars1 = GetHistory<Tick>(symbol, TimeSpan.FromSeconds(1), Resolution.Tick);
var bars2 = GetHistory<Tick>(symbol, TimeSpan.FromMinutes(1), Resolution.Tick);
var bars3 = GetHistory<Tick>(symbol, TimeSpan.FromHours(1), Resolution.Tick);
var bars4 = GetHistory<Tick>(symbol, TimeSpan.FromDays(1), Resolution.Tick);
Debug($"Tick Symbol {symbol} Timespan: Seconds : {bars1.Count()}; Minutes: {bars2.Count()}; Hours: {bars3.Count()}; Days: {bars4.Count()}");
}

private void ShowUsingTimeSpan(string symbol)
{
var bars1 = GetHistory<TradeBar>(symbol, TimeSpan.FromSeconds(1000), Resolution.Second);
var bars2 = GetHistory<TradeBar>(symbol, TimeSpan.FromMinutes(1000), Resolution.Minute);
var bars3 = GetHistory<TradeBar>(symbol, TimeSpan.FromHours(1000), Resolution.Hour);
var bars4 = GetHistory<TradeBar>(symbol, TimeSpan.FromDays(1000), Resolution.Daily);
Debug($"Symbol {symbol} Timespan: Seconds : {bars1.Count()}; Minutes: {bars2.Count()}; Hours: {bars3.Count()}; Days: {bars4.Count()}");
}

private void ShowUsingInt(string symbol)
{
var bars1 = GetHistory<TradeBar>(symbol, 1000, Resolution.Second);
var bars2 = GetHistory<TradeBar>(symbol, 1000, Resolution.Minute);
var bars3 = GetHistory<TradeBar>(symbol, 1000, Resolution.Hour);
var bars4 = GetHistory<TradeBar>(symbol, 1000, Resolution.Daily);
Debug($"Symbol {symbol} int: Seconds : {bars1.Count()}; Minutes: {bars2.Count()}; Hours: {bars3.Count()}; Days: {bars4.Count()}");
}

private IEnumerable<T> GetHistory<T>(string symbol, TimeSpan periods, Resolution resolution) where T : BaseData
{
return History<T>(symbol, periods, resolution);
}

private IEnumerable<T> GetHistory<T>(string symbol, int periods, Resolution resolution) where T : BaseData
{
return History<T>(symbol, (int)periods, resolution);
}

The above results print out:

Symbol SPY int: Seconds : 1000; Minutes: 1000; Hours: 1000; Days: 1000 

Symbol SPY Timespan: Seconds : 0; Minutes: 390; Hours: 203; Days: 688

My assumption would be that both of these would have the same results?

Now when I call ShowTickUsingTimeSpan(symbol) too, it only prints out:

Runtime Error: Execution Security Error: Operation timed out - 5 minutes max. Check for recursive loops. (Open Stacktrace

Now if I use a different symbol, for example AMD:

Without the tick being printed out:

Symbol AMD int: Seconds : 1000; Minutes: 1000; Hours: 1000; Days: 1000
Symbol AMD Timespan: Seconds : 0; Minutes: 390; Hours: 203; Days: 688

With the tick being printed out

Symbol AMD int: Seconds : 1000; Minutes: 1000; Hours: 1000; Days: 1000
Symbol AMD Timespan: Seconds : 0; Minutes: 390; Hours: 203; Days: 688
Tick Symbol AMD Timespan: Se...

 

So my questions are:

  • Why passing in TimeSpan into Histotry rather than int gives different answers?  
  • Why getting History for tick just doesn't work?  "SPY" doesn't work, "AMD" doesn't even print out the line?
Anyway, this doesn't seem to be a data issue but more a code issue?  Can someone tell me what i'm doing wrong? Thanks,   Michael