Balancing Trades

Hello , I have some time trading and i am not understanding how it works with margin used on trades that are the oposite of the trades i have open ,

For example

I have this open trades
Dax30 Buy quantity 2 at 15128.5
Dax30 Buy quantity 3 at 15133.5
Leverage is 20
Margin Used is 3782.88

Now when i want to open another trade on Sell with 0.7 at price 15138.5 it requires 1514.58 Margin

Does anyone know how this margin is calculated ?

Thank You

Not something I’m really familiar with but this might help? This one’s for forex though.