Thanks for your all answers - they stimulated my thoughts. In the end I solved it with the following:
Buy = 0;
for (i=1; i<BarCount-1; i++)
{
if (LongSetup[i] == 1)
{
Buy[i+1] = 1;
BuyPrice[i+1] = O[i+1];
}
}
Sometimes simplest is best!
Alex
