Reference positions by index
Author: innertrader
Creation Date: 6/5/2018 8:37 PM
profile picture

innertrader

#1
Is there a way to reference positions by index number other than enumerating all positions and tagging, as in:
CODE:
Please log in to see this code.



Even with that, I would have to create a loop to select a specific position....
profile picture

Eugene

#2
Sure there is. Firstly, instead of foreach you could use for loop. But even this is unnecessary as each Position is tagged. You just have to call IndexOf of a Position object:

CODE:
Please log in to see this code.
profile picture

innertrader

#3
Thank you. The IndexOf property sounds like what I was looking for. I can't find any documentation on ways to use it, although I found a couple of code samples using it with apparent lists. Is this a generic property that can be applied to all lists in WL? Is Positions is a special type of list and that's why it supports this property?

I see now how I can get an Int reference for a specific Position. How can I go the other way and reference positions, e.g. to get the average Net Profit or number of bars held for the last 3 positions?
profile picture

innertrader

#4
I think I figured it out. Thanks for setting me in the right direction.

CODE:
Please log in to see this code.
profile picture

superticker

#5
I believe
CODE:
Please log in to see this code.
will always hold true for a numerable C# collection such as Positions, so you don't need the .IndexOf property call. Calling that property unnecessarily will only slow you down. The .IndexOf property is available to all numerable C# collection types. Check the Microsoft .NET framework docs concerning C# collections.

Now you can change/redefine the numeration order of a C# collection such as Positions, say through an inverse sort, but WL 6.X.X isn't doing that with the Positions object.
profile picture

innertrader

#6
Thanks! C# coding is not my forte. Appreciate the lesson.
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).