- ago
I have tried several times to get ActivePositions.Count to work without success.

Here is a simple example:

using WealthLab.Backtest;
using System;
using System.Collections.Generic; // Required for .Count
using WealthLab.Core;
using WealthLab.Data;
using WealthLab.Indicators;


namespace WealthScript68
{
public class MyStrategy : UserStrategyBase
{


//create indicators and other objects here, this is executed prior to the main trading loop
//public override void Initialize(BarHistory bars)
//{
//}

//execute the strategy rules here, this is executed once for each bar in the backtest history
public override void Execute(BarHistory bars, int idx)
{
int activepositioncount = ActivePostions.Count;

WriteToDebugLog("Write to Output" + activepositioncount);
}

//declare private variables below

}
}

and I get the error:

Compiled at 2/15/2026 11:01:02
21: The name 'ActivePostions' does not exist in the current context

Please help.
0
76
5 Replies

Reply

Bookmark

Sort
- ago
#1
Please bracket your code between "code" tags so it's formatted by the website. Use the Code button when you post.

I've searched for ActivePostions with the Visual Studio object browser, and it can't even find this property anywhere. Where did you see it?

The typical way to address this attribute is with the OpenPositions property, which will return the open positions for the current symbol your strategy is processing.

CODE:
List<Position> openPositions = OpenPositions; int openPositionCount = OpenPositions.Count;
0
- ago
#2
Use
CODE:
OpenPositionsAllSymbols
if you need open positions from all symbols being backtested.
0
- ago
#3
I used a query of Google Gemeni for how to create a strategy in wealth lab that when a strong signal is received and there was already too many open positions how to sell the least performing position and the buy the new strong signal. It responded with the "ActivePositions.Count" to be tested and that would not compile. I will try the OpenPositionsAllSymbols as suggested below.
0
- ago
#4
QUOTE:
I used a query of Google Gemeni for how to create a strategy ... when a strong signal is received ... It responded with the "ActivePositions.Count" to be tested ...

Interesting. Thanks for that answer.

Because of AI hallucinations, I wouldn't take it too literally. Also, a "strong signal" to me means "high trading volume" (or high turnover, which is price*volume for the trading day), but who knows what AI thinks it means? Take what it tells you with a grain of salt for now. (But in the future, AI may get better.)

Take note, WL has an indicator for Turnover.

Happy trading.
0
Cone8
 ( 17.57% )
- ago
#5
Prompt your AIs with WealthLab Version 8.
ActivePositions.Count worked fine for Version 6.
1

Reply

Bookmark

Sort