How to get BarsSinceEntry of prior open position  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

How to get BarsSinceEntry of prior open position

Postby GTrader » 05 Feb 2016

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.

User avatar
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

Postby JoshM » 06 Feb 2016

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.
`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.

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: How to get BarsSinceEntry of prior open position

Postby GTrader » 06 Feb 2016

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.

User avatar
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]

Postby JoshM » 06 Feb 2016

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.

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: How to get BarsSinceEntry of prior open position

Postby GTrader » 06 Feb 2016

Thanks Josh


Return to “MultiCharts .NET”