This particular script will find the biggest winning / losing trade among a list of trades and close them . if you want either of them then comment the code block accordingly. there is also symbol and magic number filter Close biggest winning / losing trade in MT4 - scrip...
from https://tradingrobots.net/close-biggest-winning-losing-trade-in-mt4-script-for-metatrader-4/