- ago
How can I access OpenPositions.Count bars ago in the Execute loop Wealth Lab 8?
0
123
5 Replies

Reply

Bookmark

Sort
Glitch8
 ( 5.10% )
- ago
#1
You’d maintain your own List int to store the open position count and add the value each Execute loop.
0
- ago
#2
Why declaring TimeSeries OpenPosSeries; OpenPosSeries= new TimeSeries(bars.DateTimes, 0);

and assigning OpenPosSeries[idx] = OpenPositions.Count; in the Execute loop does not work?
0
- ago
#3
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.
0
- ago
#4
https://www.wealth-lab.com/blog/anatomy-of-a-wl7-strategy
0
Cone8
 ( 2.12% )
- ago
#5
@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();

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();          :          :
0

Reply

Bookmark

Sort