Trademinator selling and buying algorithm will not sell 100% of your balance in the first spot. Because you do not know what will happen in the future, the algorithm plays safe and it sells in a proportion of `n / (n + 1)` with a correction factor. Although this could be very good and profitable if the price is not bearing, when it is, it could harm as you are carrying a balance with a greater buying rate than the current one. This document proposes a double average as a solution.

The double average means using the last 4 periods of orders (2 sells, 2 buys). The following formula shows the way to calculate the balanced buying average between two periods B_{1} and B_{2}.

B = ((V_{S1}- V_{B1}) * B_{1}+ V_{B2}* B_{2}) / (V_{S1}- V_{B1}+ V_{B2})

Where:

- B is the balanced buying average
- V means the volume of YYY units
- S means a selling rate of XXX/YYY
- B means a buying rate of XXX/YYY
- 1 or 2 are the periods behind

The following cases explain more carefully.

Some hard rules to remember:

- Trademinator will only sell if the last average buying price is lower than the current selling price. In other words, it will seel if B
_{n}< S.

## Case 1: Neutral Trend

The following conditions are met:

- B
_{1}< S_{1} **B**_{1}> B_{2}**B**_{1}< S_{2}- S
_{1}> S_{2} - B
_{2}< S_{2}

There is no need to use a double average as B_{2} is less than B_{1}, it will average down any remaining balance not sold by S_{1}.

## Case 2: Bearing Trend

The following conditions are met:

- B
_{1}< S_{1} **B**_{1}> B_{2}**B**_{1}> S_{2}- S
_{1}> S_{2} - B
_{2}< S_{2}

The double average is needed. Because B_{1} > S_{2}, any remaining balance not sold in S_{1} needs to be average with B_{2}. S_{2} can only happen if it is greater than the balanced average between B_{1} and B_{2} balances.

## Case 3: Bullying Trend

The following conditions are met:

- B
_{1}< S_{1} **B**_{1}< B_{2}**B**_{1}< S_{2}- S
_{1}< S_{2} - B
_{2}< S_{2}

There is no need to use a double average. The balanced average between B_{1} and B_{2} will be less than B_{2} then S_{2} will take place if the average of B_{1} and B_{2} which it is the same as comparing against B_{2}.

## Status

- Partial implementation in 0.3.0