Any reason why this is closing sells?
-

-
Also @roar you are the loop master, maybe you can help me! I have the following variables:
openSells: current open profit/loss on sell positions
openBuys: current open profit/loss on sell positions
MaxSells: Highest value of sell profits reached
MaxBuys: Highest number of buy profits reached.I'm trying to get the EA to do the logic:
If OpenBuys > (MaxBuys - MaxSells)
Close all BUY trades, starting with the least profitable, until OpenBuys =< (MaxBuys - MaxSells)I managed to get similar logic working with a simple loop in another project (https://fxdreema.com/shared/a3cD1cAjb) but when I use it in my main project it either gets stuck in the loop OR just closes everything, buys and sells
-
Remove the 'for each' trade' block. The 'close trades' block is a loop itself. Your structure is combining a loop unto another loop. That is probably the reason why it's not working correctly.
-
@l-andorrà Thanks, I tried it with a regular close block and still no luck, it just crashes the EA in the tester as it's stuck in an infinite loop.

To be honest I already have data the variables I need: When I have a X amount of loss in BUY trades and Y amount of profit hedged in SELL trades, I want to close all SELL trades, and close the equivellant amount of profit (loss) in BUY trades
EG:
Buys: -$200
Sells: +$150Close all SELLS and equivelant value of BUYS
Result:
Buys: -$50
Sells: $0This keeps the on-balance profit/loss the same but frees up some margin.
but I'm struggling to find a way to do this! If you can offer some ideas that would be amazing.
-
I know @roar made something that does a similar thing here: https://fxdreema.com/shared/ZVBBYk4M
but I can't seem to get it to work. I have these variables if that helps:

-
original thread where ROAR posted: https://fxdreema.com/forum/topic/7555/request-suggestion-for-close-partially-group-of-trades-block?_=1685989402676 I'm going to keep playing with it but any assistance is greatly appreciated as I'm still learning!
-
I got it working based off of @roar 's project so thanks guys! it was a problem with caclulating the max open sells because when i did it with a fixed value it worked fine

Any way to get the final trade to close a partial to keep the math more precise as a bonus? thanks guys! -
Congrats for making it work! What do you exactly mean by 'keep the math more precise'?