If the behavior is not what you expect use prints to debug and understand the behavior.
Your question is why is the condition evaluating as true?
if (listOfSeriesValues != null
&& listOfSeriesValues.Count() > 0
&& listOfSeriesValues.Count() <= BarsBack)
Print the values of the condition
if (listOfSeriesValues != null)
{
Print(string.Format("{0} | listOfSeriesValues.Count(): {1} > 0 && listOfSeriesValues.Count(): {1} <= BarsBack: {2}", Time[0], listOfSeriesValues.Count(), BarsBack));
}
else
{
Print(string.Format("{0} | listOfSeriesValues is null", Time[0]));
}
Print within the condition as well to confirm.
if (listOfSeriesValues != null
&& listOfSeriesValues.Count() > 0
&& listOfSeriesValues.Count() <= BarsBack)
{
Print(string.Format("{0} | condition is true", Time[0]));
}
It would be expected that once the count is greater than BarsBack that the action block code would stop being run.
Or is your question why is the foreach loop looping through each item instead of through a specific range the way a for loop would?

Comment