How can I access OpenPositions.Count bars ago in the Execute loop Wealth Lab 8?
Rename
You’d maintain your own List int to store the open position count and add the value each Execute loop.
Why declaring TimeSeries OpenPosSeries; OpenPosSeries= new TimeSeries(bars.DateTimes, 0);
and assigning OpenPosSeries[idx] = OpenPositions.Count; in the Execute loop does not work?
and assigning OpenPosSeries[idx] = OpenPositions.Count; in the Execute loop does not work?
Open positions count is not known in Execute() yet.
Keep track of the filled transactions in Execute and update a static int var.
In Cleanup() assign it to your static TimeSeries.
See the BLOG article about the inner workings for details.
Keep track of the filled transactions in Execute and update a static int var.
In Cleanup() assign it to your static TimeSeries.
See the BLOG article about the inner workings for details.
@wl64bit - It works, but OpenPositions.Count only gives the count for the bars being processed (one symbol).
For the count for all open positions, use OpenPositionsAllSymbols.Count();
For the count for all open positions, use OpenPositionsAllSymbols.Count();
CODE:
TimeSeries OpenPosSeries; public override void Initialize(BarHistory bars) { OpenPosSeries = new TimeSeries(bars.DateTimes, 0); PlotTimeSeries(OpenPosSeries, "Open Positions", "OpenPos", WLColor.Green, PlotStyle.Histogram); } public override void Execute(BarHistory bars, int idx) { OpenPosSeries[idx] = OpenPositionsAllSymbols.Count(); : :
Your Response
Post
Edit Post
Login is required