For the next sell price divide N by 1 minus safe minus minimum trade % i.e. if safe = 10%, minimum trade size = 5% then 1 - 0.1 - 0.05 = 0.85 (so N / 0.85)
For next buy price divide N by 1 + safe + minimum trade % i.e. if safe = 10% minimum trade size = 5% then 1 + 0.1 + 0.05 = 1.15 (so N / 1.15)