Hi,
If I have two open positions on the same security. I am trying to get the BarsSinceEntry of the first position taken. The BarsSinceEntry method only returns the most recent entry.
Thanks for the help.
How to get BarsSinceEntry of prior open position [SOLVED]
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: How to get BarsSinceEntry of prior open position
`Positions[1].ClosedTrades[0].EntryOrder.BarNumber` returns the bar number of the first entry into the previous position, if I'm not mistaken. You can compare that value with the current bar (`Bars.CurrentBar`) to get the number of bars since that position was opened.If I have two open positions on the same security. I am trying to get the BarsSinceEntry of the first position taken. The BarsSinceEntry method only returns the most recent entry.
Re: How to get BarsSinceEntry of prior open position
Hi JoshM,
I'm actually trying to get prior open position not the closed position.
Imagine the following:
- buy 100 @ 99 on 1/1/2016
- buy 100 @ 98 on 1/5/2016
Both positions are still open. After the second entry the BarsSinceEntry() method get reset to the most recent entry. I can't figure out how to reference the first buy on 1/1/2016 and get it's BarsSinceEntry.
I'm actually trying to get prior open position not the closed position.
Imagine the following:
- buy 100 @ 99 on 1/1/2016
- buy 100 @ 98 on 1/5/2016
Both positions are still open. After the second entry the BarsSinceEntry() method get reset to the most recent entry. I can't figure out how to reference the first buy on 1/1/2016 and get it's BarsSinceEntry.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: How to get BarsSinceEntry of prior open position [SOLVED]
So with 'prior open position' you mean not the previous position, but the first trade in the current position?
In that case, `CurrentPosition.OpenTrades[0].EntryOrder.BarNumber` returns the bar number of the first entry into the current position.
If you want to access information about the second entry in the current position (the buy at 5 Jan), then you'd use `CurrentPosition.OpenTrades[1]`. Hope this makes sense.
In that case, `CurrentPosition.OpenTrades[0].EntryOrder.BarNumber` returns the bar number of the first entry into the current position.
If you want to access information about the second entry in the current position (the buy at 5 Jan), then you'd use `CurrentPosition.OpenTrades[1]`. Hope this makes sense.