Description:
The code implementation only handles long positions, not short positions.
When shorting, existingMtp.Custody is the base asset, and existingMtp.OpenPrice is the price of the trading asset.
Code logic:

suggestion:
Position_SHORT: Custody is base asset
((existingMtp.Custody + newMtp.Custody)/ ( (existingMtp.Custody / existingMtp.OpenPrice) + ( newMtp.Custody / newMtp.OpenPrice))