my code below just prints best/worst equity when these are breached. And when equity hits X then closes all trades.
This worked fine for oever 3 months til my lateest update 5833. i dont know if this is a bug or is my amateur coding. Here's my coding below. If you see anything that is wrong or can be done better, PLEASE TELL ME.
klast week and today, it didnt close all trades when it was supposed to do so. and then, even when i manually right clicked on a trade and selected : Bulk Positions >> Close all positions, i had to do this 4 times before all my 100 trades had closed! i am suspicious about both my coding AND 5833.
I don't know if -1 is proper for a Deviation parameter:
trade.PositionClose(tk,-1); I do know that I don't have a problem in Build 5833, using 0 instead of -1.
I don't know if -1 is proper for a Deviation parameter:
I do know that I don't have a problem in Build 5833, using 0 instead of -1.
i have been using that line for years, no issues, but i have SetDeviation in my OnInit, so i never understood what i was meant to put on that Deviation parameter on the trade.PositionClose line.
I see that you have:
input int iSlippage = 1; // Slippage (in pips)
trade.SetDeviationInPoints(iSlippage);
But I don't see any pips to points conversion math.
TBH, I have no idea how your SetDeviaton code interacts with an attempt to override it with -1... in Build 5833.
On an unrelated note, your event handler header comments for OnInit() and OnTick() appear to be transposed.
Also, PositionsTotal() is an int.
Your custom define shows a ushort:
#define total0 (ushort)PositionsTotal()
for(int k = total0 - 1; k >= 0; k--)
- www.mql5.com
A more likely explanation for both symptoms, the EA not closing everything and the manual bulk-close needing four attempts, is too many simultaneous close requests in flight. SetAsyncMode(true) fires every PositionClose without waiting for server confirmation before sending the next one, and at 100 positions that can hit broker-side throttling or requotes that silently drop some closes. Worth testing the same loop with SetAsyncMode(false) and comparing.
i agree and i considered that -- at the time, but same thing happened when i created a script to limit closing to just 20 trades.
But then the next day, after my previous msg, the issue was gone -- i was closing 100 trades in bulk, with both script and the mt5 terminal, right click feature -- without any issue; no explanation, the issue just disappeard. maybe it was broker issue for those few days.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
my code below just prints best/worst equity when these are breached. And when equity hits X then closes all trades.
This worked fine for oever 3 months til my lateest update 5833. i dont know if this is a bug or is my amateur coding. Here's my coding below. If you see anything that is wrong or can be done better, PLEASE TELL ME.
klast week and today, it didnt close all trades when it was supposed to do so. and then, even when i manually right clicked on a trade and selected : Bulk Positions >> Close all positions, i had to do this 4 times before all my 100 trades had closed! i am suspicious about both my coding AND 5833.