Grid based on equity or margin level

 

I am developing a kind of grid system on MT4. The lot sizes will be distributed in one area, increasing the lots for every new position.

Requirements:

1) The system knows that can open at maximum x positions. ( x = 5 in the example below)

2) The system shall use a multiplier Z to increase the lot size for every the position. ( z = 1.5 for example)

Question:

How to calculate the lot sizes for each position considering the requirements above and the two new requirements below ? The new requirements below will not be used together. The user can select one or the other or do not use it.

3) The equity can reach 50% of the actual account balance if the the last position is opened. Example: The user has 1000 USD in his account before opening the first grid position. The 5th position is opened. Now he has the equity showing 500 USD, but the account balance is still 1000 USD.

4) The margin level can reach 500% if the the last position is opened. Example: Before opening the first grid position, the system shows a margin level of 1000%.  The 5th position is opened.  Now the user checks MT4 and see the margin level showing around 500%.

Thanks!


 
I wont use a grid ea, so I can't tell you but there are already so many Grid EAs, just search under (on the left side) articles and/or codebase: https://www.mql5.com/en/search#!keyword=grid%20EA