It makes only sense for loops over asset or algo to create a series inside a loop. Otherwise create it outside and shift it inside if needed. Alternatively to the automatic shifting per bar, you can use the shift() function.