example: For each trade
-
Here I provide you few examples how to work with blocks For each Trade, or For each Closed Trade, you can also work with blocks for pendings ...
https://fxdreema.com/shared/FRLmvb2Bb
you can also download mq4 file and import it into your projects to have my provided original:
0_1482090825721_example_loop_trades.mq4maybe something must not working and need some little change, I have not tried this my examples in tester, you can ... and here are other ways how to do this, better or worser, it is up to you and your invested time

have a fun ...



-
Hi @miro1360 Thanks for this.really helpful, But I have some questions:
- What exactly does the Area do? Does it separate the trades... I mean the commands in Area #1 does not control the trades in Area #
- Also i will like to partially close a trade, add to volume (partial close should not apply).
For example:
Create a trade
partially close 10%
partially close 10%
add to volume (i will not like to partially close this trade).Please any suggestions.
Thank You.
-
maybe add to lot size without close can be done in MT5 (I have not study how, you can
), but in MT4 it is not possible (not possible to modify the lot size of trades for original open price or recalculated open price), I mean when your trade is opened like 1.0 lot, you can not modify lot size to 1.5 into one tradebut here in fxdreema you can do something as opening new trade with the same SL TP like parent one using "add to volume" (currently loaded using For each trade block) ...
partially closing is working as you asked, here you can view some example to your question:
https://fxdreema.com/shared/5XS8SPvIbor here you can work with ticket number ...
https://fxdreema.com/shared/Y90zEfaFb
there are many ways how to work with these numbers, you need try it ...instead of "add to volume" you can close trade, load its lot size into variable and add next lot size to this variable: closed was 1.0, you will add 0.5, so result save into variable like 1.0+0.5=1.5 and this 1.5 open as new trade on current price ... it is maybe not as you expected but can working with few compromises (like open on current price)
...
rest what you asked for Area xy, it are only areas for separating examples, each area is each example ... and "area in area" - it is because of comment - I used it only for commenting main Area ... -
@miro1360 Hi, still having the same issue. This is what i am trying to achieve: shared/q1wdRiUPc
I will like to take partial profit for the parent trade, but do not want to take partial profit for the add to volume. I cant differentiate both trades.Would appreciate your input.
Thank You.
-
This is the project: https://fxdreema.com/shared/y6F1bWm9c
-
no guarantee

https://fxdreema.com/shared/Vf2S0sctd
-
@miro1360 @administrators @fxDreema Nice. Works like a charm. Thank you so much.
My other question is: Can I save the open price for multiple orders (Buy and sell), and put them in a list for cross reference. like you did with the Condition with saveOpenPrice.
Thank You.
-
you mean list as array like:
openPrice[0]=1.10
openPrice[1]=1.15
openPrice[2]=1.12
.....
openPrice[x]=y
?
yes you can do this now ...
just define in variables these:
double openPrices[100]
double openPrice=0
int myInc=0take 4 blocks:
- reset variable myInc=0
- For each Trade
- Modify Variable block: save Open price into variable openPrice
- custom code block where you put:
openPrices[myInc]=openPrice;
myInc=myInc+1;
after this you have open price from all trades in array openPrices[] and you can get values from it like:
openPrices[0] ... open price from first loaded trade
openPrices[1] ... open price from second loaded trade
.. etc
or using Loop/for where you use your increment variable myInc and you can get values one after another: openPrices[myInc]
of course you can resize this array using some functions from mql code, or all what you will do, all next is up to you ... -
Great. Yes... I meant like an array.
Thank You. will try this out.
-
@shomefun No working
-
Thanks for the great examples on the For Each Trade block. However, I have still an issue when looking for solution to close the first and last trade when breakeven/small profit. The proposed solution as shown in the picture and coming from another tag in FxDreema does not seem to work as it still closes ALL trades.
Does someone has the solution how to close only the first and last trade? -
@bhovens Your logic is correct. The problem is that this action is executed every single tick. This is why all of them are closed, because every single tick, both are closed. You need to move to the 'on Trade' tab. Probably you will also need to create a variable to identify when this calculation should be done.
-
Thanks. I now added the blocks in the "On Trade" tab, but now when I backtest it is not executed at all. The C_Trade_DD_Red constant for the Check trades count is set to "4". Any solution?

-
@bhovens I see this is a part of a much larger project. Can you please share it? Obviously there is something interfering with this part.
-
This is the project: https://fxdreema.com/shared/hXFB1qJUb
-
@bhovens I don't see any special issue with the whole project. I recommend you to duplicated the structue below both 'For each trade' block on the 'On trade' tab. Just create one variable for the oldest and another one for the newest open trades (as you are doing now) and store the amount of money of each one this way:

Then subtract one from the other in a 'formula' block and finally compare it with with value of 5. Not an elegant soluton but probaly effective.
-
Thanks for the proposal. As I understand it correctly I have adjusted the project as shown below.
Still with no result as it always still closes ALL trades and not only the oldest and newest trade.
It seems that the "For each Trade" block does not work properly where it should come back only with one trade, it comes back with ALL trades.
-
Anyone any idea how to resolve this issue?
-
@bhovens

This blue block doesnt care about the above loop or what trade is currently selected, it always closes all trades. Replace it with the pink close block, that one closes according to the loop. -
Hi Roar, I implemented your suggestion as per below scheme. Still the same result as it does not close the first and last trade, when profit is 5 for both first and last trade, but still closes all trades as programmed in the "on Tick" section. Does it has something to do with the Group #???
