OrderClose() Error 4051

 

Hello.

I get an "Invalid ticket for OrderClose() function" (error 4051)  when I test my EA. Looking at the error codes I see that a parameter is invalid. Although I have a hunch it is OrderTicket() that is messing up, I have seen this parameter listed like it is in other codes.

The OrderClose() code is written below. Please help.

Thank you,

Mac 

if(OrdersTotal() > 0)
                    {
                       OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red) ;
                    } 
 

You have to use OrderSelect() before using OrderTicket()

Read Documentation https://docs.mql4.com/trading/orderticket

 
Also you trie to close all your orders with Ask,   not checking your OrderType()