Try following to narrow down cause of the error:
If OrderSelect fails because the ticket number (or index) doesn't exist, you get Error 4051.
Additionally, some print statements get skipped in the Experts log. Try right-clicking the Experts log and selecting "view"
OK, it's not OrderSelect().
Anyway, you should not call OrderTicket() and OrderOpenPrice() when OrderSelect() fails. Behavior is undefined.
Are you absolutely sure that the order with the ticket number 1 exists?
Is it possible that it was a pending order that was deleted or expired at some point?
So try adding this:
I'm fairly confident that you won't get a match between buyticketnumber and the printed ticket numbers.
There is no point printing the value of OrderTicket() or OrderOpenPrice() if OrderSelect() has failed. All the values of Orderxxxxx() are irrelevant if the OrderSelect failed.
Error 130 may be due to a lack of braces after OrderSelect()