Can ActivePositions.Contains be used to find a position by symbol?
Author: Panache
Creation Date: 10/7/2018 1:14 AM
profile picture

Panache

#1
I would like to check whether a position in a symbol is open. Obviously, I can iterate through ActivePositions and check each Position.Symbol.
CODE:
Please log in to see this code.

I assume there is a non-iterative way to do it using ActivePositions.Contains(??), but I don't know what to insert in the parenthesis, since the only information I have about the Position is the symbol.

Am I missing something, or do I have to resort to Linq?
profile picture

Eugene

#2
Syntactic sugar aside, ultimately it boils down to iteration. Your code is OK. ActivePositions.Contains can be used to look up a specific Position instance - which is not what you want.

Note that without a (potential) rewrite of your Strategy this cannot be used to check if there are active positions in a DataSet in Portfolio Simulation mode: Any Open Position (in Other Symbols) in Portfolio Mode
profile picture

Panache

#3
Thanks Eugene.

I'm just trying to learn how to be a better programmer.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).