How to Select "Least profitable trade"?
-
Hi,
There is a blue block on "Trading Actions" that closes the least profitable trade.
But what I want is to select this trade (the least profitable trade) to compare with another value.
How can I do it? A pink block "select least profitable trade" would be perfect.
Thanks
-
Any idea?
I have tried using a combination of check loss, check profit, variables, conditions, etc. But it's not very simple... If I have several open trades, I have to compare all of them to select which one has the biggest loss...
But I still haven't found a reliable way to do that.
Any help or idea is much appreciated.
Thanks -
https://fxdreema.com/shared/2TwfqkIod
Well, I have an idea but its not the simplest one
We could use a position loop that goes through all your open trades, it finds the lowest profit and the trade number (loop id) - after that loop we have the amount and trade number identified and so we can select that individual trade, and also use the basic condition block.If you copypaste the blocks, you will need to create these variables to your project:

Hope you get the idea

-
Hi @roar
Thank you very much for your help! Using your example I was able to make something that works on my strategy!
What I was missing was:
- Reseting the variable "smallestprofit" on every new loop
- Using the second output of "Each Trade" to wait for all trades to be checked
Best regards!
-
@rafaelgrecco said in How to Select "Least profitable trade"?:
What I was missing was:
- Reseting the variable "smallestprofit" on every new loop
We must reset the variables at some point, so the ea don't get "stuck" to some big loss that is already closed. Now it resets the variable on every tick, and also calculates it again so we always have the correct value. It is not the most cpu-optimal way but should work fine.
- Using the second output of "Each Trade" to wait for all trades to be checked
I think this is the correct way, we must first check all trades in order to find the lowest profit.
The looping blocks work a bit different than other blocks, go ahead and test different logic builds
