Thank you so much for your help ! I will give a look at this tonight and see if it solve the problems, thank you for your time again !

Edit : for the point 3) I don't really understand. Isn't the line " >= 0" there to make sure that the first iteration does not fail ?

4) you are right I should check them, I'm not used to check them yet, as I've not been coding for a long time and as I code for myself (as you can see by the lack of commentaries // next to the code ;) )

6) I don't intend to trade before StartHour and after EndHour, which is why I wrote that line. I think the positions will be kept overnight by the robot anyway.

I cleaned the code and changed everything you told me to change, it all works very good now. Thank you very much for your help and your time, it is very appreciated. Hope I can turn the favuor to you someday.