Some (not all!) of my orders get MARGIN rejected and I cannot figure out why. Please help, thanks in advance.

Below I buffer the orders by 50 USD in the Sizer but I still get the MARGIN :(

_getsizing:

```
result = int(cash_per_order / data.open[1]) * self.coef
result = round(result, 0)
while True:
c = comminfo.getcommission(result, data.open[1])
if result * data.open[1] + c < self.broker.get_cash()-50:
break
result -= 1
# price, size, commission, all costs, available cash
print("Sizer:", data.open[1], result, c, result * data.open[1] + c, self.broker.get_cash())
```

notify_order:

```
elif (o_status == "Margin"):
self.cancel(self.order[symbol])
self.order[symbol] = None
print("\n", "MARGIN!", order.p.data.open[0], order.size, self.broker.get_cash(), "\n")
```

Result:

Sizer: 10.814 9347 46.735 101125.193 101180.15400000001

MARGIN! 10.814 9347 101180.15400000001

The whole (very straightforward) Sizer:

```
class LongSizer(bt.Sizer):
#coef = 0.95
coef = 1
def _getsizing(self, comminfo, cash, data, isbuy):
result = 0
if isbuy is True:
if self.strategy.getposition(data) is not None:
if self.strategy.getposition(data).size > 0:
return 0
max_pos_value = int(self.broker.get_value() / self.strategy.max_stake)
cash_per_order = int(self.broker.get_cash() / len(self.strategy.buy_orders.keys()))
if cash_per_order > max_pos_value:
cash_per_order = max_pos_value
try:
if cash_per_order > data.open[1]:
result = int(cash_per_order / data.open[1]) * self.coef
result = round(result, 0)
while True:
c = comminfo.getcommission(result, data.open[1])
if result * data.open[1] + c < self.broker.get_cash()-50:
break
result -= 1
print("Sizer:", data.open[1], result, c, result * data.open[1] + c, self.broker.get_cash())
else:
return 0
except IndexError:
return 0
else:
if self.strategy.getposition(data) is not None:
if self.strategy.getposition(data).size > 0:
result = self.strategy.getposition(data).size
return result
```