I get an error when trying to retrieve tick data. The error message is:

"Runtime Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index (Open Stacktrace)"

Error goes away when I comment out the following line:

tick_price = data["EURUSD"][-1].LastPrice;       

What is causing the problem? Help much appreciated.       

 

////////////////////////////////Code //////////////////////////

public override void Initialize()

{

     SetStartDate(2019,4,15);

     SetEndDate(2019,4,22);

     SetCash(1000);

     AddForex("EURUSD", Resolution.Tick, Market.FXCM);

     SetWarmUp(TimeSpan.FromDays(5));

}

 

public void OnData(Slice data)                 

{

Decimal tick_price = 0;

     if (data.ContainsKey("EURUSD"))

     {           

           tick_price = data["EURUSD"][-1].LastPrice;

     }       

}     

///////////////////////////////////////End//////////////////////////