Plot() does not belong within barcount loop. Create an array to be plotted. Code: priceatbuy[i] = ...;