I'm new to coding so please bear with me! I'm trying to make a simple test algo that keeps track of the three most recent 5min bars, it's not working the way it should though and I'm not sure why. Here is my code:
close_5m = price_history.resample('5T', closed='right', label='right').last()
price_list = []
price_list.append(close_5m)
print(price_list)
third_bar = price_list[-1]
second_bar = price_list[-2]
first_bar = price_list[-3]
I am getting the error:
IndexError: list index out of range
USER ALGORITHM:21, in handle_data
second_bar = price_list[-2]
I realize that upon the first instance of running def handle_data there is not yet a value for second_bar, how do I get the program to ignore that and just store a value in second_bar once it has an appropriate value after enough time has passed?