Hi Everyone,

I have implemented several Futures contract in my code,

I have different conditions for each Futures to place orders. In this case i have to check which contract must be selected.

I tried that :

public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
foreach(var chain in slice.FutureChains)
{

// find the front contract expiring no earlier than in 90 days
var contract = (from futuresContract in chain.Value.OrderBy(x => x.Expiry) where futuresContract.Expiry > Time.Date.AddDays(90) select futuresContract).FirstOrDefault();

// if found, perform logic
if (contract != null && contract.LastPrice != 0)
{
if (contract.StartsWith("ES"))

{

 But the line :

if (contract.StartsWith("ES"))

return an access violation due to its protection level.

How can i do ?