I need to stop a loop when a condition is true, I am looping thrue a pandas dataframe and I saw that the problem comes probably from the range(1,len(newdatafr)): because all the elements of this list must be 'filled'
for ind in range(1,len(newdatafr)):
if newdatafr['h'][ind] > tp_2 and newdatafr['l'][ind] > sl_1:
sl_1 = tp_2
print("scale up")
elif newdatafr['h'][ind] < tp_2 and newdatafr['h'][ind] > tp_1 and newdatafr['l'][ind] > sl_1:
sl_1 = tp_1 ## BE
elif newdatafr['l'][ind] < sl_1:
print("Sortie du trade. Ouverture :"+str(open_1)+" Sortie :"+str(sl_1) )
break
How can I write this in an other way ? Thank you