Hi all.

Trying to calculate an order to trade a forex pair (e.g. USDNOK) on Wednesday 2021 Feb 3 19:00 using “calculate_order_quantity” returns None. However, using a fixed order quantity the marker_order gets executed just fine, see attached backtest. Why?

I noticed this behaviour in a backtest where I used either a fixed quantity or calculating the quantity with calculate_order_quantity. In a backtest (over ~4 years, one order per day, so ~2000 orders) in about ¼ of cases, calculate_order_quantity returns None (~1500 total orders). However, if using the fixed quantity, the forex pairs can be traded (~2000 orders).

Is this a bug or am I missing something or doing something wrong? Any help or alternative method of calculating order size (considering portfolio/equity/etc. and remaining margin) would be appreciated. I just did not know how to do it manually, that's why I used calculate_order_quantity. If you could point me to a source on how to calculate it manually, I would be very grateful.