New to the platform and seem to be having an issue with closing out a position under tight liquidity conditions. I have used the order_target_percent function to both buy and sell a single security based on the 5 vs 20 day moving average, the purchase was completed as expected but the sale occurred during a rapid price drop and the order was filled incrementally but continued to sell (even more shares than were originally owned) leading to a short position which is not feasible. I've tried the order_target and order_value functions as well to no avail as well as the old school approach of getting the current position size each time the if statement before the sale is triggered.
Please let me know if you have any suggestions for dealing with this issue.
Thanks!