Issue with Foreach Trade
-
I have created an EA that according to the configuration creates up to 5 pending buy orders (all at the same point) and 5 pending sell orders (all at the same point). This is configured in the "On tick" section and works correctly.
In the "On trade" section, I want to configure that every time a pending trade enters the market, the pending orders of the opposite type are closed and if the option to make a second trade is activated, a second trade of the opposite type must be opened.
For example: Initially a buy stop and a sell stop are placed simultaneously. The buy I am enters the market, a buy order is generated, at which point the initial sell stop is removed and another sell stop is opened for double the volume.
I have tried several ways, but it does not remove the pending orders after opening the first trade or trades, does anyone know how I can do this?
This is my project: https://fxdreema.com/shared/nJTEUPsbb
P.S. In case anyone is wondering, I want to do this so that I can spread the total volume over several trades.
Thank you in advance for your help.
-
@mlumbreras
Interesting theory. I changed your AE something. You only need the "Pass" block if a block would otherwise stand alone or for special other applications. The "OpB" block is also not necessary, since something is only executed after an event, and "for each trade" is also not required , because the search is for the trade that JUST was executed. Maybe that will help you first, I didn't fully understand your description of how the EA works, but I think you need an additional variable, maybe. -
Thank you very much for your reply @RGoo . I wanted to make it too complicated. Your example is more in line with what I want, but I still have a problem.
Continuing with your example, blocks 139 and 141 should open a pending order with double the volume for each of the open trades. Currently, the pending orders are created, but one of them is closed and I don't know why.

-
@mlumbreras
This can actually only be due to the expiration mode. You have to check that. I once inserted a control block for you, you can place it anywhere and you can then see whether the block is currently being run through and how often.
-
Excellent! Indeed, that was the problem. Thank you very much for your help @RGoo !
-
@mlumbreras
Try this out, it should work.

https://fxdreema.com/shared/Mflx9sUWc