dplaisted (3/22/2007) BigBerner (3/22/2007)
I think a tutorial on order placement and management would be useful. It has taken me quite a while to work out how to do things. Most of the systems uploaded on the site simply place buy orders at market and nothing else. Also I am finding some of the terminology used a little unclear.
For example if I place an order to buy on stop just above the market using systemdata.openposition I will now have a working order in the broker. I only want to have this order placed once. Does the "Max open" field in the Position Management section of the system properties stop this order from being placed again when the next bar completes (assuming I set it to 1) ? There are currently no open positions but if it lets it go through there are going to be more than one.
How do I check what orders are currently being worked in the broker? I think it might be PositionManager.GetPendingOrdersForPosition or .GetPendingPositions. What is the difference between these two functions?
A pending order is an order that has been submitted, but not filled. Depending on the order it may or may not eventually be filled. A "pending" position is a position where the order to open the position is pending. It is not yet open. If the order is filled, it will then be an open position. If the order is canceled, the position will be discarded.
GetPendingPositions() returns the list of pending positions. GetPendingOrdersForPosition() returns the pending orders for a specific position. If the position is not open yet (pending), then it would return the order to open the position. If the position is open, then the pending orders would include the orders corresponding to the profit target, stop loss, etc., as well as any orders that were submitted by the user.
So to find all the orders being worked by the broker, you would call GetPendingOrdersForPosition() for all the positions returned by GetPendingPositons() and GetOpenPositions().
Looking at the code, the Max open positions setting only checks open positions, not pending positions. However, this is a bug, as it should also take into account the pending positions. I have added this as bug 888.
Thanks Daniel, so this is what I think you mean.
Pending Order: This is an order that is working in the broker.
Pending Position: This is NOT an order that is working in the broker. It is an order that is being monitored by RE which may become a working order. (Correct me if I still haven't got it)
It seems to me that you have blurred the lines between an order and a position. You can place an order but you cannot place a position (which is what is seems to me you are doing with Pending Position). You place an order which will then have various states. A position either exists or it doesn't, you either have an exposure to the market or you don't. You can't have a pending position because this is really an order with a different orderstate. I think a pending position is an order with an orderstate that should be called "Monitoring" or something like that. I think you will have a lot of trouble if you use this terminology and suggest you change it.
GetPendingPositions() should be GetMonitoringOrders() and should return a list of monitoring orders not positions.
GetPendingOrdersForPosition(String) should be GetMonitoringOrdersForPosition(String) and return the orders that are being monitored (Take profit etc) for a specific OPEN position.