I'm getting a margin error when I try to do a full reversal using Limit Orders. It works when I use SetHoldings function.

Error: "Backtest Handled Error: Order Error: id: 6, Insufficient buying power to complete order (Value:199042.8), Reason: Id: 6, Initial Margin: 99524.8, Free Margin: 50125.4."

I've attached a dummy algorithm as an example.