What is the "lowest position" ? The one with highest loss ?
This is the problem, i don't know how to do exactly that...
How to identify the one with le largest lost.
If you can post an example of code it would be great.
int ticket=0; double largestLoss=0; for(int i=PositionsTotal()-1; i>=0; i--){ // \ Go if(m_position.SelectByIndex(i) // > through && m_position.Symbol()==Symbol() // / the list. && m_position.Profit() < largestLoss // \ remember ){ // \ the ticket largestLoss = m_position.Profit(); // / with the ticket = m_position.Ticket(); // / largest loss. } } // \ On loop exit, if(ticket) m_trade.PositionClose(ticket); // / close the ticketNot compiled, not tested.
I will try this as soon as possible. Many thanks.
It seem to be simple for you, but for me, four months ago i had never coded anything neither done any trade.
As it is
not so obvious for me, i am still in training and sometimes i need a help from a more senior coder.
Thank you for your response but i think this won't do the job.
Your code seem to select all the positions with profit under 0.
I can have up to 100 positions with profit under 0. For example if have 4 negative profit positions :
pos1 = -10, pos2 = -20, pos3 = -5, pos 4 = -15. I want to close only "pos 2" and keep opened all the others.
My need is to select "pos2" in a large group of negative profit positions, i know how to close only this one if i can select it.
- There is no need to select profitable positions as you aren't going to close them.
chpeller: i need in somme situations to close only the lowest position.
- Yes, it selects all losing positions. There is no way to find the biggest looser unless you look at all of them.
- Once the loop exits, then and only then, do you know the biggest. Think!
What is the "lowest position" ? The one with highest loss ?
It is the worst profitable buy or sell position.
The one with the highest loss

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody,
I'm a newby and i work with MT5.
I'l developping my own EA and i need in somme situations to close only the lowest position.
That mean i have to identify and select it and i don't know how to do that.
Actually to close a position i use this :
and i wonder if with the same logical i can close only the lowest positions.
Thank's for the help.
Regards