I'm working on a strategy using limit orders, and I need to manage an order on each side, so the strategy can go long or short. If the buy/long entry is triggered, then the sell/short order needs to be canceled, and vice versa. And, when a position opens, I need to use some type of order to set my profit target. I've been having some difficulty with all this, and I have the following questions.

1) Should/can I use Portfolio[symbol].IsLong and Portfolio[symbol].IsShort inside of OnOrderEvent() after a limit order has filled/partially filled, to check my direction, or do I need to check some property of the order event object instead?

2) Should/can I use Liquidate() to close any long and any short position ASAP, regardless of profit or loss?

3) Am I able to use a limit order to close my position at my profit target? When I try this, it seems that my exit order fills before reaching the target. Here's what the code looks like for buy side:

// Set entry limit order in OnData method:
loLower = LimitOrder(assetName, positionSize, priceLevel, "enter long")

// Set profit target in OnOrderEvent method:
loClose = LimitOrder(assetName, -Portfolio[symbol].Quantity, priceLevel, "exit long")

I've been using StopMarketOrder() instead of LimitOrder() to make this work, but I don't think this is what I want, I think this creates more slippage.

4) When do the Inactive and None order statuses occur?

5) I keep getting this error if I change one of my input parameters to certain values, how do I find the cause of it? No line number is given.

Runtime Error: Object reference not set to an instance of an object (Open Stacktrace)