WHY OPTIMIZATION IS SO SLOW WHEN I USE "ON TRADE" BLOCKS ?
-
GOOD MORNING MR JSTAP
JUST A QUIK QUESTION TO GET PROFIT OF YOUR VALUED EXPIRIENCE:
I NOTICED THAT WHEN I USE "ON TRADE" BLOCKS THE OPTIMIZATING IS GETTING TOOOOO SLOW..!! ..
HOW CANI SOLVE IT TO GET AT LEAST SAME OPTIMIZATION SPEAD AS WHEN USING "ON TICK" BLOCKES ..
THANK YOU FOR YOUR SUPPORT
RGDS -
Is hard to say without looking at your project link, I do not find these blocks slow things too much, although it can happen. Generally this is too much computing power being used on backtest, stopping blocks working every tick will normally fix this... like putting trees/blocks under a once per bar block set to 1 minute.
-
Dear Mr Jstap
Simply: how to store the :
TOTAL PROFIT OF THE “TOTAL CURRENT BUY POSITIONS” AT THE MOMENT OF ADDING A NEW POSITION BUY in a variable.
AND
TOTAL PROFIT OF THE “TOTAL CURRENT SELL POSITIONS” AT THE MOMENT OF ADDING A NEW POSITION SELL in a different variable.
In this project : https://fxdreema.com/shared/opyzomi2e ,I am comparing the “current profit” with the “last opened position” profit and make the buy/sell decision, but my problem is that I am not able to store the ‘total profit at last position” buy or sell in variables correctly.
It seems -not sure- that if i put these blocked under trade instead of under tick and eliminate the pink blocks it works but in this case it is impossible to optimize the EA independently of the computing power and resources.
Hope you can help
Kind regards
Bachar -
Under your buy or sell block - modify variable to 0 - for each closed trade (set up as you want) - formula + trade profit and save into the variable you just set to 0.
-
dear sir
I am not sure if you could perfectly consider what I want.
Each time a new BUY position is opened, the EA must look at the total current buy profit of CURRENT OPENED BUY POSTIONS and store this profit in a variable.
The same for SELL positions.
I wonder that you are asking me to use: “FOR EACH CLOSED POSITION” which has nothing to do with the current opened position...!!!
Probably It is mistake ..alternatively I hope you can explain more or better just amend this shared EA..!!
According to the best of my knowledge I did modify the EA to achieve this target , kindly have a look and tell me if it is correct like that …tks
https://fxdreema.com/shared/uoEURx60dThank you for your support
rgds -
The current just placed trade will be in a spared distance loss, what I put it how to get the value of all closed buy/sell trades:. Use a formula to get the value of each closed position:

-
thank you very much for your expirienced replay.
a final question please : in this strategy hundreds of buy/sell trades will be opened and i an suffering looses due to delay in closeing them using "close positions" block since it close them one by one which cobers few mintes even on VPS..
i hope you can faind a solution for fast closing ...
thank you very much for every thing
rgds -
You will have to create a block, not really tested much with this though:
https://fxdreema.com/forum/topic/21603/close-all-mt5-trades-quickly -
YOU ARE GRATE ... DONE .. THANK YOU VERY MUCH
-
-
DEAR SIR
https://fxdreema.com/shared/xqWIR5Zrd
FOLLOWING YOUR INSTRUCTIONS TO CREATE A CUSTOM CLOSE ALL GROUP , IT WORKS SO GOOD AND CLOSE ALL TRADES ENOUGH FAST , THE PROBLEM IS THAT IT CLOSES ALL TRADES EVEN IF MANUALY OPENED AND INDIPENDENTLY EVEN OF THE MAGIC NUMBER..
I ADDED THE PINCK (FOR EACH POSITIONS) BLOCK IT CONTINUE TO CLOSE ALLL ALL OPENED POSITIONS INDIPENDENTLY OF THE MAGIC NUMBER OR THE POSITION TYPE...!!!
CAN YOU PLS HELP FOR MAKING IT CLOSE ONLY POSITIONS WITH A SPECIFIC MAGIC NUMBER OR POSITION DIRECTION TYPE (BUY OR SELL)..!!
THANKYOU FOR YOUR KIND SUPPORT
RGDS -
try adding this to the function, not tested though:
void CloseAllPositions(ulong MagicStart)
{
for (int cnt = PositionsTotal() - 1; cnt >= 0 && !IsStopped(); cnt--)
{
if (PositionSelectByIndex(cnt))
{
ulong ticket = PositionGetInteger(POSITION_TICKET);
long magic = PositionGetInteger(POSITION_MAGIC);// Only close positions matching the EA's magic number if (magic == (long)MagicStart) { sTrade.PositionClose(ticket, 100); uint code = sTrade.ResultRetcode(); Print("Close result code: ", IntegerToString(code), " | Ticket: ", ticket); } }}
} -
GOOD DAY TO YOU:
AS PER YOUR INSTRUCTION ADDING THE CODE YOU SENT ABOVE RESULT IN FUNCTION THE FOLLOWING CODE :
void CloseAllPositions() {
for (int cnt = PositionsTotal() - 1; cnt >= 0 && !IsStopped(); cnt--) {
if (PositionGetTicket(cnt)) {
sTrade.PositionClose(PositionGetInteger(POSITION_TICKET), 100);
uint code = sTrade.ResultRetcode();
Print("Close result code: ", IntegerToString(code));
}
}
}void PrintPerformance(ulong startTime) {
for (int i = 0; i < 100; i++) {
Print("Elapsed time: ", IntegerToString(GetMicrosecondCount() - startTime), " microseconds. Open positions: ", IntegerToString(PositionsTotal()));
if (PositionsTotal() <= 0) { break; }
Sleep(100);
}
}
void CloseAllPositions(ulong MagicStart)
{
for (int cnt = PositionsTotal() - 1; cnt >= 0 && !IsStopped(); cnt--)
{
if (PositionSelectByIndex(cnt))
{
ulong ticket = PositionGetInteger(POSITION_TICKET);
long magic = PositionGetInteger(POSITION_MAGIC);// Only close positions matching the EA's magic number if (magic == (long)MagicStart) { sTrade.PositionClose(ticket, 100); uint code = sTrade.ResultRetcode(); Print("Close result code: ", IntegerToString(code), " | Ticket: ", ticket); }}
}
}
BUT NOW I AM GETTING THIS ERROR UPON COMPILING :CAN YOU PLS TELL ME WHAT IS WRONG ?? HOW TO FIX ? TKS

-
Try this.
Global Includes section **********************************************
#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>ulong startTime;
CTrade sTrade;
CPositionInfo mPosition;Custom Function Section ******************************************
void CloseAllPositions(ulong MagicStart)
{
for (int cnt = PositionsTotal() - 1; cnt >= 0 && !IsStopped(); cnt--)
{
if (PositionSelectByIndex(cnt))
{
ulong ticket = PositionGetInteger(POSITION_TICKET);
long magic = PositionGetInteger(POSITION_MAGIC);if (magic == (long)MagicStart) { sTrade.PositionClose(ticket, 100); uint code = sTrade.ResultRetcode(); Print("Close result code: ", code, " | Ticket: ", ticket); } }}
}Settings section *******************************************
startTime = GetMicrosecondCount();
sTrade.SetAsyncMode(true);CloseAllPositions(MagicStart); // Pass your EA’s magic number
PrintPerformance(startTime);~next~
Hope this works

-

as you can see hear i did exactly as per your instruction but still i am getting the following error massage :

can you pls rectify , tks
rgds
