Would it be a bug??? Sum in Loop for 2 or more orders not working!
-
Observer in the image and in the project that I am trying to add (the gain of the last 2 orders) for both sides separately, buy and sell.
The EA is not able to perform this sum, it is taking only the last order.
Here is the test project! https://fxdreema.com/shared/Uszc3hoHc
I tested the same on other brokers, would I be making a mistake in logic, or is it a BUG???I'm worried if it's a BUG because I imagine that like me, many people use these blocks and conditions to perform different tasks.
-
Closed value is for each closed position, use trade closed position for number of which 2 to add, you could also use bucket, just depends on your needs.
-
@jstap I understand what you mean, thank you very much for the tip, but the focus is on knowing if this is a BUG, do you understand this as a BUG or not?
-
Have never seen it not working.
-
@OntradingX
Not a bug. I am afraid your EA does not have any logic of summation as you claim. Maybe checking your own logic can help -
@sktsec my logic is simple as shown in the project. loop to get the last 2 open buys and give me the sum of them. What is the logic error you are seeing?
-
@OntradingX
How does your logic give you the sum? -
@sktsec open the project and understand. i use only 2 blocks to get the sum. 1. In the pink block I am checking only the last 2 orders. 2. In the gray block, I am getting the gain of these 2 orders that the selected block and saving in the variable.
-
@fxDreema help here please.
-
Now that's an example that contains a good amount of blocks and is easily testable, I like it

The problem is that you are not incrementing the variables.
Let's get
twobuysfor example. Block 9 would run block 8 twice for the two last positions, first the last position and then the previous.- On the first run
twobuysis set to the profit of the last position, which is -4.06. The value oftwobuyswas 0 and became -4.06. - On the second run
twobuysis set to the profit of the previous position, which is -4.00. The value was -4.06 and became -4.00.
If you want to sum both values, you should add the value of
twobuysto itself on every run. But also, you must reset the variable every time before such incrementations, otherwise the value will grow and grow without limits.
Instead of the side Variables panel, you can also use "Modify Variables" before blocks 9 and 11 to set the variables to 0.
- On the first run
-
@fxDreema
Glad you liked the way I did to explain my problem.
It worked perfectly, you got straight to the point I need.
Thanks for your help.I would like another help taking advantage of this post:
What if I now want to determine that the EA closes the last 2 buys that it found in profit along with only 1 sale (the last one) that is at a loss?
Can you see if my logic is correct?