at this point, my EA is supposed to have taken a trade, and I want it to manage it:
When it reaches TP1 (profit), 80% of the position should be closed (lots3)
while (trade == 1) // trade has been taken
{
if (MarketInfo(Symbol(), MODE_BID) <= profit) //if the market reaches TP1
{
if(OrderSelect (magic,SELECT_BY_TICKET) == true) //then it selects my trade
lot3 = CDouble::RoundToLots(OrderLots() * 0.8); //it calculates 80% of the position
OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); //and close 80% of it
}
OrderClose isn't a void function but a bool function and you should check the return value if the OrderClose was successful or not. See documentation: https://docs.mql4.com/trading/orderclose
Petr Nosek: OrderClose isn't a void function but a bool function and you should check the return value if the OrderClose was successful or not. See documentation: https://docs.mql4.com/trading/orderclose
it took me some time to figure out how to make it work.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thanks I did and it is almost working !!! thanks a lot !
I still have some problems when I try to close some part of the lots.
What I initially wrote was :
But then, a warning message saying "return value of 'orderClose' should be checked
So I wrote that, as suggested here:
Now there is this error message "'return' - 'void' function returns a value".
I am confused as I do not understand why should I wrote return 0.. or do anything else..
Any suggestions? :)
What is that you are actually trying to accomplish? Tell us your end goal in plain English.
Hi (again),
in plain English,
at this point, my EA is supposed to have taken a trade, and I want it to manage it:
When it reaches TP1 (profit), 80% of the position should be closed (lots3)
then this error message appears:
then this error message appears:
OrderClose isn't a void function but a bool function and you should check the return value if the OrderClose was successful or not. See documentation: https://docs.mql4.com/trading/orderclose
it took me some time to figure out how to make it work.
here is the final code (if it helps someone):