Profile Picture

ClosePosition cleanup?

Posted By davidS 8 Years Ago
Message
Posted Friday March 06 2009
Am I correct in assuming that the ClosePosition and CloseAllPositions methods also cancel all pending orders (e.g. take profit and stop-loss) and ensure that they haven't been executed?

I'm also a little confused about what constitutes a position. I assume that the OpenPosition method creates a new position of the current symbol, whereas the AddToPosition method adds to an existing position of the current symbol so that multiple trades may be associated with a single position. If so, I can't figure out how to determine the position ID associated with a particular use of OpenPosition so that I can add to it with AddToPosition. Any hints?

By the way, I'm a new purchaser of RE and I find myself very impressed with the flexibility of the platform, though the learning curve is pretty steep. I'm compiling a document of lessons learned and will be happy to share it when it gets a bit further along. Perhaps it could serve as the beginning of a more comprehensive tutorial. Congratulations on a solid and flexible product, and your excellent customer support.



Posted Sunday March 08 2009
Any pending order that exists for that position is canceled. A position is nothing more than a collection of trades for a symbol when the number of shares held is not 0. It's really just a convenient grouping. For example, you buy 100 shares of MSFT, you've opened a position in MSFT. If you sell 50 shares, the position is open. You sell the last 50, the position is now closed and P/L accounting is done on those three trades.

I'm not sure I fully understand your question about determining a Position ID associated with a particular use of OpenPosition. So set me straight if I'm missing your question. A Position ID is set immediately upon calling OpenPosition. If you needed to, you could store this PositionID off for your own internal tracking. Later, when you're iterating over your positions, you can do a lookup (using a Dictionary or another collection?) to match things up your way.

We really do appreciate your support. Thank you.

davidS (3/6/2009)
Am I correct in assuming that the ClosePosition and CloseAllPositions methods also cancel all pending orders (e.g. take profit and stop-loss) and ensure that they haven't been executed?

I'm also a little confused about what constitutes a position. I assume that the OpenPosition method creates a new position of the current symbol, whereas the AddToPosition method adds to an existing position of the current symbol so that multiple trades may be associated with a single position. If so, I can't figure out how to determine the position ID associated with a particular use of OpenPosition so that I can add to it with AddToPosition. Any hints?

By the way, I'm a new purchaser of RE and I find myself very impressed with the flexibility of the platform, though the learning curve is pretty steep. I'm compiling a document of lessons learned and will be happy to share it when it gets a bit further along. Perhaps it could serve as the beginning of a more comprehensive tutorial. Congratulations on a solid and flexible product, and your excellent customer support.



Posted Sunday March 08 2009
When you call OpenPosition, it returns a position object.  This has an Error property which will let you know if there was anything wrong with the request, and an ID property that is the ID of the position.

Thanks,
Daniel



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems