self updating/refreshing grid, compare two groups of trades
-
I will do something for this issue, but who knows when...
Here is a little trick by using 1 Variable, 1 block and 1 MQL4 function (OrderLots()), but I'm lazy to explain how exactly this works, so I hope that you will somehow get it

-
laziness is not a virtue, don't you know?

I would like to try that with a loop. But I still not really understand how it is working. Does "For each trade" is working on any block?
logically this should work: https://fxdreema.com/shared/oXgeJOBcbWhat I want here is to hedge the side (buy or sell) that has the bigger lot size. Could the above scheme work? If not, how to use "For each trade" correctly to get the whole lot size (buy or sell) stored in the proper variable?
-
You don't why "For each Trade" exists and why I mention that block, which I do very often. Try this one, hopefully you will get the idea: https://fxdreema.com/shared/A4w0WN0yb
And the idea is pretty simple, but 90% of the people don't get it. This block creates a list of all available trades and then loads them one after another, sending their attributes to the blocks connected after. -
there are comments on the following scheme:
https://fxdreema.com/shared/RNdjhmD8cI try to understand step by step how "For each Trade" and its relationship to the other blocks is working.
-
-
My application for "For each Trade" is a little different than the example you refered to, but I have tried to create something. But unfortunately, it is not working: https://fxdreema.com/shared/9vsPd4Ayd
What is wrong here?
"For each Trade" is resetet by EMPTY_VALUE on every loop
the saved variable is added to an another variable which shoud hold the summed whole lot size.What is missing/wrong? (Choose 1M chart and wait a few minutes to see results)
-
I think you still don't get it
What is reset on each loop and what should be reset? Do you know why it must be reset?These Variables are global variables. They have initial value, which can be anything, let's say 0. This is only the initial value, then it can be modified. The variable holds that value until you modify it or until you close that EA (then it disappears).
If you increment a variable on each tick, it's value will grow. Add the value of 1 on each tick to that variable - then you have a variable that holds the number of ticks.
So, this "For each..." block does even more. Within a tick it can cause the next block that is connected to it to run few times!
What is the idea of collection the total sum of... let's say lot sizes. What we want to do is to read the lot size of trade 1 and keep that value in our variable. Then we want to read the lot size of trade 2 and add this value to our variable. The same with all other trades. What we have at the end - the total sum of lot sizes.
But! On the very next tick we will do the same thing, because "For each Trade" is placed under "on Tick". Now, our variable contains a value that is the sum of all lot sizes. At this point we will just continue adding to that value. So yes, the value will grow without limits.
That's why we must reset that variable who collects this sum on each tick. We don't need to reset variable that will just be set with a single lot size value and is not used to collect data.
-
I can follow you but I still did not get is.
There is a comment in the comment Area: https://fxdreema.com/shared/i2n4wfW6e"The whole list from "For each Trade" is worked through on every tick and the list is worked through probabely by CPUs speed. Therefore we have to reset the Variable that is collecting the whole lot size "all_buy_lots" and "all_sell_lots" on every tick to have only the current lot size and not adding lots to infinite.
But this is also not working."
-
Now this is a little bit better, and it basically works, but you don't know what is the value of this constant EMPTY_VALUE. In the other project, from which you get that, I used it because it was needed there and I believe that I explained why - this constant has the maximum value for this numeric data type. It is confusing that it's name contains "EMPTY", which maks you think that it is 0, but it's not 0. And in your case you don't need this constant, you need 0.
-
OK, thanks. I think I got it now (I hope so) :).
-
Now I would like to display a line with the average open price of for instance, all open buy trades, but this is not working:
https://fxdreema.com/shared/0j7avY9GdOther aplications of this kind of using "For each trade" are working. What is wrong or missing here? I have an assumption but I am not really sure how to do that.
p.s.:
actually I need the average open price in one value of all buy trades in cosideration of their lot size.
-
What is wrong is that you sum all open prices, so you got the sum of all open prices. For something to be average, you must divide the total sum to the number of elements.
There is a block to check the average profit with respect to the lot sizes, but open prices (Check current unrealized profit)... I don't know how?
-
I also think to get the value of an average open price of trades that is depending on their distance from each other and their lot size is very complex. Maybe I try to create that later again.
An another problem which came up is, how to close a special trade or trades. For instance I would like to close the two first (oldest) buy trades. To get their profit is possible but how to close these trades?
-
There is a block called "close"
-
I have tried something but it was not working correctly. Because of creating a new specific Test EA is sometimes quite difficult, so I have extracted the pice that I want to make working from my current EA. It is just to show you the problem I want you to look over.
I want to compare the profit of two goups. But I am still not sure how to close specific trades. Could you look over #Area2 and write me what is wrong there and what I have to change. You have to verify just logikally/syntactically in assuming there will be 100-group orders and sell orders.
-
What, it is difficult? I do this every day to show something to someone, or to check something for myself. At least this is refreshing.
This is Area #2 is not exactly right, but it's not wrong as well. The "close" block will close the right trade, only because you have 1 for "Not more than....". The yellow output of all "For each..." blocks is the end of the loop. At this point there is some trade/order loaded and blocks like "close" will do something over it. It is the last trade/order that "For each..." block was loaded.
-
Well, the problem is that some "testing enviroments" will take a lot of blocks and there is a propability I will do something wrong. The last Example (a few postings ago), for instance was not working correctly but luckily you coud make me understand how to use that "principle" correctly. I will try to explain problems to you as easy and clearly as possible.
But back to the current problem... as I understood you, the below modification shoud work correctly, because one trade after another will be "loaded" and closed depending on "Not more...". Right?
-
The probability is that you would find the problem while building the test environment

I don't really know the idea. The block "close" closes whatever is loaded from the "For each..." block above. If you run this block outside the loop, it will also close something, if it still exists.
-
I am a little confused now. I think I will explain you in detail how things shoud work maybe you are able to make a suggestion to create what is needed.
-Assume there are sell-trades in loss in a grid.
-To close these trades without a loss, a buy-grid (100 group) is started and the sell-grid is stopped (protection-mode)
-In case 100-buy-group profit is bigger than the first (oldest) two sell-trades, the 100-group and the two oldest trades shoud close.
-buy-group-grid 100 will start from beginning and after 100-group profit is again bigger than the new first/oldest trades, 100-group and the two oldest sell-trades will be closed again.
-and so on until there are no sell-trades in loss or protection mode will be canceled manually. This is a basic behaviour I need first.Area #1 will work correctly but I don't know how to close the oldest sell-trades (Area #2). Ideally the oldest trades shloud be collected first and then get closed when condition is met. What would you suggest?
-
What is specific for the trades that must be closed? Use that specific thing as a filter and close them. In "For each Trade" you can filter by group, type, market, time, you can also sort them by profit and select how many trades to work on, and also you can skip some from the list that this block creates. Under "For each Trade" you can also filter by something.
Do you understand the need of "For each Trade" and how this block works with the other pink blocks in the same category?