You right, I only see partial of your code and you probably have different plans in your mind, and surely reading 4000 lines of code doesn't help to get clear head - me too.
You said that your EA can not close a trade. So we have to find out what causing it and deal with it. This is the way I see it:
:D
#include <stdlib.mqh>
...
for(int pos = OrdersTotal(); pos >= 0 ; pos--)
{
if ( OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)
&& OrderMagicNumber() == My_Magic_Number
&& OrderSymbol() == Symbol())
{
if (OrderType() = OP_BUY) // we close long
{
for (int try_to_close = 1; try_to_close <= 100; try_to_close ++)
{
bool success = OrderClose (OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Yellow);
if (success = false)
{
int Error = GetLastError();
Print ("Unable to close ticket ",OrderTicket()," with error ",ErrorDescription(Error)); // from #include <stdlib.mqh>if (TRY_CLOSE_AGAIN_OR_NOT(Error) == false ) break; //
}
}
}
if (OrderType() = OP_SELL) // we close short
{
// do the same with sell
}
}
}
//+------------------------------------------------------------------+bool TRY_CLOSE_AGAIN_OR_NOT(int err) // True
{
switch (err)
{
case1: return (false); //error_string="no error"; case2: return (false); //error_string="common error"; case3: return (false); //error_string="invalid trade parameters"; case4: Sleep (500); return (true); //error_string="trade server is busy"; case5: return (false); //error_string="old version of the client terminal"; case6: Sleep (500); return (true); //error_string="no connection with trade server"; case7: return (false); //error_string="not enough rights"; case8: Sleep (500); return (true); //error_string="too frequent requests"; case9: return (false); //error_string="malfunctional trade operation (never returned error)"; case64: return (false); //error_string="account disabled"; case65: return (false); //error_string="invalid account"; case128: Sleep (500); return (true); //error_string="trade timeout"; case129: return (false); //error_string="invalid price"; case130: return (false); //error_string="invalid stops"; case131: return (false); //error_string="invalid trade volume"; case132: return (false); //error_string="market is closed"; case133: return (false); //error_string="trade is disabled"; case134: return (false); //error_string="not enough money"; case135: return (false); //error_string="price changed"; case136: return (false); //error_string="off quotes"; case137: Sleep (500); return (true); //error_string="broker is busy (never returned error)"; case138: return (false); ////error_string="requote"; case139: return (false); //error_string="order is locked"; case140: return (false); //error_string="long positions only allowed"; case141: return (false); //error_string="too many requests"; //case 145: return (true); //error_string="modification denied because order too close to market"; case146: Sleep (500); return (true); //error_string="trade context is busy"; //case 147: return (true); error_string="expirations are denied by broker"; //case 148: return (true); error_string="amount of open and pending orders has reached the limit"; //case 149: return (true); error_string="hedging is prohibited"; case150: return (false); //error_string="prohibited by FIFO rules"; default : return (false);
}
return(false); // can not manage the err we get out
}
So, You have a problem, that NOT ALL orders are closed. This code, You've pasted - WILL NEVER close ALL orders. So if You want some help - paste ALL the code witch's working with order CLOSING. There's no need to paste all You code (I understand You want it to keep secret), but You'll never get help without pasting part of the code, witch's involved in the problem (in this case - there's NO code for SHORT order closing).
You right, I only see partial of your code and you probably have different plans in your mind, and surely reading 4000 lines of code doesn't help to get clear head - me too.
You said that your EA can not close a trade. So we have to find out what causing it and deal with it. This is the way I see it:
:D
Thanks onewithzachy for this idea. It is useful anywhere as it is here.
Please let it work for another few hours, and I promise to update you.
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.
Don't you think that 20000 retrys is a bit excessive. If it fails to close 5 times in a row then it's time to quit.
It would be nice to print the error message if the close fails.
Hi there crossy,
You right, I only see partial of your code and you probably have different plans in your mind, and surely reading 4000 lines of code doesn't help to get clear head - me too.
You said that your EA can not close a trade. So we have to find out what causing it and deal with it. This is the way I see it:
:D
So, You have a problem, that NOT ALL orders are closed. This code, You've pasted - WILL NEVER close ALL orders. So if You want some help - paste ALL the code witch's working with order CLOSING. There's no need to paste all You code (I understand You want it to keep secret), but You'll never get help without pasting part of the code, witch's involved in the problem (in this case - there's NO code for SHORT order closing).
Hi there crossy,
You right, I only see partial of your code and you probably have different plans in your mind, and surely reading 4000 lines of code doesn't help to get clear head - me too.
You said that your EA can not close a trade. So we have to find out what causing it and deal with it. This is the way I see it:
:D
Thanks onewithzachy for this idea. It is useful anywhere as it is here.
Please let it work for another few hours, and I promise to update you.
Thanks Raptor, too, for his nice contribution.
Y.
Hello,
As I promised, after 6 hours the the EA works, everything works properly, thanks to your
good thinking.
So, meanwhile let's go ahead and I hope that there will not be any truboles.
Y.
Hello,
As I promised, after 6 hours the the EA works, everything works properly, thanks to your
good thinking.
So, meanwhile let's go ahead and I hope that there will not be any truboles.
Y.
Great !,Please update us again in a weeks
:D