Not sure I fully understand the 'For each trade' block as it is
-
I want to create my first array with fxDreema blocks and no custom code. Obviously I failed, but I guess I'm missing something important when dealing with the 'For each trade' block. Any help will be appreciated. This is my project:
https://fxdreema.com/shared/PXFDNj0wd
Everything below block ID 4 works correctly so no problem there. Now let's focus on the right. I need to filter how many profitable trades are open right now. That should happen on block ID 55. Then the combined profit of each new trade found by the loop should be added to the variable on block ID 58. When the calculation in block ID 59 is true (ie the accumulated profit plus a gain value is higher than the loss stored in the variable of block ID 54), the loop is broken and loop moves to block ID 62. If not true a variable is counting how many trades are necessary for condition in block ID 59 to be true.
Once this loop is broken or finally executed, block ID 62 is closing the trade identified in block ID 54. Finally the loop in block ID 61 should also close as many trades as previously identified in block ID 56. Considering that both loops in blocks ID 5 and 61 are ordered to search exactly in the same direction (profitable last). The second one should close those found by block 5's loop. However, no trade is closed at all.

Can someone please tell me what am I missing?
-
@l-andorrà Hello,
To be honest, I'm not able to follow exactly what is supposed to happen here but I have a way that you may be able to follow the error. It seems to me that it may be that one of these variables are not being calculated correctly. Just place a comment block with all these variables and visually follow through a backtest while seeing exactly the values of these variables in the comment panel.
Other than that, the block orders may be the problem here. I think that these changes may work.

-
@q8carpenter Thank you for your reply. I forgot to say that I already used a 'comment' block to visualize the value of the variables and I confirm they are not calculated correctly. Their value is always 0 and I don't know why. On the other hand, block ID 62 needs to be executed AFTER block ID 5 so it should work.

-
@l-andorrà
That is a tricky loop I admit, if I understand well the condition in block ID 59 can never be true as "guanyatparcial" is always positive and "idmaxperd" always negative.
In the first branch you want to store the value of the least profitable trade(handling biggest loss), if the top block processes from the least profitable to the most profitable one, you could just make it pass once. -
@l-andorrà said in Not sure I fully understand the 'For each trade' block as it is:
On the other hand, block ID 62 needs to be executed AFTER block ID 5 so it should work.
Yes my friend but the thing that I feel is wrong (and I'm maybe wrong here), is that in the way you have set up the order, I feel that 61 and 63 will run before 56, while 61 has a variable that requires to be updated by 56.

-
@q8carpenter Probably. I'm don't know. I will try a differenet configuration. Thank you for your help.
-
@l-andorrà
Have you tried my recommandation ?